idx
int64 0
60.3k
| question
stringlengths 64
4.24k
| target
stringlengths 5
618
|
|---|---|---|
47,200
|
public function validate ( Request $ request ) { $ prefix = $ this -> filterAndExplode ( $ this -> prefix ) ; $ path = $ this -> filterAndExplode ( $ request -> getPathInfo ( ) ) ; return ! \ is_null ( $ this -> prefix ) && $ prefix == \ array_slice ( $ path , 0 , \ count ( $ prefix ) ) ; }
|
Validate the request has a prefix and if it matches the configured API prefix .
|
47,201
|
protected function scopes ( $ scopes , array $ options = [ ] ) { $ scopes = $ this -> getPropertyValue ( $ scopes ) ; $ this -> scopes [ ] = \ compact ( 'scopes' , 'options' ) ; }
|
Add scopes to controller methods .
|
47,202
|
protected function authenticateWith ( $ providers , array $ options = [ ] ) { $ providers = $ this -> getPropertyValue ( $ providers ) ; $ this -> authenticationProviders [ ] = \ compact ( 'providers' , 'options' ) ; }
|
Authenticate with certain providers on controller methods .
|
47,203
|
public function group ( array $ attributes , $ callback ) { if ( ! isset ( $ attributes [ 'conditionalRequest' ] ) ) { $ attributes [ 'conditionalRequest' ] = $ this -> conditionalRequest ; } $ attributes = $ this -> mergeLastGroupAttributes ( $ attributes ) ; if ( ! isset ( $ attributes [ 'version' ] ) ) { throw new RuntimeException ( 'A version is required for an API group definition.' ) ; } else { $ attributes [ 'version' ] = ( array ) $ attributes [ 'version' ] ; } if ( ( ! isset ( $ attributes [ 'prefix' ] ) || empty ( $ attributes [ 'prefix' ] ) ) && isset ( $ this -> prefix ) ) { $ attributes [ 'prefix' ] = $ this -> prefix ; } if ( ( ! isset ( $ attributes [ 'domain' ] ) || empty ( $ attributes [ 'domain' ] ) ) && isset ( $ this -> domain ) ) { $ attributes [ 'domain' ] = $ this -> domain ; } $ this -> groupStack [ ] = $ attributes ; \ call_user_func ( $ callback , $ this ) ; \ array_pop ( $ this -> groupStack ) ; }
|
Create a new route group .
|
47,204
|
public function match ( $ methods , $ uri , $ action ) { return $ this -> addRoute ( \ array_map ( 'strtoupper' , ( array ) $ methods ) , $ uri , $ action ) ; }
|
Create a new route with the given verbs .
|
47,205
|
public function resources ( array $ resources ) { foreach ( $ resources as $ name => $ resource ) { $ options = [ ] ; if ( \ is_array ( $ resource ) ) { list ( $ resource , $ options ) = $ resource ; } $ this -> resource ( $ name , $ resource , $ options ) ; } }
|
Register an array of resources .
|
47,206
|
public function collection ( Collection $ collection , $ transformer , $ parameters = [ ] , Closure $ after = null ) { if ( $ collection -> isEmpty ( ) ) { $ class = \ get_class ( $ collection ) ; } else { $ class = \ get_class ( $ collection -> first ( ) ) ; } if ( $ parameters instanceof \ Closure ) { $ after = $ parameters ; $ parameters = [ ] ; } $ binding = $ this -> transformer -> register ( $ class , $ transformer , $ parameters , $ after ) ; return new Response ( $ collection , 200 , [ ] , $ binding ) ; }
|
Bind a collection to a transformer and start building a response .
|
47,207
|
public function paginator ( Paginator $ paginator , $ transformer , array $ parameters = [ ] , Closure $ after = null ) { if ( $ paginator -> isEmpty ( ) ) { $ class = \ get_class ( $ paginator ) ; } else { $ class = \ get_class ( $ paginator -> first ( ) ) ; } $ binding = $ this -> transformer -> register ( $ class , $ transformer , $ parameters , $ after ) ; return new Response ( $ paginator , 200 , [ ] , $ binding ) ; }
|
Bind a paginator to a transformer and start building a response .
|
47,208
|
protected function watch ( ) { if ( $ this -> id ) { $ this -> bag -> remove ( $ this ) ; } $ this -> id = $ this -> addWatch ( ) ; $ this -> bag -> add ( $ this ) ; }
|
Starts to track current resource
|
47,209
|
protected function fromInotifyMask ( $ mask ) { $ mask &= ~ IN_ISDIR ; $ event = 0 ; switch ( $ mask ) { case ( IN_MODIFY ) : case ( IN_ATTRIB ) : $ event = FilesystemEvent :: MODIFY ; break ; case ( IN_CREATE ) : $ event = FilesystemEvent :: CREATE ; break ; case ( IN_DELETE ) : case ( IN_IGNORED ) : $ event = FilesystemEvent :: DELETE ; } return $ this -> supportsEvent ( $ event ) ? $ event : false ; }
|
Transforms inotify event to FilesystemEvent event
|
47,210
|
protected function createChildCheckers ( ) { foreach ( $ this -> getResource ( ) -> getFilteredResources ( ) as $ resource ) { $ resource instanceof DirectoryResource ? $ this -> directories [ basename ( ( string ) $ resource ) ] = new DirectoryStateChecker ( $ this -> getBag ( ) , $ resource , $ this -> getEventsMask ( ) ) : $ this -> files [ basename ( ( string ) $ resource ) ] = $ resource ; } }
|
Reads files and subdirectories and transforms them to resources .
|
47,211
|
protected function reindexChildCheckers ( ) { $ this -> fileEvents = array_fill_keys ( array_keys ( $ this -> files ) , IN_DELETE ) ; $ this -> dirEvents = array_fill_keys ( array_keys ( $ this -> directories ) , IN_DELETE ) ; foreach ( $ this -> getResource ( ) -> getFilteredResources ( ) as $ resource ) { $ basename = basename ( ( string ) $ resource ) ; if ( $ resource instanceof FileResource ) { if ( isset ( $ this -> files [ $ basename ] ) ) { $ this -> fileEvents [ $ basename ] = IN_MODIFY ; } else { $ this -> files [ $ basename ] = $ resource ; $ this -> fileEvents [ $ basename ] = 'new' ; } } else { isset ( $ this -> directories [ $ basename ] ) ? $ this -> dirEvents [ $ basename ] = IN_CREATE : $ this -> createNewDirectoryChecker ( $ basename , $ resource ) ; } } $ this -> watch ( ) ; }
|
Used in case the folder was deleted and than created again or situations like this . It rescans the folder files that was before get IN_MODIFY event folders - IN_CREATE - to make them to rescan itself
|
47,212
|
protected function normalizeFileEvent ( $ event , $ name ) { if ( 'new' === $ event ) { return IN_CREATE ; } $ event = $ this -> normalizeEvent ( $ event ) ; if ( isset ( $ this -> files [ $ name ] ) ) { return $ this -> isCreated ( $ event ) ? IN_MODIFY : $ event ; } if ( ! $ this -> isDeleted ( $ event ) ) { $ this -> createFileResource ( $ name ) ; return IN_CREATE ; } return null ; }
|
Normalizes file event
|
47,213
|
protected function createNewDirectoryChecker ( $ name , DirectoryResource $ resource = null ) { $ resource = $ resource ? : new DirectoryResource ( $ this -> getResource ( ) -> getResource ( ) . '/' . $ name ) ; $ this -> directories [ $ name ] = new NewDirectoryStateChecker ( $ this -> getBag ( ) , $ resource , $ this -> getEventsMask ( ) ) ; }
|
Creates new DirectoryStateChecker
|
47,214
|
protected function createFileResource ( $ name ) { if ( $ this -> getResource ( ) -> getPattern ( ) && ! preg_match ( $ this -> getResource ( ) -> getPattern ( ) , $ name ) ) { $ this -> files [ $ name ] = 'skip' ; } else { $ this -> files [ $ name ] = new FileResource ( $ this -> getResource ( ) -> getResource ( ) . '/' . $ name ) ; } }
|
Creates new FileResource
|
47,215
|
public function track ( $ trackingId , $ resource , $ eventsMask = FilesystemEvent :: ALL ) { if ( 'all' === $ trackingId ) { throw new InvalidArgumentException ( '"all" is a reserved keyword and can not be used as tracking id' ) ; } if ( ! $ resource instanceof ResourceInterface ) { if ( is_file ( $ resource ) ) { $ resource = new FileResource ( $ resource ) ; } elseif ( is_dir ( $ resource ) ) { $ resource = new DirectoryResource ( $ resource ) ; } else { throw new InvalidArgumentException ( sprintf ( 'Second argument to track() should be either file or directory resource, ' . 'but got "%s"' , $ resource ) ) ; } } $ trackedResource = new TrackedResource ( $ trackingId , $ resource ) ; $ this -> getTracker ( ) -> track ( $ trackedResource , $ eventsMask ) ; }
|
Track resource with watcher .
|
47,216
|
public function addListener ( $ trackingId , $ callback ) { if ( ! is_callable ( $ callback ) ) { throw new InvalidArgumentException ( sprintf ( 'Second argument to listen() should be callable, but got %s' , gettype ( $ callback ) ) ) ; } $ this -> getEventDispatcher ( ) -> addListener ( 'resource_watcher.' . $ trackingId , $ callback ) ; }
|
Adds callback as specific tracking listener .
|
47,217
|
public function trackByListener ( $ resource , $ callback , $ eventsMask = FilesystemEvent :: ALL ) { $ this -> track ( $ trackingId = md5 ( ( string ) $ resource . $ eventsMask ) , $ resource , $ eventsMask ) ; $ this -> addListener ( $ trackingId , $ callback ) ; }
|
Tracks specific resource change by provided callback .
|
47,218
|
public function start ( $ checkInterval = 1000000 , $ timeLimit = null ) { $ totalTime = 0 ; $ this -> watching = true ; while ( $ this -> watching ) { usleep ( $ checkInterval ) ; $ totalTime += $ checkInterval ; if ( null !== $ timeLimit && $ totalTime > $ timeLimit ) { break ; } foreach ( $ this -> getTracker ( ) -> getEvents ( ) as $ event ) { $ trackedResource = $ event -> getTrackedResource ( ) ; $ this -> getEventDispatcher ( ) -> dispatch ( 'resource_watcher.all' , $ event ) ; $ this -> getEventDispatcher ( ) -> dispatch ( sprintf ( 'resource_watcher.%s' , $ trackedResource -> getTrackingId ( ) ) , $ event ) ; } } $ this -> watching = false ; }
|
Starts watching on tracked resources .
|
47,219
|
public function add ( ResourceStateChecker $ watched ) { $ id = $ watched -> getId ( ) ; if ( ! isset ( $ this -> watched [ $ id ] ) ) { $ this -> watched [ $ id ] = new \ SplObjectStorage ( ) ; } $ this -> watched [ $ id ] -> attach ( $ watched ) ; }
|
Adds state checker to the bag .
|
47,220
|
private function assertGoodDatabaseConnection ( ) { $ connection = $ this -> entityManager -> getConnection ( ) ; if ( $ connection -> ping ( ) === false ) { $ connection -> close ( ) ; $ connection -> connect ( ) ; } }
|
Some database systems close the connection after a period of time in MySQL this is system variable wait_timeout . Given the daemon is meant to run indefinitely we need to make sure we have an open connection before working any job . Otherwise we would see MySQL has gone away type errors .
|
47,221
|
public static function create ( $ name , $ value = null , Scope $ childScope = null , Scope $ parentScope = null , Comment $ comment = null ) { return new self ( $ name , $ value , $ childScope , $ parentScope , $ comment ) ; }
|
Provides fluid interface .
|
47,222
|
public function setChildScope ( Scope $ childScope ) { $ this -> childScope = $ childScope ; if ( $ childScope -> getParentDirective ( ) !== $ this ) { $ childScope -> setParentDirective ( $ this ) ; } return $ this ; }
|
Sets the child Scope for this Directive .
|
47,223
|
public function getChar ( $ position = self :: CURRENT_POSITION ) { if ( self :: CURRENT_POSITION === $ position ) { $ position = $ this -> position ; } if ( ! is_int ( $ position ) ) { throw new Exception ( 'Position is not int. ' . gettype ( $ position ) ) ; } if ( $ this -> eof ( ) ) { throw new Exception ( 'Index out of range. Position: ' . $ position . '.' ) ; } return $ this -> data [ $ position ] ; }
|
Returns one character of the string .
|
47,224
|
public function eol ( $ position = self :: CURRENT_POSITION ) { return ( ( "\r" === $ this -> getChar ( $ position ) ) || ( "\n" === $ this -> getChar ( $ position ) ) ) ; }
|
Is this the end of line?
|
47,225
|
public function isEmptyLine ( $ position = self :: CURRENT_POSITION ) { $ line = $ this -> getCurrentLine ( $ position ) ; return ( 0 === strlen ( trim ( $ line ) ) ) ; }
|
Is this line empty?
|
47,226
|
public function getCurrentLine ( $ position = self :: CURRENT_POSITION ) { if ( self :: CURRENT_POSITION === $ position ) { $ position = $ this -> position ; } $ offset = $ this -> getLastEol ( $ position ) ; $ length = $ this -> getNextEol ( $ position ) - $ offset ; return substr ( $ this -> data , $ offset , $ length ) ; }
|
Get the current line .
|
47,227
|
public function getNextEol ( $ position = self :: CURRENT_POSITION ) { if ( self :: CURRENT_POSITION === $ position ) { $ position = $ this -> position ; } $ eolPosition = strpos ( $ this -> data , "\n" , $ position ) ; if ( false === $ eolPosition ) { $ eolPosition = strlen ( $ this -> data ) - 1 ; } return $ eolPosition ; }
|
Get the position of the next EOL .
|
47,228
|
public function saveToFile ( $ filePath ) { $ handle = @ fopen ( $ filePath , 'w' ) ; if ( false === $ handle ) { throw new Exception ( 'Cannot open file "' . $ filePath . '" for writing.' ) ; } $ bytesWritten = @ fwrite ( $ handle , ( string ) $ this ) ; if ( false === $ bytesWritten ) { fclose ( $ handle ) ; throw new Exception ( 'Cannot write into file "' . $ filePath . '".' ) ; } $ closed = @ fclose ( $ handle ) ; if ( false === $ closed ) { throw new Exception ( 'Cannot close file handle for "' . $ filePath . '".' ) ; } }
|
Write this Scope into a file .
|
47,229
|
public static function fromString ( Text $ configString ) { $ scope = new Scope ( ) ; while ( false === $ configString -> eof ( ) ) { if ( true === $ configString -> isEmptyLine ( ) ) { $ scope -> addPrintable ( EmptyLine :: fromString ( $ configString ) ) ; } $ char = $ configString -> getChar ( ) ; if ( '#' === $ char ) { $ scope -> addPrintable ( Comment :: fromString ( $ configString ) ) ; continue ; } if ( ( 'a' <= $ char ) && ( 'z' >= $ char ) ) { $ scope -> addDirective ( Directive :: fromString ( $ configString ) ) ; continue ; } if ( '}' === $ configString -> getChar ( ) ) { break ; } $ configString -> inc ( ) ; } return $ scope ; }
|
Create new Scope from the configuration string .
|
47,230
|
public function addDirective ( Directive $ directive ) { if ( $ directive -> getParentScope ( ) !== $ this ) { $ directive -> setParentScope ( $ this ) ; } $ this -> directives [ ] = $ directive ; $ this -> addPrintable ( $ directive ) ; return $ this ; }
|
Add a Directive to the list of this Scopes directives
|
47,231
|
public function setParentDirective ( Directive $ parentDirective ) { $ this -> parentDirective = $ parentDirective ; if ( $ parentDirective -> getChildScope ( ) !== $ this ) { $ parentDirective -> setChildScope ( $ this ) ; } return $ this ; }
|
Set parent directive for this Scope .
|
47,232
|
protected function validateConfig ( array $ config ) { $ validator = Validator :: make ( $ config , $ this -> getConfigValidationRules ( ) ) ; if ( $ validator -> fails ( ) ) { throw new ServiceConfigurationException ( 'Invalid configuration: ' . print_r ( $ validator -> messages ( ) -> toArray ( ) , true ) , $ validator -> messages ( ) -> toArray ( ) ) ; } }
|
Checks config against validation rules
|
47,233
|
public function call ( $ method , $ request = null , $ parameters = null , $ headers = null , $ options = [ ] ) { if ( is_a ( $ request , ServiceRequestInterface :: class ) ) { $ this -> request = $ request -> setMethod ( $ method ) ; } else { $ class = $ this -> requestDefaultsClass ; $ this -> request = new $ class ( $ request , $ parameters , $ headers , $ method , null , $ options ) ; $ this -> checkRequestClassType ( $ this -> request ) ; } $ this -> checkRequest ( ) ; $ this -> supplementRequestWithDefaults ( ) ; $ this -> resetResponseInformation ( ) ; if ( ! $ this -> firstCallIsMade ) { $ this -> firstCallIsMade = true ; $ this -> beforeFirstCall ( ) ; } $ this -> before ( ) ; $ this -> rawResponse = $ this -> callRaw ( $ this -> request ) ; $ this -> afterRaw ( ) ; $ this -> interpretResponse ( ) ; $ this -> after ( ) ; return $ this -> getLastInterpretedResponse ( ) ; }
|
Performs a call on the service returning an interpreted response
|
47,234
|
protected function interpretResponse ( ) { $ this -> response = $ this -> interpreter -> interpret ( $ this -> request , $ this -> rawResponse , $ this -> responseInformation ) ; }
|
Interprets the raw response if an interpreter is available and stores it in the response property
|
47,235
|
protected function convertXmlObjectToArray ( $ xml ) { $ array = ( array ) $ xml ; if ( count ( $ array ) == 0 && ! is_array ( $ xml ) ) { $ array = [ ( string ) $ xml ] ; } if ( is_array ( $ array ) ) { foreach ( $ array as $ key => $ value ) { if ( is_object ( $ value ) ) { if ( strpos ( get_class ( $ value ) , "SimpleXML" ) !== false ) { $ array [ $ key ] = $ this -> convertXmlObjectToArray ( $ value ) ; } else { $ array [ $ key ] = $ this -> convertXmlObjectToArray ( ( array ) $ value ) ; } } elseif ( is_array ( $ value ) ) { $ array [ $ key ] = $ this -> convertXmlObjectToArray ( $ value ) ; } } } return $ array ; }
|
Converts SimpleXml structure to array
|
47,236
|
public function setCredentials ( $ name , $ password = null , $ domain = null ) { $ credentials = $ this -> getCredentials ( ) ; $ credentials [ 'name' ] = $ name ; $ credentials [ 'password' ] = $ password ; $ credentials [ 'domain' ] = $ domain ; $ this -> setAttribute ( 'credentials' , $ credentials ) ; return $ this ; }
|
Sets the credentials to be used for the request .
|
47,237
|
public function setPort ( $ port ) { if ( ! is_null ( $ port ) ) $ port = ( int ) $ port ; $ this -> setAttribute ( 'port' , $ port ) ; return $ this ; }
|
Sets the port number
|
47,238
|
protected function getArrayForSpecialCase ( $ xml ) { $ regEx = '#\s*(<\?xml.*interface>)\s*#is' ; $ regExReplace = '#\s*>\s*(<\?xml.*interface>)\s*<[^>]+>\s*#is' ; $ regExReplaceWith = '/>' ; if ( ! preg_match ( $ regEx , $ xml ) ) { return [ 0 => $ xml ] ; } $ xml = preg_replace ( $ regExReplace , $ regExReplaceWith , $ xml ) ; return $ this -> parse ( $ xml ) ; }
|
In special cases where XML is malformed attempt to salvage the last element anyway .
|
47,239
|
public function disconnect ( ) { if ( $ this -> connected ) return false ; $ this -> exec ( 'exit;' ) ; $ this -> connection = null ; $ this -> connected = false ; return true ; }
|
Disconnects open connection .
|
47,240
|
public function exec ( $ command ) { if ( ! ( $ stream = ssh2_exec ( $ this -> connection , $ command ) ) ) { throw new Ssh2CommandException ( "Exec failed: '{$command}'." ) ; } stream_set_blocking ( $ stream , true ) ; $ data = '' ; while ( $ buf = fread ( $ stream , 4096 ) ) { $ data .= $ buf ; } fclose ( $ stream ) ; return $ data ; }
|
Executes command over connection
|
47,241
|
protected function parseFileContents ( $ file ) { try { $ data = $ this -> files -> get ( $ file ) ; } catch ( FileNotFoundException $ e ) { throw new CouldNotConnectException ( "Local file could not be found: '{$file}'" ) ; } catch ( Exception $ e ) { throw new CouldNotConnectException ( "Local file unreadable or unopenable: '{$file}'" ) ; } $ this -> request -> setMethod ( basename ( $ file ) ) ; $ information = new ServiceResponseInformation ( ) ; $ information -> setStatusCode ( 200 ) ; return $ this -> interpreter -> interpret ( $ this -> request , $ data , $ information ) ; }
|
Loads data from a local file and parses it through the interpreter
|
47,242
|
public function setHttpMethod ( $ method ) { $ method = strtoupper ( ( string ) $ method ) ; if ( ! in_array ( $ method , $ this -> allowedHttpMethods ) ) { throw new InvalidArgumentException ( "Invalid HTTP method: '{$method}'" ) ; } $ this -> setAttribute ( 'http_method' , $ method ) ; return $ this ; }
|
Sets the HTTP method name
|
47,243
|
public function addError ( $ error ) { $ errors = $ this -> getAttribute ( 'errors' ) ? : [ ] ; $ errors [ ] = $ error ; $ this -> setAttribute ( 'errors' , $ errors ) ; return $ this ; }
|
Adds a single error to the error list
|
47,244
|
public function setMessage ( $ message ) { if ( ! is_null ( $ message ) ) $ message = ( string ) $ message ; $ this -> setAttribute ( 'message' , $ message ) ; return $ this ; }
|
Sets the message or reason phrase
|
47,245
|
protected function buildDomDocumentFromXml ( $ xml ) { $ sxe = new \ SimpleXMLElement ( $ xml ) ; $ dom_sxe = dom_import_simplexml ( $ sxe ) ; $ dom = new DOMDocument ( '1.0' ) ; $ dom_sxe = $ dom -> importNode ( $ dom_sxe , true ) ; $ dom -> appendChild ( $ dom_sxe ) ; $ element = $ dom -> childNodes -> item ( 0 ) ; foreach ( $ sxe -> getDocNamespaces ( true ) as $ name => $ uri ) { $ element -> removeAttributeNS ( $ uri , $ name ) ; } return $ dom ; }
|
Strip namespaces from XML string
|
47,246
|
protected function convertDomToArray ( $ root ) { $ result = [ ] ; if ( $ root -> hasAttributes ( ) ) { $ attrs = $ root -> attributes ; foreach ( $ attrs as $ attr ) { $ result [ '@attributes' ] [ $ attr -> name ] = $ attr -> value ; } } if ( $ root -> hasChildNodes ( ) ) { $ children = $ root -> childNodes ; if ( $ children -> length == 1 ) { $ child = $ children -> item ( 0 ) ; if ( $ child -> nodeType == XML_TEXT_NODE ) { $ result [ '_value' ] = $ child -> nodeValue ; return ( count ( $ result ) == 1 ) ? $ result [ '_value' ] : $ result ; } } $ groups = [ ] ; foreach ( $ children as $ child ) { if ( ! isset ( $ result [ $ child -> nodeName ] ) ) { $ result [ $ child -> nodeName ] = $ this -> convertDomToArray ( $ child ) ; } else { if ( ! isset ( $ groups [ $ child -> nodeName ] ) ) { $ result [ $ child -> nodeName ] = array ( $ result [ $ child -> nodeName ] ) ; $ groups [ $ child -> nodeName ] = 1 ; } $ result [ $ child -> nodeName ] [ ] = $ this -> convertDomToArray ( $ child ) ; } } } return $ result ; }
|
Converts DomDocument to array with all attributes in it
|
47,247
|
public function make ( $ class , $ hostname , $ user , $ password , $ port = 22 , $ fingerprint = null ) { if ( $ class === Ssh2SftpConnectionInterface :: class ) { $ class = $ this -> getDefaultConnectionClass ( ) ; } return new $ class ( $ hostname , $ user , $ password , $ port , $ fingerprint , app ( 'files' ) ) ; }
|
Makes an SSH2SFTP connection instance .
|
47,248
|
public function make ( $ class , $ wsdl , array $ config = [ ] ) { $ reflectionClass = new ReflectionClass ( $ class ) ; $ client = $ reflectionClass -> newInstanceArgs ( [ $ wsdl , $ config ] ) ; return $ client ; }
|
Makes a SoapClient instance .
|
47,249
|
protected function makeCouldNotRetrieveExceptionFromSoapFault ( SoapFault $ soapFault ) { $ exception = new CouldNotRetrieveException ( $ soapFault -> getMessage ( ) , $ soapFault -> getCode ( ) , $ soapFault ) ; return $ exception ; }
|
Makes a generic service exception based on the given soapfault . Extend or override this to deal with specific error information that your service might respond with
|
47,250
|
protected function applySoapHeaders ( ) { $ headers = $ this -> request -> getHeaders ( ) ? : [ ] ; if ( $ headers instanceof SoapHeader ) { $ headers = [ $ headers ] ; } else { foreach ( $ headers as & $ header ) { if ( $ header instanceof SoapHeader ) continue ; $ namespace = isset ( $ header [ 'namespace' ] ) ? $ header [ 'namespace' ] : null ; $ name = isset ( $ header [ 'name' ] ) ? $ header [ 'name' ] : null ; $ data = isset ( $ header [ 'data' ] ) ? $ header [ 'data' ] : null ; $ mustUnderstand = isset ( $ header [ 'mustunderstand' ] ) ? $ header [ 'mustunderstand' ] : null ; $ actor = isset ( $ header [ 'actor' ] ) ? $ header [ 'actor' ] : null ; $ header = new SoapHeader ( $ namespace , $ name , $ data , $ mustUnderstand , $ actor ) ; } } unset ( $ header ) ; $ this -> client -> __setSoapHeaders ( $ headers ) ; }
|
Applies request s headers as soapheaders on the SoapClient
|
47,251
|
protected function parseTracedReponseInformation ( ) { if ( ! isset ( $ this -> clientOptions [ 'trace' ] ) || $ this -> clientOptions [ 'trace' ] !== true ) { return ; } $ responseHeaderString = $ this -> client -> __getLastResponseHeaders ( ) ; $ this -> responseInformation -> setStatusCode ( $ this -> parseResponseHeaderForStatusCode ( $ responseHeaderString ) ) ; $ this -> responseInformation -> setHeaders ( $ this -> parseResponseHeadersAsArray ( $ responseHeaderString ) ) ; }
|
Extracts information from SOAP client if tracing
|
47,252
|
protected function parseResponseHeadersAsArray ( $ headers ) { if ( empty ( $ headers ) ) return [ ] ; $ headersArray = [ ] ; foreach ( preg_split ( '#[\r\n]+#' , $ headers ) as $ headerString ) { if ( ! preg_match ( '#^\s*(?<name>.*?)\s*:\s*(?<value>.*)\s*$#' , $ headerString , $ matches ) ) continue ; $ headersArray [ $ matches [ 'name' ] ] = $ matches [ 'value' ] ; } return $ headersArray ; }
|
Parses a header string to an array
|
47,253
|
protected function before ( ) { if ( empty ( $ this -> client ) || empty ( $ this -> clientHash ) || $ this -> clientHash !== $ this -> makeSoapClientHash ( ) ) { $ this -> initializeClient ( ) ; } }
|
Runs before any call is made
|
47,254
|
protected function initializeClient ( ) { $ this -> wsdl = $ this -> request -> getLocation ( ) ; $ this -> clientOptions = $ this -> request -> getOptions ( ) ; $ this -> clientHash = $ this -> makeSoapClientHash ( ) ; $ xdebugEnabled = extension_loaded ( 'xdebug' ) && xdebug_is_enabled ( ) ; try { if ( $ xdebugEnabled ) xdebug_disable ( ) ; $ class = $ this -> soapClientClass ; $ this -> client = $ this -> getSoapClientFactory ( ) -> make ( $ class , $ this -> wsdl , $ this -> clientOptions ) ; if ( $ xdebugEnabled ) xdebug_enable ( ) ; } catch ( SoapFault $ e ) { throw new CouldNotConnectException ( $ e -> getMessage ( ) , $ e -> getCode ( ) , $ e ) ; } catch ( Exception $ e ) { throw new CouldNotConnectException ( $ e -> getMessage ( ) , $ e -> getCode ( ) , $ e ) ; } }
|
Initializes Soap Client with WSDL and an options array
|
47,255
|
protected function makeSoapClientHash ( ) { return sha1 ( $ this -> request -> getLocation ( ) . json_encode ( $ this -> request -> getOptions ( ) ) . json_encode ( $ this -> request -> getHeaders ( ) ) ) ; }
|
Creates a hash from the combination of all settings that need to be tracked to see whether a new soapclient should be instantiated
|
47,256
|
protected function initialize ( ) { parent :: initialize ( ) ; $ options = $ this -> defaults -> getOptions ( ) ? : [ ] ; foreach ( $ this -> soapOptionDefaults as $ option => $ value ) { if ( ! array_key_exists ( $ option , $ options ) ) { $ options [ $ option ] = $ value ; } } $ this -> defaults -> setOptions ( $ options ) ; }
|
Runs directly after construction Extend this to customize your service
|
47,257
|
protected function connectSftp ( ) { if ( ! $ this -> connected ) return false ; $ this -> ftpConnection = ssh2_sftp ( $ this -> connection ) ; return true ; }
|
Make SFTP connection over SSH2
|
47,258
|
public function listFiles ( $ path = '/./' ) { $ handle = opendir ( 'ssh2.sftp://' . ( string ) $ this -> ftpConnection . $ path ) ; $ files = [ ] ; while ( ( $ file = readdir ( $ handle ) ) !== false ) { if ( $ file === '.' || $ file === '..' ) continue ; $ files [ ] = $ file ; } closedir ( $ handle ) ; return $ files ; }
|
Lists files in the given path
|
47,259
|
public function downloadFile ( $ pathFrom , $ pathTo ) { if ( ! $ remoteStream = @ fopen ( "ssh2.sftp://{$this->ftpConnection}/{$pathFrom}" , 'r' ) ) { throw new SftpRemoteFileException ( "Unable to open remote: '{$pathFrom}'." ) ; } if ( ! is_dir ( dirname ( $ pathTo ) ) ) { $ this -> files -> makeDirectory ( dirname ( $ pathTo ) , static :: DIRECTORY_CREATE_MODE , true , true ) ; } if ( ! $ localStream = @ fopen ( $ pathTo , 'w' ) ) { throw new SftpLocalFileException ( "Unable to open local file: '{$pathTo}'." ) ; } if ( $ this -> chunking ) { $ bytesRead = 0 ; while ( ! feof ( $ remoteStream ) ) { $ buffer = fread ( $ remoteStream , $ this -> chunkSize ) ; $ bytesRead += strlen ( $ buffer ) ; if ( fwrite ( $ localStream , $ buffer ) === false ) { throw new SftpLocalFileException ( "Unable to write to local file: '{$pathTo}'." ) ; } } } else { $ buffer = stream_get_contents ( $ remoteStream ) ; $ bytesRead = strlen ( $ buffer ) ; if ( fwrite ( $ localStream , $ buffer ) === false ) { throw new SftpLocalFileException ( "Unable to write to local file: '{$pathTo}'." ) ; } } unset ( $ buffer ) ; fclose ( $ localStream ) ; fclose ( $ remoteStream ) ; event ( new SshFileDownloaded ( basename ( $ pathFrom ) , $ pathTo , $ bytesRead ) ) ; return $ bytesRead ; }
|
Downloads files via SFTP
|
47,260
|
public function uploadFile ( $ pathFrom , $ pathTo ) { if ( ! $ localStream = @ fopen ( $ pathFrom , 'r' ) ) { throw new SftpLocalFileException ( "Unable to open local file: '{$pathFrom}'." ) ; } if ( ! $ remoteStream = @ fopen ( "ssh2.sftp://{$this->ftpConnection}/{$pathTo}" , 'w' ) ) { throw new SftpRemoteFileException ( "Unable to open remote: '{$pathTo}'." ) ; } $ buffer = stream_get_contents ( $ localStream ) ; $ bytesWritten = strlen ( $ buffer ) ; if ( fwrite ( $ remoteStream , $ buffer ) === false ) { throw new SftpLocalFileException ( "Unable to write to remote file: '{$pathTo}'." ) ; } fclose ( $ localStream ) ; fclose ( $ remoteStream ) ; event ( new SshFileUploaded ( basename ( $ pathFrom ) , $ pathTo , $ bytesWritten ) ) ; return $ bytesWritten ; }
|
Uploads files over SFTP
|
47,261
|
protected function prepareGuzzleOptions ( ServiceRequestInterface $ request , $ httpMethod = null ) { if ( ! $ httpMethod ) { $ httpMethod = $ this -> determineHttpMethod ( $ request ) ; } $ options = [ 'http_errors' => false , ] ; $ credentials = $ request -> getCredentials ( ) ; if ( $ this -> basicAuth && ! empty ( $ credentials [ 'name' ] ) && ! empty ( $ credentials [ 'password' ] ) ) { $ options [ 'auth' ] = [ $ credentials [ 'name' ] , $ credentials [ 'password' ] ] ; } switch ( $ httpMethod ) { case static :: METHOD_PATCH : case static :: METHOD_POST : case static :: METHOD_PUT : if ( $ this -> multipart ) { $ options [ 'multipart' ] = $ this -> prepareMultipartData ( $ request -> getBody ( ) ) ; } elseif ( $ this -> sendJson ) { $ options [ 'json' ] = $ request -> getBody ( ) ; } else { $ options [ 'form_params' ] = $ request -> getBody ( ) ; } $ parameters = $ request -> getParameters ( ) ; if ( ! empty ( $ parameters ) ) { $ options [ 'query' ] = $ parameters ; } break ; case static :: METHOD_DELETE : case static :: METHOD_GET : $ options [ 'query' ] = $ request -> getBody ( ) ? : [ ] ; break ; } $ headers = $ request -> getHeaders ( ) ; if ( count ( $ headers ) ) { $ options [ 'headers' ] = $ headers ; } return $ options ; }
|
Prepares and returns guzzle options array for next call
|
47,262
|
protected function isGuzzleException ( Exception $ e ) { return ( is_a ( $ e , GuzzleException \ BadResponseException :: class ) || is_a ( $ e , GuzzleException \ ClientException :: class ) || is_a ( $ e , GuzzleException \ ConnectException :: class ) || is_a ( $ e , GuzzleException \ RequestException :: class ) || is_a ( $ e , GuzzleException \ SeekException :: class ) || is_a ( $ e , GuzzleException \ ServerException :: class ) || is_a ( $ e , GuzzleException \ TooManyRedirectsException :: class ) || is_a ( $ e , GuzzleException \ TransferException :: class ) ) ; }
|
Returns whether the given is a standard Guzzle exception
|
47,263
|
protected function prepareMultipartData ( $ params ) { $ multipart = [ ] ; if ( $ params instanceof Arrayable ) { $ params = $ params -> toArray ( ) ; } foreach ( $ params as $ key => $ value ) { if ( ! is_array ( $ value ) ) { $ multipart [ ] = [ 'name' => $ key , 'contents' => $ value , ] ; continue ; } foreach ( array_dot ( $ value ) as $ dotKey => $ leafValue ) { $ partKey = $ key . implode ( array_map ( function ( $ partKey ) { return "[{$partKey}]" ; } , explode ( '.' , $ dotKey ) ) ) ; $ multipart [ ] = [ 'name' => $ partKey , 'contents' => $ leafValue , ] ; } } return $ multipart ; }
|
Converts a given array with parameters to the multipart array format
|
47,264
|
protected function makeFilePathFromRequest ( ServiceRequestInterface $ request ) { $ location = $ request -> getLocation ( ) ; $ method = $ request -> getMethod ( ) ; if ( ! empty ( $ location ) && ! empty ( $ method ) ) { return rtrim ( $ location ( ) , DIRECTORY_SEPARATOR ) . DIRECTORY_SEPARATOR . $ method ( ) ; } if ( ! empty ( $ location ) ) return $ location ; if ( ! empty ( $ method ) ) return $ method ; throw new CouldNotConnectException ( 'No path given for FileService. Set a location and/or method to build a valid path.' ) ; }
|
Builds an returns local file path from current request
|
47,265
|
protected function cleanupLocalFiles ( array $ newFiles ) { $ localPath = rtrim ( $ this -> request -> getLocalPath ( ) , DIRECTORY_SEPARATOR ) ; $ deleteFiles = array_diff ( $ this -> files -> files ( $ localPath ) , $ newFiles ) ; foreach ( $ deleteFiles as $ file ) { if ( ! $ this -> files -> delete ( $ file ) ) { throw new \ RuntimeException ( "Failed to delete local file for cleanup: {$file}" ) ; } event ( new SshLocalFileDeleted ( $ file , $ localPath ) ) ; } }
|
Removes locally files that are not newly downloaded
|
47,266
|
protected function initializeSsh ( ) { try { $ this -> ssh = $ this -> getSsh2SftpConnectionFactory ( ) -> make ( Ssh2SftpConnectionInterface :: class , $ this -> request -> getLocation ( ) , $ this -> request -> getCredentials ( ) [ 'name' ] , $ this -> request -> getCredentials ( ) [ 'password' ] , $ this -> request -> getPort ( ) ? : 22 , $ this -> request -> getFingerprint ( ) ) ; } catch ( Ssh2ConnectionException $ e ) { throw new CouldNotConnectException ( $ e -> getMessage ( ) , 0 , $ e ) ; } }
|
Initializes the SSH connection
|
47,267
|
public function listContents ( $ directory = '' , $ recursive = false ) { try { return $ this -> addDirNames ( $ this -> doListContents ( $ directory ) ) ; } catch ( \ Exception $ e ) { return [ ] ; } }
|
List contents of a directory . Cloudinary does not support non recursive directory scan because they treat filename prefixes as folders .
|
47,268
|
public function pathToId ( $ path ) { $ extension = pathinfo ( $ path , PATHINFO_EXTENSION ) ; return $ extension ? substr ( $ path , 0 , - ( strlen ( $ extension ) + 1 ) ) : $ path ; }
|
Converts path to public Id
|
47,269
|
public static function getNumberBaseFromString ( $ value ) { if ( substr ( $ value , 0 , 1 ) == 'b' ) return self :: BINARY ; if ( substr ( $ value , 0 , 1 ) == 'o' ) return self :: OCTAL ; if ( substr ( $ value , 0 , 2 ) == '0x' ) return self :: HEXADECIMAL ; if ( is_numeric ( $ value ) ) return self :: DECIMAL ; throw new \ Exception ( "not a number " . $ value ) ; }
|
Recognize current number base of string
|
47,270
|
protected function lookup ( $ system ) { foreach ( static :: $ conversionTable as $ row ) { if ( isset ( $ row [ $ this -> system ] , $ row [ $ system ] ) && $ row [ $ this -> system ] === $ this -> value ) { return $ row [ $ system ] ; } } throw new \ Exception ( sprintf ( 'Failed to look up value "%s" from system "%s" to system "%s"' , $ this -> value , $ this -> system , $ system ) ) ; }
|
Finds this size in another system .
|
47,271
|
public function to ( $ system ) { $ this -> value = $ this -> lookup ( $ system ) ; $ this -> system = $ system ; return $ this ; }
|
Converts this size to another system .
|
47,272
|
public function setCurrencyData ( CurrencyData $ currencyData ) { self :: $ conversionMap = $ currencyData -> getCurrencies ( ) ; self :: $ native = $ currencyData -> getNative ( ) ; return $ this ; }
|
Sets the currency conversion data
|
47,273
|
public function sub ( $ quantity , $ unit = null ) { if ( $ unit === null ) { $ unit = $ this -> unit ; } $ quantity = new static ( $ quantity , $ unit , $ this -> currencyData ) ; $ quantity -> to ( $ this -> unit ) ; $ this -> value -= $ quantity -> getValue ( ) ; return $ this ; }
|
Subtracts a quantity from this quantity
|
47,274
|
public function to ( $ unit ) { $ this -> value = $ this -> convert ( $ this -> unit , $ unit , $ this -> value ) ; $ this -> unit = $ unit ; return $ this ; }
|
Converts this quantity to another unit .
|
47,275
|
protected function getConversionRate ( $ unit ) { if ( ! isset ( static :: $ conversionMap [ $ unit ] ) ) { throw new \ Exception ( sprintf ( 'Conversion rate between "%s" and "%s" is not defined.' , static :: $ native , $ unit ) ) ; } return static :: $ conversionMap [ $ unit ] ; }
|
Returns the conversion rate for a unit .
|
47,276
|
public function format ( $ decimals = 2 , $ decPoint = '.' , $ thousandSep = ',' ) { return number_format ( $ this -> value , $ decimals , $ decPoint , $ thousandSep ) ; }
|
Formats this quantity .
|
47,277
|
public function out ( $ decimals = 2 , $ decPoint = '.' , $ thousandSep = ',' ) { return $ this -> format ( $ decimals , $ decPoint , $ thousandSep ) . ' ' . $ this -> unit ; }
|
Converts this quantity into a string
|
47,278
|
public function processContent ( string $ content ) : string { $ matches = Strings :: matchAll ( $ content , '#\[' . RegexPattern :: PR_OR_ISSUE . '\]#m' ) ; foreach ( $ matches as $ match ) { $ link = sprintf ( '[#%d]: %s/pull/%d' , $ match [ 'id' ] , $ this -> repositoryUrl , $ match [ 'id' ] ) ; $ this -> linkAppender -> add ( $ match [ 'id' ] , $ link ) ; } return $ content ; }
|
Github can redirects PRs to issues so no need to trouble with their separatoin
|
47,279
|
public function normalize ( $ input , $ options ) { global $ jsonld_default_load_document ; self :: setdefaults ( $ options , array ( 'base' => is_string ( $ input ) ? $ input : '' , 'documentLoader' => $ jsonld_default_load_document ) ) ; if ( isset ( $ options [ 'inputFormat' ] ) ) { if ( $ options [ 'inputFormat' ] != 'application/nquads' ) { throw new JsonLdException ( 'Unknown normalization input format.' , 'jsonld.NormalizeError' ) ; } $ dataset = $ this -> parseNQuads ( $ input ) ; } else { try { $ opts = $ options ; if ( isset ( $ opts [ 'format' ] ) ) { unset ( $ opts [ 'format' ] ) ; } $ opts [ 'produceGeneralizedRdf' ] = false ; $ dataset = $ this -> toRDF ( $ input , $ opts ) ; } catch ( Exception $ e ) { throw new JsonLdException ( 'Could not convert input to RDF dataset before normalization.' , 'jsonld.NormalizeError' , null , null , $ e ) ; } } return $ this -> _normalize ( $ dataset , $ options ) ; }
|
Performs JSON - LD normalization .
|
47,280
|
public function toRDF ( $ input , $ options ) { global $ jsonld_default_load_document ; self :: setdefaults ( $ options , array ( 'base' => is_string ( $ input ) ? $ input : '' , 'produceGeneralizedRdf' => false , 'documentLoader' => $ jsonld_default_load_document ) ) ; try { $ expanded = $ this -> expand ( $ input , $ options ) ; } catch ( JsonLdException $ e ) { throw new JsonLdException ( 'Could not expand input before serialization to RDF.' , 'jsonld.RdfError' , null , null , $ e ) ; } $ namer = new UniqueNamer ( '_:b' ) ; $ node_map = ( object ) array ( '@default' => new stdClass ( ) ) ; $ this -> _createNodeMap ( $ expanded , $ node_map , '@default' , $ namer ) ; $ dataset = new stdClass ( ) ; $ graph_names = array_keys ( ( array ) $ node_map ) ; sort ( $ graph_names ) ; foreach ( $ graph_names as $ graph_name ) { $ graph = $ node_map -> { $ graph_name } ; if ( $ graph_name === '@default' || self :: _isAbsoluteIri ( $ graph_name ) ) { $ dataset -> { $ graph_name } = $ this -> _graphToRDF ( $ graph , $ namer , $ options ) ; } } $ rval = $ dataset ; if ( isset ( $ options [ 'format' ] ) && $ options [ 'format' ] ) { if ( $ options [ 'format' ] === 'application/nquads' ) { $ rval = self :: toNQuads ( $ dataset ) ; } else { throw new JsonLdException ( 'Unknown output format.' , 'jsonld.UnknownFormat' , null , array ( 'format' => $ options [ 'format' ] ) ) ; } } return $ rval ; }
|
Outputs the RDF dataset found in the given JSON - LD object .
|
47,281
|
public function processContext ( $ active_ctx , $ local_ctx , $ options ) { global $ jsonld_default_load_document ; self :: setdefaults ( $ options , array ( 'base' => '' , 'documentLoader' => $ jsonld_default_load_document ) ) ; if ( $ local_ctx === null ) { return $ this -> _getInitialContext ( $ options ) ; } $ local_ctx = self :: copy ( $ local_ctx ) ; if ( is_string ( $ local_ctx ) or ( is_object ( $ local_ctx ) && ! property_exists ( $ local_ctx , '@context' ) ) ) { $ local_ctx = ( object ) array ( '@context' => $ local_ctx ) ; } try { $ this -> _retrieveContextUrls ( $ local_ctx , new stdClass ( ) , $ options [ 'documentLoader' ] , $ options [ 'base' ] ) ; } catch ( Exception $ e ) { throw new JsonLdException ( 'Could not process JSON-LD context.' , 'jsonld.ContextError' , null , null , $ e ) ; } return $ this -> _processContext ( $ active_ctx , $ local_ctx , $ options ) ; }
|
Processes a local context resolving any URLs as necessary and returns a new active context in its callback .
|
47,282
|
public static function hasProperty ( $ subject , $ property ) { $ rval = false ; if ( property_exists ( $ subject , $ property ) ) { $ value = $ subject -> { $ property } ; $ rval = ( ! is_array ( $ value ) || count ( $ value ) > 0 ) ; } return $ rval ; }
|
Returns true if the given subject has the given property .
|
47,283
|
public static function hasValue ( $ subject , $ property , $ value ) { $ rval = false ; if ( self :: hasProperty ( $ subject , $ property ) ) { $ val = $ subject -> { $ property } ; $ is_list = self :: _isList ( $ val ) ; if ( is_array ( $ val ) || $ is_list ) { if ( $ is_list ) { $ val = $ val -> { '@list' } ; } foreach ( $ val as $ v ) { if ( self :: compareValues ( $ value , $ v ) ) { $ rval = true ; break ; } } } else if ( ! is_array ( $ value ) ) { $ rval = self :: compareValues ( $ value , $ val ) ; } } return $ rval ; }
|
Determines if the given value is a property of the given subject .
|
47,284
|
public static function addValue ( $ subject , $ property , $ value , $ options = array ( ) ) { self :: setdefaults ( $ options , array ( 'allowDuplicate' => true , 'propertyIsArray' => false ) ) ; if ( is_array ( $ value ) ) { if ( count ( $ value ) === 0 && $ options [ 'propertyIsArray' ] && ! property_exists ( $ subject , $ property ) ) { $ subject -> { $ property } = array ( ) ; } foreach ( $ value as $ v ) { self :: addValue ( $ subject , $ property , $ v , $ options ) ; } } else if ( property_exists ( $ subject , $ property ) ) { $ has_value = ( ! $ options [ 'allowDuplicate' ] && self :: hasValue ( $ subject , $ property , $ value ) ) ; if ( ! is_array ( $ subject -> { $ property } ) && ( ! $ has_value || $ options [ 'propertyIsArray' ] ) ) { $ subject -> { $ property } = array ( $ subject -> { $ property } ) ; } if ( ! $ has_value ) { $ subject -> { $ property } [ ] = $ value ; } } else { $ subject -> { $ property } = ( $ options [ 'propertyIsArray' ] ? array ( $ value ) : $ value ) ; } }
|
Adds a value to a subject . If the value is an array all values in the array will be added .
|
47,285
|
public static function getValues ( $ subject , $ property ) { $ rval = ( property_exists ( $ subject , $ property ) ? $ subject -> { $ property } : array ( ) ) ; return self :: arrayify ( $ rval ) ; }
|
Gets all of the values for a subject s property as an array .
|
47,286
|
public static function removeValue ( $ subject , $ property , $ value , $ options = array ( ) ) { self :: setdefaults ( $ options , array ( 'propertyIsArray' => false ) ) ; $ filter = function ( $ e ) use ( $ value ) { return ! self :: compareValues ( $ e , $ value ) ; } ; $ values = self :: getValues ( $ subject , $ property ) ; $ values = array_values ( array_filter ( $ values , $ filter ) ) ; if ( count ( $ values ) === 0 ) { self :: removeProperty ( $ subject , $ property ) ; } else if ( count ( $ values ) === 1 && ! $ options [ 'propertyIsArray' ] ) { $ subject -> { $ property } = $ values [ 0 ] ; } else { $ subject -> { $ property } = $ values ; } }
|
Removes a value from a subject .
|
47,287
|
public static function getContextValue ( $ ctx , $ key , $ type ) { $ rval = null ; if ( $ key === null ) { return $ rval ; } if ( $ type === '@language' && property_exists ( $ ctx , $ type ) ) { $ rval = $ ctx -> { $ type } ; } if ( property_exists ( $ ctx -> mappings , $ key ) ) { $ entry = $ ctx -> mappings -> { $ key } ; if ( $ entry === null ) { return null ; } if ( $ type === null ) { $ rval = $ entry ; } else if ( property_exists ( $ entry , $ type ) ) { $ rval = $ entry -> { $ type } ; } } return $ rval ; }
|
Gets the value for the given active context key and type null if none is set .
|
47,288
|
public static function toNQuads ( $ dataset ) { $ quads = array ( ) ; foreach ( $ dataset as $ graph_name => $ triples ) { foreach ( $ triples as $ triple ) { if ( $ graph_name === '@default' ) { $ graph_name = null ; } $ quads [ ] = self :: toNQuad ( $ triple , $ graph_name ) ; } } sort ( $ quads ) ; return implode ( $ quads ) ; }
|
Converts an RDF dataset to N - Quads .
|
47,289
|
public function registerRDFParser ( $ content_type , $ parser ) { if ( $ this -> rdfParsers === null ) { $ this -> rdfParsers = new stdClass ( ) ; } $ this -> rdfParsers -> { $ content_type } = $ parser ; }
|
Registers a processor - specific RDF dataset parser by content - type . Global parsers will no longer be used by this processor .
|
47,290
|
public function unregisterRDFParser ( $ content_type ) { if ( $ this -> rdfParsers !== null && property_exists ( $ this -> rdfParsers , $ content_type ) ) { unset ( $ this -> rdfParsers -> { $ content_type } ) ; if ( count ( get_object_vars ( $ content_type ) ) === 0 ) { $ this -> rdfParsers = null ; } } }
|
Unregisters a process - specific RDF dataset parser by content - type . If there are no remaining processor - specific parsers then the global parsers will be re - enabled .
|
47,291
|
public static function setdefault ( & $ arr , $ key , $ value ) { isset ( $ arr [ $ key ] ) or $ arr [ $ key ] = $ value ; }
|
Sets the value of a key for the given array if that property has not already been set .
|
47,292
|
public static function setdefaults ( & $ arr , $ defaults ) { foreach ( $ defaults as $ key => $ value ) { self :: setdefault ( $ arr , $ key , $ value ) ; } }
|
Sets default values for keys in the given array .
|
47,293
|
protected function _expandLanguageMap ( $ language_map ) { $ rval = array ( ) ; $ keys = array_keys ( ( array ) $ language_map ) ; sort ( $ keys ) ; foreach ( $ keys as $ key ) { $ values = $ language_map -> { $ key } ; $ values = self :: arrayify ( $ values ) ; foreach ( $ values as $ item ) { if ( $ item === null ) { continue ; } if ( ! is_string ( $ item ) ) { throw new JsonLdException ( 'Invalid JSON-LD syntax; language map values must be strings.' , 'jsonld.SyntaxError' , 'invalid language map value' , array ( 'languageMap' , $ language_map ) ) ; } $ rval [ ] = ( object ) array ( '@value' => $ item , '@language' => strtolower ( $ key ) ) ; } } return $ rval ; }
|
Expands a language map .
|
47,294
|
public function _labelBlankNodes ( $ namer , $ element ) { if ( is_array ( $ element ) ) { $ length = count ( $ element ) ; for ( $ i = 0 ; $ i < $ length ; ++ $ i ) { $ element [ $ i ] = $ this -> _labelBlankNodes ( $ namer , $ element [ $ i ] ) ; } } else if ( self :: _isList ( $ element ) ) { $ element -> { '@list' } = $ this -> _labelBlankNodes ( $ namer , $ element -> { '@list' } ) ; } else if ( is_object ( $ element ) ) { if ( self :: _isBlankNode ( $ element ) ) { $ name = null ; if ( property_exists ( $ element , '@id' ) ) { $ name = $ element -> { '@id' } ; } $ element -> { '@id' } = $ namer -> getName ( $ name ) ; } $ keys = array_keys ( ( array ) $ element ) ; sort ( $ keys ) ; foreach ( $ keys as $ key ) { if ( $ key !== '@id' ) { $ element -> { $ key } = $ this -> _labelBlankNodes ( $ namer , $ element -> { $ key } ) ; } } } return $ element ; }
|
Labels the blank nodes in the given value using the given UniqueNamer .
|
47,295
|
protected function _expandValue ( $ active_ctx , $ active_property , $ value ) { if ( $ value === null ) { return null ; } $ expanded_property = $ this -> _expandIri ( $ active_ctx , $ active_property , array ( 'vocab' => true ) ) ; if ( $ expanded_property === '@id' ) { return $ this -> _expandIri ( $ active_ctx , $ value , array ( 'base' => true ) ) ; } else if ( $ expanded_property === '@type' ) { return $ this -> _expandIri ( $ active_ctx , $ value , array ( 'vocab' => true , 'base' => true ) ) ; } $ type = self :: getContextValue ( $ active_ctx , $ active_property , '@type' ) ; if ( $ type === '@id' || ( $ expanded_property === '@graph' && is_string ( $ value ) ) ) { return ( object ) array ( '@id' => $ this -> _expandIri ( $ active_ctx , $ value , array ( 'base' => true ) ) ) ; } if ( $ type === '@vocab' ) { return ( object ) array ( '@id' => $ this -> _expandIri ( $ active_ctx , $ value , array ( 'vocab' => true , 'base' => true ) ) ) ; } if ( self :: _isKeyword ( $ expanded_property ) ) { return $ value ; } $ rval = new stdClass ( ) ; if ( $ type !== null ) { $ rval -> { '@type' } = $ type ; } else if ( is_string ( $ value ) ) { $ language = self :: getContextValue ( $ active_ctx , $ active_property , '@language' ) ; if ( $ language !== null ) { $ rval -> { '@language' } = $ language ; } } $ rval -> { '@value' } = $ value ; return $ rval ; }
|
Expands the given value by using the coercion and keyword rules in the given context .
|
47,296
|
protected function _graphToRDF ( $ graph , $ namer , $ options ) { $ rval = array ( ) ; $ ids = array_keys ( ( array ) $ graph ) ; sort ( $ ids ) ; foreach ( $ ids as $ id ) { $ node = $ graph -> { $ id } ; if ( $ id === '"' ) { $ id = '' ; } $ properties = array_keys ( ( array ) $ node ) ; sort ( $ properties ) ; foreach ( $ properties as $ property ) { $ items = $ node -> { $ property } ; if ( $ property === '@type' ) { $ property = self :: RDF_TYPE ; } else if ( self :: _isKeyword ( $ property ) ) { continue ; } foreach ( $ items as $ item ) { if ( ! ( self :: _isAbsoluteIri ( $ id ) && self :: _isAbsoluteIri ( $ property ) ) ) { continue ; } $ subject = new stdClass ( ) ; $ subject -> type = ( strpos ( $ id , '_:' ) === 0 ) ? 'blank node' : 'IRI' ; $ subject -> value = $ id ; $ predicate = new stdClass ( ) ; $ predicate -> type = ( strpos ( $ property , '_:' ) === 0 ? 'blank node' : 'IRI' ) ; $ predicate -> value = $ property ; if ( $ predicate -> type === 'blank node' && ! $ options [ 'produceGeneralizedRdf' ] ) { continue ; } if ( self :: _isList ( $ item ) ) { $ this -> _listToRDF ( $ item -> { '@list' } , $ namer , $ subject , $ predicate , $ rval ) ; } else { $ object = $ this -> _objectToRDF ( $ item ) ; if ( $ object ) { $ rval [ ] = ( object ) array ( 'subject' => $ subject , 'predicate' => $ predicate , 'object' => $ object ) ; } } } } } return $ rval ; }
|
Creates an array of RDF triples for the given graph .
|
47,297
|
protected function _objectToRDF ( $ item ) { $ object = new stdClass ( ) ; if ( self :: _isValue ( $ item ) ) { $ object -> type = 'literal' ; $ value = $ item -> { '@value' } ; $ datatype = property_exists ( $ item , '@type' ) ? $ item -> { '@type' } : null ; if ( is_bool ( $ value ) ) { $ object -> value = ( $ value ? 'true' : 'false' ) ; $ object -> datatype = $ datatype ? $ datatype : self :: XSD_BOOLEAN ; } else if ( is_double ( $ value ) || $ datatype == self :: XSD_DOUBLE ) { $ object -> value = preg_replace ( '/(\d)0*E\+?/' , '$1E' , sprintf ( '%1.15E' , $ value ) ) ; $ object -> datatype = $ datatype ? $ datatype : self :: XSD_DOUBLE ; } else if ( is_integer ( $ value ) ) { $ object -> value = strval ( $ value ) ; $ object -> datatype = $ datatype ? $ datatype : self :: XSD_INTEGER ; } else if ( property_exists ( $ item , '@language' ) ) { $ object -> value = $ value ; $ object -> datatype = $ datatype ? $ datatype : self :: RDF_LANGSTRING ; $ object -> language = $ item -> { '@language' } ; } else { $ object -> value = $ value ; $ object -> datatype = $ datatype ? $ datatype : self :: XSD_STRING ; } } else { $ id = is_object ( $ item ) ? $ item -> { '@id' } : $ item ; $ object -> type = ( strpos ( $ id , '_:' ) === 0 ) ? 'blank node' : 'IRI' ; $ object -> value = $ id ; } if ( $ object -> type === 'IRI' && ! self :: _isAbsoluteIri ( $ object -> value ) ) { return null ; } return $ object ; }
|
Converts a JSON - LD value object to an RDF literal or a JSON - LD string or node object to an RDF resource .
|
47,298
|
protected function _RDFToObject ( $ o , $ use_native_types ) { if ( $ o -> type === 'IRI' || $ o -> type === 'blank node' ) { return ( object ) array ( '@id' => $ o -> value ) ; } $ rval = ( object ) array ( '@value' => $ o -> value ) ; if ( property_exists ( $ o , 'language' ) ) { $ rval -> { '@language' } = $ o -> language ; } else { $ type = $ o -> datatype ; if ( $ use_native_types ) { if ( $ type === self :: XSD_BOOLEAN ) { if ( $ rval -> { '@value' } === 'true' ) { $ rval -> { '@value' } = true ; } else if ( $ rval -> { '@value' } === 'false' ) { $ rval -> { '@value' } = false ; } } else if ( is_numeric ( $ rval -> { '@value' } ) ) { if ( $ type === self :: XSD_INTEGER ) { $ i = intval ( $ rval -> { '@value' } ) ; if ( strval ( $ i ) === $ rval -> { '@value' } ) { $ rval -> { '@value' } = $ i ; } } else if ( $ type === self :: XSD_DOUBLE ) { $ rval -> { '@value' } = doubleval ( $ rval -> { '@value' } ) ; } } if ( ! in_array ( $ type , array ( self :: XSD_BOOLEAN , self :: XSD_INTEGER , self :: XSD_DOUBLE , self :: XSD_STRING ) ) ) { $ rval -> { '@type' } = $ type ; } } else if ( $ type !== self :: XSD_STRING ) { $ rval -> { '@type' } = $ type ; } } return $ rval ; }
|
Converts an RDF triple object to a JSON - LD object .
|
47,299
|
function _createImplicitFrame ( $ flags ) { $ frame = new stdClass ( ) ; foreach ( $ flags as $ key => $ value ) { $ frame -> { '@' . $ key } = array ( $ flags [ $ key ] ) ; } return array ( $ frame ) ; }
|
Creates an implicit frame when recursing through subject matches . If a frame doesn t have an explicit frame for a particular property then a wildcard child frame will be created that uses the same flags that the parent frame used .
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.