idx int64 0 60.3k | question stringlengths 92 4.62k | target stringlengths 7 635 |
|---|---|---|
50,900 | public function getById ( $ collection , $ documentId , array $ options = [ ] ) { if ( strpos ( $ documentId , '/' ) !== false ) { @ list ( $ collection , $ documentId ) = explode ( '/' , $ documentId ) ; } $ data = $ this -> getDocument ( Urls :: URL_DOCUMENT , $ collection , $ documentId , $ options ) ; $ options [ '... | Get a single document from a collection |
50,901 | public function getHead ( $ collection , $ documentId , $ revision = null , $ ifMatch = null ) { return $ this -> head ( Urls :: URL_DOCUMENT , $ collection , $ documentId , $ revision , $ ifMatch ) ; } | Gets information about a single documents from a collection |
50,902 | public function save ( $ collection , $ document , array $ options = [ ] ) { $ collection = $ this -> makeCollection ( $ collection ) ; $ _documentClass = $ this -> _documentClass ; $ params = $ this -> includeOptionsInParams ( $ options , [ 'waitForSync' => null , 'silent' => false , 'createCollection' => $ this -> ge... | save a document to a collection |
50,903 | public function update ( Document $ document , array $ options = [ ] ) { return $ this -> updateById ( $ document -> getCollectionId ( ) , $ this -> getDocumentId ( $ document ) , $ document , $ options ) ; } | Update an existing document in a collection identified by the including _id and optionally _rev in the patch document . Attention - The behavior of this method has changed since version 1 . 1 |
50,904 | public function updateById ( $ collection , $ documentId , Document $ document , array $ options = [ ] ) { return $ this -> patch ( Urls :: URL_DOCUMENT , $ collection , $ documentId , $ document , $ options ) ; } | Update an existing document in a collection identified by collection id and document id Attention - The behavior of this method has changed since version 1 . 1 |
50,905 | public function replace ( Document $ document , array $ options = [ ] ) { $ documentId = $ this -> getDocumentId ( $ document ) ; return $ this -> replaceById ( $ document , $ documentId , $ document , $ options ) ; } | Replace an existing document in a collection identified by the document itself |
50,906 | public function replaceById ( $ collection , $ documentId , Document $ document , array $ options = [ ] ) { return $ this -> put ( Urls :: URL_DOCUMENT , $ collection , $ documentId , $ document , $ options ) ; } | Replace an existing document in a collection identified by collection id and document id |
50,907 | public function remove ( Document $ document , array $ options = [ ] ) { $ documentId = $ this -> getDocumentId ( $ document ) ; $ revision = $ this -> getRevision ( $ document ) ; return $ this -> removeById ( $ document , $ documentId , $ revision , $ options ) ; } | Remove a document from a collection identified by the document itself |
50,908 | public function removeById ( $ collection , $ documentId , $ revision = null , array $ options = [ ] ) { return $ this -> erase ( Urls :: URL_DOCUMENT , $ collection , $ documentId , $ revision , $ options ) ; } | Remove a document from a collection identified by the collection id and document id |
50,909 | protected function prepareOptions ( array $ options = [ ] ) { $ cookieName = time ( ) . "_" . substr ( md5 ( microtime ( ) ) , 0 , 5 ) . ".txt" ; $ defaultConfig = array ( 'curl' => array ( CURLOPT_COOKIEJAR => $ cookieName , CURLOPT_COOKIEFILE => $ cookieName , ) , ) ; $ configOptions = array_merge_recursive ( $ optio... | get default configuration options for guzzle |
50,910 | public function getAbsoluteUrl ( $ withFragment = true ) { if ( $ this -> isCrawlable ( ) === false && empty ( $ this -> getFragment ( ) ) ) { $ absolutePath = $ this -> getOriginalUrl ( ) ; } else { if ( $ this -> parentLink !== null ) { $ newUri = \ GuzzleHttp \ Psr7 \ UriResolver :: resolve ( $ this -> parentLink , ... | converting nodeUrl to absolute Url form |
50,911 | public function isCrawlable ( ) { if ( empty ( $ this -> getPath ( ) ) === true && ( $ this -> parentLink && empty ( $ this -> parentLink -> getPath ( ) ) ) ) { return false ; } $ stop_links = array ( '@^javascript\:.*$@i' , '@^mailto\:.*@i' , '@^tel\:.*@i' , '@^skype\:.*@i' , '@^fax\:.*@i' , ) ; foreach ( $ stop_links... | Is a given URL crawlable? |
50,912 | public function isExternal ( ) { $ parentLink = $ this -> parentLink ; if ( $ parentLink === null ) { return false ; } $ isExternal = $ this -> getHost ( ) !== "" && ( $ this -> getHost ( ) != $ parentLink -> getHost ( ) ) ; return $ isExternal ; } | Is URL external? |
50,913 | public function extractHeaders ( ) { $ absoluteUrl = $ this -> getAbsoluteUrl ( ) ; $ headersArrRaw = get_headers ( $ absoluteUrl , 1 ) ; if ( $ headersArrRaw === false ) { throw new \ Exception ( "cannot get headers for {$absoluteUrl}" ) ; } $ headersArr = array_change_key_case ( $ headersArrRaw , CASE_LOWER ) ; if ( ... | extract headers array for the link url |
50,914 | protected function removeDotsFromPath ( ) { if ( $ this -> parentLink !== null ) { $ newUri = \ GuzzleHttp \ Psr7 \ UriResolver :: resolve ( $ this -> parentLink , $ this ) ; } else { $ newUri = $ this ; } $ finalPath = \ GuzzleHttp \ Psr7 \ UriResolver :: removeDotSegments ( $ newUri -> getPath ( ) ) ; return $ finalP... | remove dots from uri |
50,915 | public function traverse ( Link $ url = null ) { if ( $ url === null ) { $ url = $ this -> baseUrl ; } $ this -> links [ $ url -> getAbsoluteUrl ( false ) ] = $ url ; $ this -> traverseSingle ( $ url , 0 ) ; for ( $ depth = 1 ; $ depth < $ this -> maxDepth ; $ depth ++ ) { $ this -> log ( LogLevel :: DEBUG , "crwaling ... | Initiate the crawl |
50,916 | public function getLinksArray ( $ includeOnlyVisited = false ) { $ links = $ this -> getLinks ( ) ; if ( $ includeOnlyVisited === true ) { $ links = array_filter ( $ links , function ( Link $ linkObj ) { return $ linkObj -> isVisited ( ) === true ; } ) ; } return array_map ( function ( Link $ link ) { return [ 'fullUrl... | get links information as array |
50,917 | public function getScrapClient ( ) { if ( $ this -> scrapClient === null ) { if ( $ this -> headlessBrowserEnabled === true ) { $ scrapClient = CrawlingFactory :: create ( CrawlingFactory :: TYPE_HEADLESS_BROWSER , $ this -> config ) ; } else { $ scrapClient = CrawlingFactory :: create ( CrawlingFactory :: TYPE_GOUTTE ... | create and configure client used for scrapping it will configure goutte client by default |
50,918 | public function traverseChildren ( Link $ sourceUrl , $ childLinks , $ depth ) { foreach ( $ childLinks as $ url => $ info ) { $ filterCallback = $ this -> filterCallback ; $ childLink = new Link ( $ url , $ sourceUrl ) ; $ hash = $ childLink -> getAbsoluteUrl ( false ) ; $ this -> links [ $ hash ] = $ childLink ; if (... | Crawl child links |
50,919 | public function extractLinksInfo ( DomCrawler $ crawler , Link $ pageLink ) { $ childLinks = array ( ) ; $ crawler -> filter ( 'a' ) -> each ( function ( DomCrawler $ node , $ i ) use ( & $ childLinks , $ pageLink ) { $ nodeText = trim ( $ node -> html ( ) ) ; $ href = $ node -> extract ( 'href' ) [ 0 ] ; if ( empty ( ... | Extract links information from url |
50,920 | public function filterByDepth ( $ depth ) { return $ this -> filter ( function ( Link $ link ) use ( $ depth ) { return $ link -> getCrawlDepth ( ) == $ depth ; } ) -> map ( function ( Link $ link ) { return [ 'source_page' => $ link -> getParentUrl ( ) , 'link' => $ link -> getAbsoluteUrl ( ) , ] ; } ) ; } | getting links in specific depth |
50,921 | public function getBrokenLinks ( $ showSummaryInfo = false ) { $ brokenLinks = $ this -> filter ( function ( Link $ link ) { return $ link -> isVisited ( ) !== Link :: STATUS_NOT_VISITED && $ link -> checkCrawlableStatusCode ( ) === false ; } ) ; return $ showSummaryInfo === false ? $ brokenLinks : $ brokenLinks -> map... | getting broken links |
50,922 | public function groupLinksByDepth ( ) { $ final_items = [ ] ; $ this -> each ( function ( Link $ linkObj , $ uri ) use ( & $ final_items ) { $ final_items [ $ linkObj -> getCrawlDepth ( ) ] [ $ uri ] = [ 'link' => $ linkObj -> getAbsoluteUrl ( ) , 'source_page' => $ linkObj -> getParentUrl ( ) , ] ; } ) ; ksort ( $ fin... | getting links grouped by depth of first traversing |
50,923 | function getIntrospectionXML ( ) { $ xml = "<?xml version='1.0' ?><introspection version='1.0'><methodList>" ; if ( isset ( $ this -> methods ) && is_array ( $ this -> methods ) ) { foreach ( $ this -> methods as $ method => $ methodData ) { if ( is_array ( $ methodData [ 'call' ] ) ) { $ reflection = new ReflectionMet... | This method returns an XML document in the introspection format expected by xmlrpc_server_register_introspection_callback . It uses the php Reflection classes to gather information from the registered methods . Descriptions are added from phpdoc docblocks if found . |
50,924 | public function parse ( $ commentBlock ) { $ this -> currentTag = 'description' ; $ description = preg_replace ( '/^(\s*(\/\*\*|\*\/|\*))/m' , '' , $ commentBlock ) ; $ info = array ( ) ; $ lines = explode ( "\n" , $ description ) ; foreach ( $ lines as $ line ) { $ info = $ this -> parseLine ( $ line , $ info ) ; } re... | This method parses a given docComment block and returns an array with information . |
50,925 | private function parseLine ( $ line , $ info ) { $ handled = false ; if ( preg_match ( '/^\s*(@[a-z]+)\s(.*)$/i' , $ line , $ matches ) ) { $ this -> currentTag = substr ( $ matches [ 1 ] , 1 ) ; $ line = trim ( substr ( $ line , strlen ( $ this -> currentTag ) + 2 ) ) ; switch ( $ this -> currentTag ) { case 'param' :... | This method parses a single line from the comment block . |
50,926 | private function parseDescription ( $ line ) { while ( preg_match ( '/{@([^}]*)}/' , $ line , $ matches ) ) { switch ( $ matches [ 1 ] ) { case 'internal' : $ line = str_replace ( $ matches [ 0 ] , '' , $ line ) ; break ; default : $ line = str_replace ( $ matches [ 0 ] , $ matches [ 1 ] , $ line ) ; break ; } } $ line... | This method parses only the text description part of a line of the comment block . |
50,927 | public function addService ( $ service , $ serviceName = 0 ) { if ( is_object ( $ service ) ) { $ reflection = new ReflectionObject ( $ service ) ; } else if ( is_string ( $ service ) && class_exists ( $ service ) ) { $ reflection = new ReflectionClass ( $ service ) ; } else if ( is_callable ( $ service ) ) { $ this ->... | Allows you to add a service to the server after construction . |
50,928 | public function addMethod ( $ name , $ method ) { $ this -> methods [ $ name ] = array ( 'name' => $ name , 'call' => $ method ) ; xmlrpc_server_register_method ( $ this -> xmlrpc , $ name , array ( $ this , 'call' ) ) ; } | Allows you to add a single method to the server after construction . |
50,929 | private function parseRequest ( $ request_xml ) { $ xml = @ simplexml_load_string ( $ request_xml ) ; if ( ! $ xml && ! $ xml -> getNamespaces ( ) ) { return xmlrpc_encode_request ( null , ripcord :: fault ( - 3 , 'Invalid Method Call - Ripcord Server accepts only XML-RPC, SimpleRPC or SOAP 1.1 calls' ) , $ this -> out... | This method wraps around xmlrpc_decode_request since it is borken in many ways . This wraps around all the ugliness needed to make it not dump core and not print expat warnings . |
50,930 | private function multiCall ( $ params = null ) { if ( $ params && is_array ( $ params ) ) { $ result = array ( ) ; $ params = $ params [ 0 ] ; foreach ( $ params as $ param ) { $ method = $ param [ 'methodName' ] ; $ args = $ param [ 'params' ] ; try { $ result [ ] = array ( $ this -> call ( $ method , $ args ) ) ; } c... | This method implements the system . multiCall method without dumping core . The built - in method from the xmlrpc library dumps core when you have registered any php methods fixed in php 5 . 3 . 2 |
50,931 | public function handle ( $ request_xml ) { $ result = $ this -> parseRequest ( $ request_xml ) ; if ( ! $ result || ripcord :: isFault ( $ result ) ) { return $ result ; } else { $ method = $ result [ 'methodName' ] ; $ params = $ result [ 'params' ] ; } if ( $ method == 'system.multiCall' || $ method == 'system.multic... | Handles the given request xml |
50,932 | public function setOutputOption ( $ option , $ value ) { if ( isset ( $ this -> outputOptions [ $ option ] ) ) { $ this -> outputOptions [ $ option ] = $ value ; return true ; } else { return false ; } } | Allows you to set specific output options of the server after construction . |
50,933 | public function post ( $ url , $ request ) { $ options = array_merge ( $ this -> options , array ( 'http' => array ( 'method' => "POST" , 'header' => "Content-Type: text/xml" , 'content' => $ request ) ) ) ; $ context = stream_context_create ( $ options ) ; $ result = @ file_get_contents ( $ url , false , $ context ) ;... | This method posts the request to the given url . |
50,934 | public function post ( $ url , $ request ) { $ curl = curl_init ( ) ; $ options = ( array ) $ this -> options + array ( CURLOPT_RETURNTRANSFER => 1 , CURLOPT_URL => $ url , CURLOPT_POST => true , CURLOPT_POSTFIELDS => $ request , CURLOPT_HEADER => true ) ; curl_setopt_array ( $ curl , $ options ) ; $ contents = curl_ex... | This method posts the request to the given url |
50,935 | public function connect ( $ db = null , $ username = null , $ password = null , array $ array = [ ] ) { $ this -> db = $ db ? : $ this -> db ; $ this -> username = $ username ? : $ this -> username ; $ this -> password = $ password ? : $ this -> password ; $ this -> auth ( $ this -> db , $ this -> username , $ this -> ... | Login to Odoo ERP . |
50,936 | public function can ( $ permission , $ model , $ withExceptions = false ) { if ( ! is_array ( $ permission ) ) $ permission = [ $ permission ] ; $ can = collect ( $ this -> object -> execute_kw ( $ this -> db , $ this -> uid , $ this -> password , $ model , 'check_access_rights' , $ permission , array ( 'raise_exceptio... | Check access rights on a model . return true or a string with the error . |
50,937 | public function where ( $ field , $ operator , $ value = null ) { if ( func_num_args ( ) === 2 ) $ new = [ $ field , '=' , $ operator ] ; else $ new = func_get_args ( ) ; $ this -> condition [ 0 ] [ ] = $ new ; return $ this ; } | Set condition for search query |
50,938 | public function limit ( $ limit , $ offset = 0 ) { $ this -> limit = $ limit ; $ this -> offset = $ offset ; return $ this ; } | Limit helps to only retrieve a subset of all matched records second parameter offset to start from that value . |
50,939 | public function search ( $ model ) { $ method = 'search' ; $ condition = $ this -> condition ? : [ [ ] ] ; $ params = $ this -> buildParams ( 'limit' , 'offset' ) ; $ result = $ this -> call ( $ model , $ method , $ condition , $ params ) ; $ this -> resetParams ( 'limit' , 'offset' , 'condition' ) ; return $ this -> m... | Get the ids of the models . |
50,940 | public function count ( $ model ) { $ method = 'search_count' ; $ condition = $ this -> condition ? : [ [ ] ] ; $ result = $ this -> call ( $ model , $ method , $ condition ) ; $ this -> resetParams ( 'condition' ) ; return $ this -> makeResponse ( $ result , 0 ) ; } | Count the items in a model s table . |
50,941 | public function get ( $ model ) { $ method = 'read' ; $ ids = $ this -> search ( $ model ) ; if ( is_string ( $ ids ) ) throw new OdooException ( $ ids ) ; $ params = $ this -> buildParams ( 'fields' ) ; $ result = $ this -> call ( $ model , $ method , [ $ ids -> toArray ( ) ] , $ params ) ; $ this -> resetParams ( 'fi... | Get a list of records . |
50,942 | public function version ( $ key = null ) { $ urlCommon = $ this -> setApiEndPoint ( $ this -> commonEndPoint ) ; $ version = collect ( $ this -> getClient ( $ urlCommon ) -> version ( ) ) ; return $ this -> makeResponse ( $ version , $ key ) ; } | Retrieve Odoo version . If key passed it returns the key value of the collection No need authentication |
50,943 | public function fieldsOf ( $ model ) { $ method = 'fields_get' ; $ result = $ this -> call ( $ model , $ method , [ ] ) ; return $ this -> makeResponse ( $ result ) ; } | Get a collection of fields of a model table . |
50,944 | public function create ( $ model , array $ data ) { $ method = 'create' ; $ result = $ this -> call ( $ model , $ method , [ $ data ] ) ; return $ this -> makeResponse ( $ result , 0 ) ; } | Create a single record and return its database identifier . |
50,945 | public function update ( $ model , array $ data ) { if ( $ this -> hasNotProvided ( $ this -> condition ) ) return "To prevent updating all records you must provide at least one condition. Using where method would solve this." ; $ method = 'write' ; $ ids = $ this -> search ( $ model ) ; if ( is_string ( $ ids ) ) thro... | Update one or more records . returns true except when an error happened . |
50,946 | public function deleteById ( $ model , $ id ) { if ( $ id instanceof Collection ) $ id = $ id -> toArray ( ) ; $ method = 'unlink' ; $ result = $ this -> call ( $ model , $ method , [ $ id ] ) ; return $ this -> makeResponse ( $ result , 0 ) ; } | Remove a record by Id or Ids . returns true except when an error happened . |
50,947 | public function delete ( $ model ) { if ( $ this -> hasNotProvided ( $ this -> condition ) ) return "To prevent deleting all records you must provide at least one condition. Using where method would solve this." ; $ ids = $ this -> search ( $ model ) ; if ( is_string ( $ ids ) ) throw new OdooException ( $ ids ) ; retu... | Remove one or a group of records . returns true except when an error happened . |
50,948 | public function call ( $ params ) { $ this -> autoConnect ( ) ; $ args = array_merge ( [ $ this -> db , $ this -> uid , $ this -> password ] , func_get_args ( ) ) ; return collect ( call_user_func_array ( [ $ this -> object , 'execute_kw' ] , $ args ) ) ; } | Run execute_kw call with provided params . |
50,949 | private function auth ( $ db , $ username , $ password , array $ array = [ ] ) { $ urlCommon = $ this -> setApiEndPoint ( $ this -> commonEndPoint ) ; $ urlActions = $ this -> setApiEndPoint ( $ this -> objectEndPoint ) ; $ this -> common = $ this -> getClient ( $ urlCommon ) ; $ this -> object = $ this -> getClient ( ... | Authenticate into Odoo ERP . |
50,950 | private function setApiEndPoint ( $ endPoint ) { if ( empty ( $ this -> host ) ) throw new OdooException ( 'You must provide the odoo host by host setter method' ) ; return $ this -> host . $ this -> suffix . $ endPoint ; } | Set the Full API endpoint |
50,951 | private function resetParams ( $ params ) { $ keys = is_array ( $ params ) ? $ params : func_get_args ( ) ; foreach ( $ keys as $ key ) { if ( property_exists ( $ this , $ key ) ) $ this -> $ key = null ; } } | Reset extra data to base values |
50,952 | private function buildParams ( $ params ) { $ keys = is_array ( $ params ) ? $ params : func_get_args ( ) ; $ array = [ ] ; foreach ( $ keys as $ key ) { if ( property_exists ( $ this , $ key ) ) $ array = array_merge ( $ array , [ $ key => $ this -> $ key ] ) ; } return $ array ; } | Create an array based on the passed keys . Those keys are properties of this class . |
50,953 | private function makeResponse ( $ result , $ key = null , $ cast = null ) { if ( array_key_exists ( 'faultCode' , $ result -> toArray ( ) ) ) return $ result [ 'faultCode' ] ; if ( ! is_null ( $ key ) && array_key_exists ( $ key , $ result -> toArray ( ) ) ) $ result = $ result -> get ( $ key ) ; if ( $ cast ) settype ... | Prepare the api response . If there is a faultCode then return its value . If key passed returns the value of that key . Otherwise return the provided data . |
50,954 | private function loadConfigData ( ) { $ config = laradooConfig ( ) ; $ this -> suffix = array_key_exists ( 'api-suffix' , $ config ) ? $ config [ 'api-suffix' ] : $ this -> suffix ; $ this -> suffix = laradooAddCharacter ( $ this -> suffix , '/' ) ; $ this -> host = array_key_exists ( 'host' , $ config ) ? $ config [ '... | Load data from config file . |
50,955 | public static function documentor ( $ options = null , $ docCommentParser = null ) { self :: load ( 'Ripcord_Documentor' ) ; if ( ! $ docCommentParser ) { $ docCommentParser = new Ripcord_Documentor_Parser_phpdoc ( ) ; } return new Ripcord_Documentor ( $ options , $ docCommentParser ) ; } | This method returns a new Ripcord documentor object . |
50,956 | public static function soapClient ( $ url , $ options = null , $ transport = null ) { $ options [ 'version' ] = 'soap 1.1' ; return self :: client ( $ url , $ options , $ transport ) ; } | This method returns a new Ripcord client configured to access a SOAP 1 . 1 server . |
50,957 | public static function xmlrpcClient ( $ url , $ options = null , $ transport = null ) { $ options [ 'version' ] = 'xmlrpc' ; return self :: client ( $ url , $ options , $ transport ) ; } | This method returns a new Ripcord client configured to access an XML - RPC server . |
50,958 | public static function simpleClient ( $ url , $ options = null , $ transport = null ) { $ options [ 'version' ] = 'simple' ; return self :: client ( $ url , $ options , $ transport ) ; } | This method returns a new Ripcord client configured to access a Simple RPC server . |
50,959 | public static function load ( $ class ) { if ( substr ( $ class , 0 , 8 ) == 'Ripcord_' ) { $ root = dirname ( __FILE__ ) . '/ripcord_' ; $ class = substr ( $ class , 8 ) ; $ file = str_replace ( '.' , '' , $ class ) ; $ file = str_replace ( '_' , '/' , $ file ) ; $ file = strtolower ( $ file ) ; while ( $ file && $ fi... | This method includes a ripcord class using require_once . Used for autoloading ripcord classes . |
50,960 | public static function encodeCall ( ) { self :: load ( 'Ripcord_Client' ) ; $ params = func_get_args ( ) ; $ method = array_shift ( $ params ) ; return new Ripcord_Client_Call ( $ method , $ params ) ; } | This method creates a new Ripcord_Client_Call object which encodes the information needed for a method call to an rpc server . This is mostly used for the system . multiCall method . |
50,961 | public function getFilteredNamedPolicy ( $ ptype , $ fieldIndex , ... $ fieldValues ) { return $ this -> model -> getFilteredPolicy ( 'p' , $ ptype , $ fieldIndex , ... $ fieldValues ) ; } | gets all the authorization rules in the named policy field filters can be specified . |
50,962 | public function getFilteredNamedGroupingPolicy ( $ ptype , $ fieldIndex , ... $ fieldValues ) { return $ this -> model -> getFilteredPolicy ( 'g' , $ ptype , $ fieldIndex , ... $ fieldValues ) ; } | gets all the role inheritance rules in the policy field filters can be specified . |
50,963 | public function addNamedPolicy ( $ ptype , ... $ params ) { $ ruleAdded = false ; if ( 1 == count ( $ params ) && is_array ( $ params [ 0 ] ) ) { $ strSlice = $ params [ 0 ] ; $ ruleAdded = $ this -> addPolicyInternal ( 'p' , $ ptype , $ strSlice ) ; } else { $ policy = [ ] ; foreach ( $ params as $ param ) { $ policy ... | AddNamedPolicy adds an authorization rule to the current named policy . If the rule already exists the function returns false and the rule will not be added . Otherwise the function returns true by adding the new rule . |
50,964 | public function removeNamedPolicy ( $ ptype , ... $ params ) { $ ruleRemoved = false ; if ( 1 == count ( $ params ) && is_array ( $ params [ 0 ] ) ) { $ strSlice = $ params [ 0 ] ; $ ruleAdded = $ this -> removePolicyInternal ( 'p' , $ ptype , $ strSlice ) ; } else { $ policy = [ ] ; foreach ( $ params as $ param ) { $... | removes an authorization rule from the current named policy . |
50,965 | public function hasNamedGroupingPolicy ( $ ptype , ... $ params ) { if ( 1 == count ( $ params ) && is_array ( $ params [ 0 ] ) ) { $ strSlice = $ params [ 0 ] ; return $ this -> model -> hasPolicy ( 'g' , $ ptype , $ strSlice ) ; } $ policy = [ ] ; foreach ( $ params as $ param ) { $ policy [ ] = $ param ; } return $ ... | determines whether a named role inheritance rule exists . |
50,966 | public function addNamedGroupingPolicy ( $ ptype , ... $ params ) { $ ruleAdded = false ; if ( 1 == count ( $ params ) && is_array ( $ params [ 0 ] ) ) { $ strSlice = $ params [ 0 ] ; $ ruleAdded = $ this -> addPolicyInternal ( 'g' , $ ptype , $ strSlice ) ; } else { $ policy = [ ] ; foreach ( $ params as $ param ) { $... | AddNamedGroupingPolicy adds a named role inheritance rule to the current policy . If the rule already exists the function returns false and the rule will not be added . Otherwise the function returns true by adding the new rule . |
50,967 | public function removeNamedGroupingPolicy ( $ ptype , ... $ params ) { $ ruleRemoved = false ; if ( 1 == count ( $ params ) && is_array ( $ params [ 0 ] ) ) { $ strSlice = $ params [ 0 ] ; $ ruleRemoved = $ this -> removePolicyInternal ( 'g' , $ ptype , $ strSlice ) ; } else { $ policy = [ ] ; foreach ( $ params as $ p... | removes a role inheritance rule from the current named policy . |
50,968 | public function removeFilteredNamedGroupingPolicy ( $ ptype , $ fieldIndex , ... $ fieldValues ) { $ ruleRemoved = $ this -> removeFilteredPolicyInternal ( 'g' , $ ptype , $ fieldIndex , ... $ fieldValues ) ; if ( $ this -> autoBuildRoleLinks ) { $ this -> buildRoleLinks ( ) ; } return $ ruleRemoved ; } | removes a role inheritance rule from the current named policy field filters can be specified . |
50,969 | public function set ( $ key , $ value ) { if ( 0 == \ strlen ( $ key ) ) { throw new CasbinException ( 'key is empty' ) ; } $ section = '' ; $ keys = explode ( '::' , strtolower ( $ key ) ) ; if ( \ count ( $ keys ) >= 2 ) { $ section = $ keys [ 0 ] ; $ option = $ keys [ 1 ] ; } else { $ option = $ keys [ 0 ] ; } $ thi... | sets the value for the specific key in the Config . |
50,970 | public function get ( $ key ) { $ keys = explode ( '::' , $ key ) ; if ( \ count ( $ keys ) >= 2 ) { $ section = $ keys [ 0 ] ; $ option = $ keys [ 1 ] ; } else { $ section = self :: DEFAULT_SECTION ; $ option = $ keys [ 0 ] ; } return isset ( $ this -> data [ $ section ] [ $ option ] ) ? $ this -> data [ $ section ] [... | section . key or key . |
50,971 | public function initWithFile ( $ modelPath , $ policyPath ) { $ adapter = new FileAdapter ( $ policyPath ) ; $ this -> initWithAdapter ( $ modelPath , $ adapter ) ; } | initializes an enforcer with a model file and a policy file . |
50,972 | public function initWithModelAndAdapter ( Model $ m , $ adapter ) { $ this -> adapter = $ adapter ; $ this -> model = $ m ; $ this -> model -> printModel ( ) ; $ this -> fm = Model :: loadFunctionMap ( ) ; $ this -> initialize ( ) ; if ( null !== $ this -> adapter ) { try { $ this -> loadPolicy ( ) ; } catch ( \ Except... | initWithModelAndAdapter initializes an enforcer with a model and a database adapter . |
50,973 | public static function newModel ( ... $ text ) { $ model = new Model ( ) ; if ( 2 == \ count ( $ text ) ) { if ( '' != $ text [ 0 ] ) { $ model -> loadModel ( $ text [ 0 ] ) ; } } elseif ( 1 == \ count ( $ text ) ) { $ model -> loadModelFromText ( $ text [ 0 ] ) ; } elseif ( 0 != \ count ( $ text ) ) { throw new Casbin... | creates a model . |
50,974 | public function setModel ( Model $ model ) { $ this -> model = $ model ; $ this -> fm = $ this -> model -> loadFunctionMap ( ) ; } | sets the current model . |
50,975 | public function setWatcher ( Watcher $ watcher ) { $ this -> watcher = $ watcher ; $ this -> watcher -> setUpdateCallback ( function ( ) { $ this -> loadPolicy ( ) ; } ) ; } | sets the current watcher . |
50,976 | public function isFiltered ( ) { if ( ! $ this -> adapter instanceof FilteredAdapter ) { return false ; } $ filteredAdapter = $ this -> adapter ; $ filteredAdapter -> isFiltered ( ) ; } | returns true if the loaded policy has been filtered . |
50,977 | public static function keyMatchFunc ( ... $ args ) { $ name1 = $ args [ 0 ] ; $ name2 = $ args [ 1 ] ; return self :: keyMatch ( $ name1 , $ name2 ) ; } | the wrapper for KeyMatch . |
50,978 | public static function keyMatch2Func ( ... $ args ) { $ name1 = $ args [ 0 ] ; $ name2 = $ args [ 1 ] ; return self :: keyMatch2 ( $ name1 , $ name2 ) ; } | the wrapper for KeyMatch2 . |
50,979 | public static function keyMatch3Func ( ... $ args ) { $ name1 = $ args [ 0 ] ; $ name2 = $ args [ 1 ] ; return self :: keyMatch3 ( $ name1 , $ name2 ) ; } | the wrapper for KeyMatch3 . |
50,980 | public static function regexMatchFunc ( ... $ args ) { $ name1 = $ args [ 0 ] ; $ name2 = $ args [ 1 ] ; return self :: regexMatch ( $ name1 , $ name2 ) ; } | the wrapper for RegexMatch . |
50,981 | public static function iPMatch ( $ ip1 , $ ip2 ) { $ objIP1 = IP :: parse ( $ ip1 ) ; $ objIP2 = Range :: parse ( $ ip2 ) ; return $ objIP2 -> contains ( $ objIP1 ) ; } | determines whether IP address ip1 matches the pattern of IP address ip2 ip2 can be an IP address or a CIDR pattern . |
50,982 | public static function iPMatchFunc ( ... $ args ) { $ ip1 = $ args [ 0 ] ; $ ip2 = $ args [ 1 ] ; return self :: iPMatch ( $ ip1 , $ ip2 ) ; } | the wrapper for IPMatch . |
50,983 | public static function loadFunctionMap ( ) { $ fm = new self ( ) ; $ fm -> addFunction ( 'keyMatch' , function ( ... $ args ) { return BuiltinOperations :: keyMatchFunc ( ... $ args ) ; } ) ; $ fm -> addFunction ( 'keyMatch2' , function ( ... $ args ) { return BuiltinOperations :: keyMatch2Func ( ... $ args ) ; } ) ; $... | loads an initial function map . |
50,984 | public function getRoles ( $ name , ... $ domain ) { if ( 1 == \ count ( $ domain ) ) { $ name = $ domain [ 0 ] . '::' . $ name ; } elseif ( \ count ( $ domain ) > 1 ) { throw new CasbinException ( 'error: domain should be 1 parameter' ) ; } if ( ! $ this -> hasRole ( $ name ) ) { return [ ] ; } $ roles = $ this -> cre... | gets the roles that a subject inherits . domain is a prefix to the roles . |
50,985 | public function getUsers ( $ name , ... $ domain ) { if ( ! $ this -> hasRole ( $ name ) ) { throw new CasbinException ( 'error: name does not exist' ) ; } $ names = [ ] ; array_map ( function ( $ role ) use ( & $ names , $ name ) { if ( $ role -> hasDirectRole ( $ name ) ) { $ names [ ] = $ role -> name ; } } , $ this... | gets the users that inherits a subject . domain is an unreferenced parameter here may be used in other implementations . |
50,986 | public function printRoles ( ) { $ line = [ ] ; array_map ( function ( $ role ) use ( & $ line ) { if ( $ text = $ role -> toString ( ) ) { $ line [ ] = $ text ; } } , $ this -> allRoles ) ; Log :: logPrint ( implode ( ', ' , $ line ) ) ; } | prints all the roles to log . |
50,987 | public function buildRoleLinks ( $ rm ) { if ( ! isset ( $ this -> model [ 'g' ] ) ) { return ; } foreach ( $ this -> model [ 'g' ] as $ ast ) { $ ast -> buildRoleLinks ( $ rm ) ; } } | initializes the roles in RBAC . |
50,988 | public function printPolicy ( ) { Log :: logPrint ( 'Policy:' ) ; foreach ( [ 'p' , 'g' ] as $ sec ) { if ( ! isset ( $ this -> model [ $ sec ] ) ) { return ; } foreach ( $ this -> model [ $ sec ] as $ key => $ ast ) { Log :: logPrint ( $ key , ': ' , $ ast -> value , ': ' , $ ast -> policy ) ; } } } | prints the policy to log . |
50,989 | public function clearPolicy ( ) { foreach ( [ 'p' , 'g' ] as $ sec ) { if ( ! isset ( $ this -> model [ $ sec ] ) ) { return ; } foreach ( $ this -> model [ $ sec ] as $ key => $ ast ) { $ this -> model [ $ sec ] [ $ key ] -> policy = [ ] ; } } } | clears all current policy . |
50,990 | public function getFilteredPolicy ( $ sec , $ ptype , $ fieldIndex , ... $ fieldValues ) { $ res = [ ] ; foreach ( $ this -> model [ $ sec ] [ $ ptype ] -> policy as $ rule ) { $ matched = true ; foreach ( $ fieldValues as $ i => $ fieldValue ) { if ( '' != $ fieldValue && $ rule [ $ fieldIndex + $ i ] != $ fieldValue ... | gets rules based on field filters from a policy . |
50,991 | public function hasPolicy ( $ sec , $ ptype , $ rule ) { if ( ! isset ( $ this -> model [ $ sec ] [ $ ptype ] ) ) { return false ; } foreach ( $ this -> model [ $ sec ] [ $ ptype ] -> policy as $ r ) { if ( empty ( array_diff ( $ rule , $ r ) ) ) { return true ; } } return false ; } | determines whether a model has the specified policy rule . |
50,992 | public function addPolicy ( $ sec , $ ptype , array $ rule ) { if ( ! $ this -> hasPolicy ( $ sec , $ ptype , $ rule ) ) { $ this -> model [ $ sec ] [ $ ptype ] -> policy [ ] = $ rule ; return true ; } return false ; } | adds a policy rule to the model . |
50,993 | public function removePolicy ( $ sec , $ ptype , array $ rule ) { foreach ( $ this -> model [ $ sec ] [ $ ptype ] -> policy as $ i => $ r ) { if ( empty ( array_diff ( $ rule , $ r ) ) ) { array_splice ( $ this -> model [ $ sec ] [ $ ptype ] -> policy , $ i , 1 ) ; return true ; } } return false ; } | removes a policy rule from the model . |
50,994 | public function removeFilteredPolicy ( $ sec , $ ptype , $ fieldIndex , ... $ fieldValues ) { $ tmp = [ ] ; $ res = false ; if ( ! isset ( $ this -> model [ $ sec ] [ $ ptype ] ) ) { return $ res ; } foreach ( $ this -> model [ $ sec ] [ $ ptype ] -> policy as $ rule ) { $ matched = true ; foreach ( $ fieldValues as $ ... | removes policy rules based on field filters from the model . |
50,995 | public function getValuesForFieldInPolicy ( $ sec , $ ptype , $ fieldIndex ) { $ values = [ ] ; if ( ! isset ( $ this -> model [ $ sec ] [ $ ptype ] ) ) { return $ values ; } foreach ( $ this -> model [ $ sec ] [ $ ptype ] -> policy as $ rule ) { $ values [ ] = $ rule [ $ fieldIndex ] ; } Util :: arrayRemoveDuplicates ... | gets all values for a field for all rules in a policy duplicated values are removed . |
50,996 | public static function escapeAssertion ( $ s ) { if ( 0 === strpos ( $ s , 'r.' ) ) { $ s = substr_replace ( $ s , 'r_' , 0 , 2 ) ; } if ( 0 === strpos ( $ s , 'p.' ) ) { $ s = substr_replace ( $ s , 'p_' , 0 , 2 ) ; } $ s = preg_replace_callback ( "~(\|| |=|\)|\(|&|<|>|,|\+|-|!|\*|\/)(r|p)(\.)~" , function ( $ m ) { r... | escapes the dots in the assertion because the expression evaluation doesn t support such variable names . |
50,997 | public static function arrayRemoveDuplicates ( & $ s ) { $ found = [ ] ; $ j = 0 ; foreach ( $ s as $ i => $ x ) { if ( ! isset ( $ found [ $ x ] ) ) { $ found [ $ x ] = true ; $ s [ $ j ] = $ s [ $ i ] ; ++ $ j ; } } $ s = \ array_slice ( $ s , 0 , $ j ) ; } | removes any duplicated elements in a string array . |
50,998 | public function mergeEffects ( $ expr , array $ effects , array $ results ) { $ result = false ; if ( 'some(where (p_eft == allow))' == $ expr ) { foreach ( $ effects as $ eft ) { if ( self :: ALLOW == $ eft ) { $ result = true ; break ; } } } elseif ( '!some(where (p_eft == deny))' == $ expr ) { $ result = true ; fore... | merges all matching results collected by the enforcer into a single decision . |
50,999 | public function hasRoleForUser ( $ name , $ role ) { $ roles = $ this -> getRolesForUser ( $ name ) ; $ hasRole = false ; foreach ( $ roles as $ r ) { if ( $ r == $ role ) { $ hasRole = true ; break ; } } return $ hasRole ; } | determines whether a user has a role . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.