idx
int64 0
60.3k
| question
stringlengths 64
4.24k
| target
stringlengths 5
618
|
|---|---|---|
49,000
|
public function loadCssFilesFromLinks ( $ message ) { $ dom = new \ DOMDocument ( ) ; $ internalErrors = libxml_use_internal_errors ( true ) ; $ dom -> loadHTML ( $ message ) ; libxml_use_internal_errors ( $ internalErrors ) ; $ link_tags = $ dom -> getElementsByTagName ( 'link' ) ; if ( $ link_tags -> length > 0 ) { do { if ( $ link_tags -> item ( 0 ) -> getAttribute ( 'rel' ) == "stylesheet" ) { $ options [ 'css-files' ] [ ] = $ link_tags -> item ( 0 ) -> getAttribute ( 'href' ) ; $ link_tags -> item ( 0 ) -> parentNode -> removeChild ( $ link_tags -> item ( 0 ) ) ; } } while ( $ link_tags -> length > 0 ) ; if ( isset ( $ options ) ) { $ this -> loadOptions ( $ options ) ; } return $ dom -> saveHTML ( ) ; } return $ message ; }
|
Find CSS stylesheet links and load them
|
49,001
|
public function read ( $ id ) { $ data = parent :: read ( $ id ) ; return empty ( $ data ) ? '' : $ this -> decrypt ( $ data , $ this -> key ) ; }
|
Read from session and decrypt
|
49,002
|
public function write ( $ id , $ data ) { return parent :: write ( $ id , $ this -> encrypt ( $ data , $ this -> key ) ) ; }
|
Encrypt the data and write into the session
|
49,003
|
protected function decrypt ( $ data , $ key ) { $ hmac = mb_substr ( $ data , 0 , 32 , '8bit' ) ; $ iv = mb_substr ( $ data , 32 , 16 , '8bit' ) ; $ ciphertext = mb_substr ( $ data , 48 , null , '8bit' ) ; $ hmacNew = hash_hmac ( 'SHA256' , $ iv . $ ciphertext , mb_substr ( $ key , 32 , null , '8bit' ) , true ) ; if ( ! hash_equals ( $ hmac , $ hmacNew ) ) { throw new Exception \ AuthenticationFailedException ( 'Authentication failed' ) ; } return openssl_decrypt ( $ ciphertext , 'AES-256-CBC' , mb_substr ( $ key , 0 , 32 , '8bit' ) , OPENSSL_RAW_DATA , $ iv ) ; }
|
Authenticate and decrypt
|
49,004
|
public function parse ( $ json , Builder $ querybuilder ) { $ query = $ this -> decodeJSON ( $ json ) ; if ( ! isset ( $ query -> rules ) || ! is_array ( $ query -> rules ) ) { return $ querybuilder ; } if ( count ( $ query -> rules ) < 1 ) { return $ querybuilder ; } return $ this -> loopThroughRules ( $ query -> rules , $ querybuilder , $ query -> condition ) ; }
|
QueryBuilderParser s parse function!
|
49,005
|
protected function createNestedQuery ( Builder $ querybuilder , stdClass $ rule , $ condition = null ) { if ( $ condition === null ) { $ condition = $ rule -> condition ; } $ condition = $ this -> validateCondition ( $ condition ) ; return $ querybuilder -> whereNested ( function ( $ query ) use ( & $ rule , & $ querybuilder , & $ condition ) { foreach ( $ rule -> rules as $ loopRule ) { $ function = 'makeQuery' ; if ( $ this -> isNested ( $ loopRule ) ) { $ function = 'createNestedQuery' ; } $ querybuilder = $ this -> { $ function } ( $ query , $ loopRule , $ rule -> condition ) ; } } , $ condition ) ; }
|
Create nested queries
|
49,006
|
protected function checkRuleCorrect ( stdClass $ rule ) { if ( ! isset ( $ rule -> operator , $ rule -> id , $ rule -> field , $ rule -> type ) ) { return false ; } if ( ! isset ( $ this -> operators [ $ rule -> operator ] ) ) { return false ; } return true ; }
|
Check if a given rule is correct .
|
49,007
|
protected function convertIncomingQBtoQuery ( Builder $ query , stdClass $ rule , $ value , $ queryCondition = 'AND' ) { $ sqlOperator = $ this -> operator_sql [ $ rule -> operator ] ; $ operator = $ sqlOperator [ 'operator' ] ; $ condition = strtolower ( $ queryCondition ) ; if ( $ this -> operatorRequiresArray ( $ operator ) ) { return $ this -> makeQueryWhenArray ( $ query , $ rule , $ sqlOperator , $ value , $ condition ) ; } elseif ( $ this -> operatorIsNull ( $ operator ) ) { return $ this -> makeQueryWhenNull ( $ query , $ rule , $ sqlOperator , $ condition ) ; } return $ query -> where ( $ rule -> field , $ sqlOperator [ 'operator' ] , $ value , $ condition ) ; }
|
Convert an incomming rule from jQuery QueryBuilder to the Eloquent Querybuilder
|
49,008
|
private function buildSubclauseQuery ( $ query , $ rule , $ value , $ condition ) { $ _sql_op = $ this -> operator_sql [ $ rule -> operator ] ; $ operator = $ _sql_op [ 'operator' ] ; $ require_array = $ this -> operatorRequiresArray ( $ operator ) ; $ subclause = $ this -> joinFields [ $ rule -> field ] ; $ subclause [ 'operator' ] = $ operator ; $ subclause [ 'value' ] = $ value ; $ subclause [ 'require_array' ] = $ require_array ; $ not = array_key_exists ( 'not_exists' , $ subclause ) && $ subclause [ 'not_exists' ] ; $ query = $ query -> whereExists ( function ( Builder $ query ) use ( $ subclause ) { $ q = $ query -> selectRaw ( 1 ) -> from ( $ subclause [ 'to_table' ] ) -> whereRaw ( $ subclause [ 'to_table' ] . '.' . $ subclause [ 'to_col' ] . ' = ' . $ subclause [ 'from_table' ] . '.' . $ subclause [ 'from_col' ] ) ; if ( array_key_exists ( 'to_clause' , $ subclause ) ) { $ q -> where ( $ subclause [ 'to_clause' ] ) ; } $ this -> buildSubclauseInnerQuery ( $ subclause , $ q ) ; } , $ condition , $ not ) ; return $ query ; }
|
Build a subquery clause if there are join fields that have been specified .
|
49,009
|
private function buildSubclauseInnerQuery ( $ subclause , Builder $ query ) { if ( $ subclause [ 'require_array' ] ) { return $ this -> buildRequireArrayQuery ( $ subclause , $ query ) ; } if ( $ subclause [ 'operator' ] == 'NULL' || $ subclause [ 'operator' ] == 'NOT NULL' ) { return $ this -> buildSubclauseWithNull ( $ subclause , $ query , ( $ subclause [ 'operator' ] == 'NOT NULL' ? true : false ) ) ; } return $ this -> buildRequireNotArrayQuery ( $ subclause , $ query ) ; }
|
The inner query for a subclause
|
49,010
|
private function buildRequireArrayQuery ( $ subclause , Builder $ query ) { if ( $ subclause [ 'operator' ] == 'IN' ) { $ query -> whereIn ( $ subclause [ 'to_value_column' ] , $ subclause [ 'value' ] ) ; } elseif ( $ subclause [ 'operator' ] == 'NOT IN' ) { $ query -> whereNotIn ( $ subclause [ 'to_value_column' ] , $ subclause [ 'value' ] ) ; } elseif ( $ subclause [ 'operator' ] == 'BETWEEN' ) { if ( count ( $ subclause [ 'value' ] ) !== 2 ) { throw new QBParseException ( $ subclause [ 'to_value_column' ] . ' should be an array with only two items.' ) ; } $ query -> whereBetween ( $ subclause [ 'to_value_column' ] , $ subclause [ 'value' ] ) ; } elseif ( $ subclause [ 'operator' ] == 'NOT BETWEEN' ) { if ( count ( $ subclause [ 'value' ] ) !== 2 ) { throw new QBParseException ( $ subclause [ 'to_value_column' ] . ' should be an array with only two items.' ) ; } $ query -> whereNotBetween ( $ subclause [ 'to_value_column' ] , $ subclause [ 'value' ] ) ; } return $ query ; }
|
The inner query for a subclause when an array is required
|
49,011
|
private function buildSubclauseWithNull ( $ subclause , Builder $ query , $ isNotNull = false ) { if ( $ isNotNull === true ) { return $ query -> whereNotNull ( $ subclause [ 'to_value_column' ] ) ; } return $ query -> whereNull ( $ subclause [ 'to_value_column' ] ) ; }
|
The inner query for a subclause when the operator is NULL .
|
49,012
|
protected function convertDatetimeToCarbon ( $ value ) { if ( is_array ( $ value ) ) { return array_map ( function ( $ v ) { return new Carbon ( $ v ) ; } , $ value ) ; } return new Carbon ( $ value ) ; }
|
Convert a Datetime field to Carbon items to be used for comparisons .
|
49,013
|
protected function appendOperatorIfRequired ( $ requireArray , $ value , $ sqlOperator ) { if ( ! $ requireArray ) { if ( isset ( $ sqlOperator [ 'append' ] ) ) { $ value = $ sqlOperator [ 'append' ] . $ value ; } if ( isset ( $ sqlOperator [ 'prepend' ] ) ) { $ value = $ value . $ sqlOperator [ 'prepend' ] ; } } return $ value ; }
|
Append or prepend a string to the query if required .
|
49,014
|
private function decodeJSON ( $ json ) { $ query = json_decode ( $ json ) ; if ( json_last_error ( ) ) { throw new QBParseException ( 'JSON parsing threw an error: ' . json_last_error_msg ( ) ) ; } if ( ! is_object ( $ query ) ) { throw new QBParseException ( 'The query is not valid JSON' ) ; } return $ query ; }
|
Decode the given JSON
|
49,015
|
protected function makeQueryWhenArray ( Builder $ query , stdClass $ rule , array $ sqlOperator , array $ value , $ condition ) { if ( $ sqlOperator [ 'operator' ] == 'IN' || $ sqlOperator [ 'operator' ] == 'NOT IN' ) { return $ this -> makeArrayQueryIn ( $ query , $ rule , $ sqlOperator [ 'operator' ] , $ value , $ condition ) ; } elseif ( $ sqlOperator [ 'operator' ] == 'BETWEEN' || $ sqlOperator [ 'operator' ] == 'NOT BETWEEN' ) { return $ this -> makeArrayQueryBetween ( $ query , $ rule , $ sqlOperator [ 'operator' ] , $ value , $ condition ) ; } throw new QBParseException ( 'makeQueryWhenArray could not return a value' ) ; }
|
makeQuery for arrays .
|
49,016
|
protected function makeQueryWhenNull ( Builder $ query , stdClass $ rule , array $ sqlOperator , $ condition ) { if ( $ sqlOperator [ 'operator' ] == 'NULL' ) { return $ query -> whereNull ( $ rule -> field , $ condition ) ; } elseif ( $ sqlOperator [ 'operator' ] == 'NOT NULL' ) { return $ query -> whereNotNull ( $ rule -> field , $ condition ) ; } throw new QBParseException ( 'makeQueryWhenNull was called on an SQL operator that is not null' ) ; }
|
Create a null query when required .
|
49,017
|
private function makeArrayQueryIn ( Builder $ query , stdClass $ rule , $ operator , array $ value , $ condition ) { if ( $ operator == 'NOT IN' ) { return $ query -> whereNotIn ( $ rule -> field , $ value , $ condition ) ; } return $ query -> whereIn ( $ rule -> field , $ value , $ condition ) ; }
|
makeArrayQueryIn when the query is an IN or NOT IN ...
|
49,018
|
private function makeArrayQueryBetween ( Builder $ query , stdClass $ rule , $ operator , array $ value , $ condition ) { if ( count ( $ value ) !== 2 ) { throw new QBParseException ( "{$rule->field} should be an array with only two items." ) ; } if ( $ operator == 'NOT BETWEEN' ) { return $ query -> whereNotBetween ( $ rule -> field , $ value , $ condition ) ; } return $ query -> whereBetween ( $ rule -> field , $ value , $ condition ) ; }
|
makeArrayQueryBetween when the query is a BETWEEN or NOT BETWEEN ...
|
49,019
|
private function processConnectionPool ( ) : void { $ readableConnections = $ this -> connectionPool -> getReadableConnections ( 5 ) ; foreach ( $ readableConnections as $ id => $ connection ) { if ( ! isset ( $ this -> connectionHandlers [ $ id ] ) ) { $ this -> connectionHandlers [ $ id ] = $ this -> connectionHandlerFactory -> createConnectionHandler ( $ this -> kernel , $ connection ) ; } try { $ statusCodes = $ this -> connectionHandlers [ $ id ] -> ready ( ) ; $ this -> considerStatusCodes ( $ statusCodes ) ; } catch ( UserlandDaemonException $ exception ) { $ this -> daemonOptions -> getOption ( DaemonOptions :: LOGGER ) -> error ( $ exception -> getMessage ( ) ) ; } if ( $ this -> connectionHandlers [ $ id ] -> isClosed ( ) ) { unset ( $ this -> connectionHandlers [ $ id ] ) ; } } }
|
Wait for connections in the pool to become readable . Create connection handlers for new connections and trigger the ready method when there is data for the handlers to receive . Clean up closed connections .
|
49,020
|
private function shutdown ( ) : void { $ this -> connectionPool -> shutdown ( ) ; foreach ( $ this -> connectionHandlers as $ connectionHandler ) { $ connectionHandler -> shutdown ( ) ; } while ( $ this -> connectionPool -> count ( ) > 0 ) { $ this -> processConnectionPool ( ) ; } $ this -> connectionPool -> close ( ) ; }
|
Gracefully shutdown the daemon .
|
49,021
|
public function flagShutdown ( string $ message = null ) : void { $ this -> isShutdown = true ; $ this -> shutdownMessage = ( null === $ message ? 'Daemon flagged for shutdown' : $ message ) ; }
|
Flags the daemon for shutting down .
|
49,022
|
private function setupDaemon ( DaemonOptionsInterface $ daemonOptions ) : void { $ this -> requestCount = 0 ; $ this -> requestLimit = ( int ) $ daemonOptions -> getOption ( DaemonOptions :: REQUEST_LIMIT ) ; $ this -> memoryLimit = ( int ) $ daemonOptions -> getOption ( DaemonOptions :: MEMORY_LIMIT ) ; $ this -> autoShutdown = ( bool ) $ daemonOptions -> getOption ( DaemonOptions :: AUTO_SHUTDOWN ) ; $ timeLimit = ( int ) $ daemonOptions -> getOption ( DaemonOptions :: TIME_LIMIT ) ; if ( DaemonOptions :: NO_LIMIT !== $ timeLimit ) { pcntl_alarm ( $ timeLimit ) ; } $ this -> installSignalHandlers ( ) ; }
|
Loads to configuration from the daemon options and installs signal handlers .
|
49,023
|
private function considerStatusCodes ( array $ statusCodes ) : void { $ this -> requestCount += count ( $ statusCodes ) ; if ( $ this -> autoShutdown ) { foreach ( $ statusCodes as $ statusCode ) { if ( $ statusCode >= 500 && $ statusCode < 600 ) { $ this -> flagShutdown ( 'Automatic shutdown following status code: ' . $ statusCode ) ; break ; } } } }
|
Increments the request count and looks for application errors .
|
49,024
|
private function checkDaemonLimits ( ) : void { if ( $ this -> isShutdown ) { throw new ShutdownException ( $ this -> shutdownMessage ) ; } pcntl_signal_dispatch ( ) ; if ( DaemonOptions :: NO_LIMIT !== $ this -> requestLimit ) { if ( $ this -> requestLimit <= $ this -> requestCount ) { throw new ShutdownException ( 'Daemon request limit reached (' . $ this -> requestCount . ' of ' . $ this -> requestLimit . ')' ) ; } } if ( DaemonOptions :: NO_LIMIT !== $ this -> memoryLimit ) { $ memoryUsage = memory_get_usage ( true ) ; if ( $ this -> memoryLimit <= $ memoryUsage ) { throw new ShutdownException ( 'Daemon memory limit reached (' . $ memoryUsage . ' of ' . $ this -> memoryLimit . ' bytes)' ) ; } } }
|
Checks the current PHP process against the limits specified in a daemon options object . This function will also throw an exception if the daemon has been flagged for shutdown .
|
49,025
|
private function getDaemonOptions ( InputInterface $ input , OutputInterface $ output ) : DaemonOptionsInterface { $ logger = new ConsoleLogger ( $ output ) ; $ requestLimit = $ input -> getOption ( 'request-limit' ) ? : DaemonOptions :: NO_LIMIT ; $ memoryLimit = $ input -> getOption ( 'memory-limit' ) ? : DaemonOptions :: NO_LIMIT ; $ timeLimit = $ input -> getOption ( 'time-limit' ) ? : DaemonOptions :: NO_LIMIT ; $ autoShutdown = $ input -> getOption ( 'auto-shutdown' ) ; return new DaemonOptions ( [ DaemonOptions :: LOGGER => $ logger , DaemonOptions :: REQUEST_LIMIT => $ requestLimit , DaemonOptions :: MEMORY_LIMIT => $ memoryLimit , DaemonOptions :: TIME_LIMIT => $ timeLimit , DaemonOptions :: AUTO_SHUTDOWN => $ autoShutdown , ] ) ; }
|
Creates a daemon configuration object from the Symfony command input and output objects .
|
49,026
|
private function selectConnections ( & $ readSockets , int $ timeout ) : void { $ read = [ ] ; foreach ( $ readSockets as $ id => $ socket ) { $ read [ ] = $ socket ; } $ writeSockets = $ exceptSockets = [ ] ; if ( false === @ stream_select ( $ read , $ writeSockets , $ exceptSockets , $ timeout ) ) { $ error = error_get_last ( ) ; if ( false === stripos ( $ error [ 'message' ] , 'interrupted system call' ) ) { throw new \ RuntimeException ( 'stream_select failed: ' . $ error [ 'message' ] ) ; } $ readSockets = [ ] ; } else { $ res = [ ] ; foreach ( $ read as $ socket ) { $ res [ array_search ( $ socket , $ readSockets ) ] = $ socket ; } $ readSockets = $ res ; } }
|
Uses the stream select function to eliminate all non - readable sockets from the read sockets parameter .
|
49,027
|
private function acceptConnection ( ) : void { $ clientSocket = @ stream_socket_accept ( $ this -> serverSocket ) ; if ( false !== $ clientSocket ) { stream_set_blocking ( $ clientSocket , false ) ; $ connection = new StreamSocketConnection ( $ clientSocket ) ; $ id = spl_object_hash ( $ connection ) ; $ this -> clientSockets [ $ id ] = $ clientSocket ; $ this -> connections [ $ id ] = $ connection ; } }
|
Accept incoming connections from the server stream socket .
|
49,028
|
private function readRecord ( ) : array { if ( $ this -> bufferLength < 8 ) { return [ ] ; } $ headerData = substr ( $ this -> buffer , 0 , 8 ) ; $ headerFormat = 'Cversion/Ctype/nrequestId/ncontentLength/CpaddingLength/x' ; $ record = unpack ( $ headerFormat , $ headerData ) ; if ( $ this -> bufferLength - 8 < $ record [ 'contentLength' ] + $ record [ 'paddingLength' ] ) { return [ ] ; } $ record [ 'contentData' ] = substr ( $ this -> buffer , 8 , $ record [ 'contentLength' ] ) ; $ recordSize = 8 + $ record [ 'contentLength' ] + $ record [ 'paddingLength' ] ; $ this -> buffer = substr ( $ this -> buffer , $ recordSize ) ; $ this -> bufferLength -= $ recordSize ; return $ record ; }
|
Read a record from the connection .
|
49,029
|
private function processRecord ( array $ record ) : ? int { $ requestId = $ record [ 'requestId' ] ; $ content = 0 === $ record [ 'contentLength' ] ? null : $ record [ 'contentData' ] ; if ( DaemonInterface :: FCGI_BEGIN_REQUEST === $ record [ 'type' ] ) { $ this -> processBeginRequestRecord ( $ requestId , $ content ) ; } elseif ( ! isset ( $ this -> requests [ $ requestId ] ) ) { throw new ProtocolException ( 'Invalid request id for record of type: ' . $ record [ 'type' ] ) ; } elseif ( DaemonInterface :: FCGI_PARAMS === $ record [ 'type' ] ) { while ( null !== $ content && strlen ( $ content ) > 0 ) { $ this -> readNameValuePair ( $ requestId , $ content ) ; } } elseif ( DaemonInterface :: FCGI_STDIN === $ record [ 'type' ] ) { if ( null !== $ content ) { fwrite ( $ this -> requests [ $ requestId ] [ 'stdin' ] , $ content ) ; } else { return $ this -> dispatchRequest ( $ requestId ) ; } } elseif ( DaemonInterface :: FCGI_ABORT_REQUEST === $ record [ 'type' ] ) { $ this -> endRequest ( $ requestId ) ; } else { throw new ProtocolException ( 'Unexpected packet of type: ' . $ record [ 'type' ] ) ; } return null ; }
|
Process a record .
|
49,030
|
private function processBeginRequestRecord ( int $ requestId , ? string $ contentData ) : void { if ( isset ( $ this -> requests [ $ requestId ] ) ) { throw new ProtocolException ( 'Unexpected FCGI_BEGIN_REQUEST record' ) ; } $ contentFormat = 'nrole/Cflags/x5' ; $ content = unpack ( $ contentFormat , $ contentData ) ; $ keepAlive = DaemonInterface :: FCGI_KEEP_CONNECTION & $ content [ 'flags' ] ; $ this -> requests [ $ requestId ] = [ 'keepAlive' => $ keepAlive , 'stdin' => fopen ( 'php://temp' , 'r+' ) , 'params' => [ ] , ] ; if ( $ this -> shutdown ) { $ this -> endRequest ( $ requestId , 0 , DaemonInterface :: FCGI_OVERLOADED ) ; return ; } if ( DaemonInterface :: FCGI_RESPONDER !== $ content [ 'role' ] ) { $ this -> endRequest ( $ requestId , 0 , DaemonInterface :: FCGI_UNKNOWN_ROLE ) ; return ; } }
|
Process a FCGI_BEGIN_REQUEST record .
|
49,031
|
private function readNameValuePair ( int $ requestId , ? string & $ buffer ) : void { $ nameLength = $ this -> readFieldLength ( $ buffer ) ; $ valueLength = $ this -> readFieldLength ( $ buffer ) ; $ contentFormat = ( 'a' . $ nameLength . 'name/' . 'a' . $ valueLength . 'value/' ) ; $ content = unpack ( $ contentFormat , $ buffer ) ; $ this -> requests [ $ requestId ] [ 'params' ] [ $ content [ 'name' ] ] = $ content [ 'value' ] ; $ buffer = substr ( $ buffer , $ nameLength + $ valueLength ) ; }
|
Read a FastCGI name - value pair from a buffer and add it to the request params .
|
49,032
|
private function readFieldLength ( string & $ buffer ) : int { $ block = unpack ( 'C4' , $ buffer ) ; $ length = $ block [ 1 ] ; $ skip = 1 ; if ( $ length & 0x80 ) { $ fullBlock = unpack ( 'N' , $ buffer ) ; $ length = $ fullBlock [ 1 ] & 0x7FFFFFFF ; $ skip = 4 ; } $ buffer = substr ( $ buffer , $ skip ) ; return $ length ; }
|
Read the field length of a FastCGI name - value pair from a buffer .
|
49,033
|
private function endRequest ( int $ requestId , int $ appStatus = 0 , int $ protocolStatus = DaemonInterface :: FCGI_REQUEST_COMPLETE ) : void { $ content = pack ( 'NCx3' , $ appStatus , $ protocolStatus ) ; $ this -> writeRecord ( $ requestId , DaemonInterface :: FCGI_END_REQUEST , $ content ) ; $ keepAlive = $ this -> requests [ $ requestId ] [ 'keepAlive' ] ; fclose ( $ this -> requests [ $ requestId ] [ 'stdin' ] ) ; unset ( $ this -> requests [ $ requestId ] ) ; if ( ! $ keepAlive ) { $ this -> close ( ) ; } }
|
End the request by writing an FCGI_END_REQUEST record and then removing the request from memory and closing the connection if necessary .
|
49,034
|
private function writeRecord ( int $ requestId , int $ type , string $ content = null ) : void { $ contentLength = null === $ content ? 0 : strlen ( $ content ) ; $ headerData = pack ( 'CCnnxx' , DaemonInterface :: FCGI_VERSION_1 , $ type , $ requestId , $ contentLength ) ; $ this -> connection -> write ( $ headerData ) ; if ( null !== $ content ) { $ this -> connection -> write ( $ content ) ; } }
|
Write a record to the connection .
|
49,035
|
private function writeResponse ( int $ requestId , string $ headerData , $ stream ) : void { $ data = $ headerData ; $ eof = false ; $ maxSize = 65535 ; fseek ( $ stream , 0 , SEEK_SET ) ; do { $ dataLength = strlen ( $ data ) ; if ( $ dataLength < $ maxSize && ! $ eof && ! ( $ eof = feof ( $ stream ) ) ) { $ readLength = $ maxSize - $ dataLength ; $ data .= fread ( $ stream , $ readLength ) ; $ dataLength = strlen ( $ data ) ; } $ writeSize = min ( $ dataLength , $ maxSize ) ; $ writeData = substr ( $ data , 0 , $ writeSize ) ; $ data = substr ( $ data , $ writeSize ) ; $ this -> writeRecord ( $ requestId , DaemonInterface :: FCGI_STDOUT , $ writeData ) ; } while ( $ writeSize === $ maxSize ) ; $ this -> writeRecord ( $ requestId , DaemonInterface :: FCGI_STDOUT ) ; }
|
Write a response to the connection as FCGI_STDOUT records .
|
49,036
|
private function dispatchRequest ( int $ requestId ) : int { $ request = new Request ( $ this -> requests [ $ requestId ] [ 'params' ] , $ this -> requests [ $ requestId ] [ 'stdin' ] ) ; try { $ response = $ this -> kernel -> handleRequest ( $ request ) ; } finally { $ request -> cleanUploadedFiles ( ) ; } if ( $ response instanceof ResponseInterface ) { $ this -> sendResponse ( $ requestId , $ response ) ; } elseif ( $ response instanceof HttpFoundationResponse ) { $ this -> sendHttpFoundationResponse ( $ requestId , $ response ) ; } else { throw new \ LogicException ( 'Kernel must return a PSR-7 or HttpFoundation response message' ) ; } $ this -> endRequest ( $ requestId ) ; return $ response -> getStatusCode ( ) ; }
|
Dispatches a request to the kernel .
|
49,037
|
private function sendHttpFoundationResponse ( int $ requestId , HttpFoundationResponse $ response ) : void { $ statusCode = $ response -> getStatusCode ( ) ; $ headerData = "Status: {$statusCode}\r\n" ; $ headerData .= $ response -> headers . "\r\n" ; $ stream = fopen ( 'php://memory' , 'r+' ) ; fwrite ( $ stream , $ response -> getContent ( ) ) ; $ this -> writeResponse ( $ requestId , $ headerData , $ stream ) ; }
|
Send a HttpFoundation response to the client .
|
49,038
|
private function getKernelObject ( $ kernel ) : KernelInterface { if ( $ kernel instanceof KernelInterface ) { return $ kernel ; } elseif ( is_callable ( $ kernel ) ) { return new CallbackKernel ( $ kernel ) ; } throw new \ InvalidArgumentException ( 'Kernel must be callable or an instance of KernelInterface' ) ; }
|
Converts the kernel parameter to an object implementing the KernelInterface if it is a callable .
|
49,039
|
public function createDaemon ( KernelInterface $ kernel , DaemonOptions $ options , int $ fd = DaemonInterface :: FCGI_LISTENSOCK_FILENO ) : DaemonInterface { $ socket = fopen ( 'php://fd/' . $ fd , 'r' ) ; if ( false === $ socket ) { throw new \ RuntimeException ( 'Could not open ' . $ fd ) ; } return $ this -> createDaemonFromStreamSocket ( $ kernel , $ options , $ socket ) ; }
|
Create a FastCGI daemon listening on file descriptor using the userland FastCGI implementation .
|
49,040
|
public function createTcpDaemon ( KernelInterface $ kernel , DaemonOptions $ options , string $ host , int $ port ) : DaemonInterface { $ address = 'tcp://' . $ host . ':' . $ port ; $ socket = stream_socket_server ( $ address ) ; if ( false === $ socket ) { throw new \ RuntimeException ( 'Could not create stream socket server on: ' . $ address ) ; } return $ this -> createDaemonFromStreamSocket ( $ kernel , $ options , $ socket ) ; }
|
Create a FastCGI daemon listening for TCP connections on a given address using the userland FastCGI implementation . The default host is localhost .
|
49,041
|
public function createDaemonFromStreamSocket ( KernelInterface $ kernel , DaemonOptions $ options , $ socket ) : DaemonInterface { $ connectionPool = new StreamSocketConnectionPool ( $ socket ) ; $ connectionHandlerFactory = new ConnectionHandlerFactory ( ) ; return new UserlandDaemon ( $ kernel , $ options , $ connectionPool , $ connectionHandlerFactory ) ; }
|
Create a FastCGI daemon from a stream socket which is configured for accepting connections using the userland FastCGI implementation .
|
49,042
|
public static function getSingleTableTypeMap ( ) { $ calledClass = get_called_class ( ) ; if ( array_key_exists ( $ calledClass , self :: $ singleTableTypeMap ) ) { return self :: $ singleTableTypeMap [ $ calledClass ] ; } $ typeMap = [ ] ; if ( property_exists ( $ calledClass , 'singleTableType' ) ) { $ classType = static :: $ singleTableType ; $ typeMap [ $ classType ] = $ calledClass ; } if ( property_exists ( $ calledClass , 'singleTableSubclasses' ) ) { $ subclasses = static :: $ singleTableSubclasses ; if ( ! in_array ( $ calledClass , $ subclasses ) ) { foreach ( $ subclasses as $ subclass ) { $ typeMap = $ typeMap + $ subclass :: getSingleTableTypeMap ( ) ; } } } self :: $ singleTableTypeMap [ $ calledClass ] = $ typeMap ; return $ typeMap ; }
|
Get the map of type field values to class names .
|
49,043
|
public static function getAllPersistedAttributes ( ) { $ calledClass = get_called_class ( ) ; if ( array_key_exists ( $ calledClass , self :: $ allPersisted ) ) { return self :: $ allPersisted [ $ calledClass ] ; } else { $ persisted = [ ] ; if ( property_exists ( $ calledClass , 'persisted' ) ) { $ persisted = $ calledClass :: $ persisted ; } $ parent = get_parent_class ( $ calledClass ) ; if ( method_exists ( $ parent , 'getAllPersistedAttributes' ) ) { $ persisted = array_merge ( $ persisted , $ parent :: getAllPersistedAttributes ( ) ) ; } } self :: $ allPersisted [ $ calledClass ] = $ persisted ; return self :: $ allPersisted [ $ calledClass ] ; }
|
Get all the persisted attributes that belongs to the class inheriting values declared on super classes
|
49,044
|
public function getPersistedAttributes ( ) { $ persisted = static :: getAllPersistedAttributes ( ) ; if ( empty ( $ persisted ) ) { return [ ] ; } else { return array_merge ( [ $ this -> primaryKey , static :: $ singleTableTypeField ] , static :: getAllPersistedAttributes ( ) , $ this -> getDates ( ) ) ; } }
|
Get the list of persisted attributes on this model inheriting values declared on super classes and including the model s primary key and any date fields .
|
49,045
|
public function setSingleTableType ( ) { $ modelClass = get_class ( $ this ) ; $ classType = property_exists ( $ modelClass , 'singleTableType' ) ? $ modelClass :: $ singleTableType : null ; if ( $ classType !== null ) { if ( $ this -> hasGetMutator ( static :: $ singleTableTypeField ) ) { $ this -> { static :: $ singleTableTypeField } = $ this -> mutateAttribute ( static :: $ singleTableTypeField , $ classType ) ; } else { $ this -> { static :: $ singleTableTypeField } = $ classType ; } } else { throw new SingleTableInheritanceException ( 'Cannot save Single table inheritance model without declaring static property $singleTableType.' ) ; } }
|
Set the type value into the type field attribute
|
49,046
|
public function newFromBuilder ( $ attributes = array ( ) , $ connection = null ) { $ typeField = static :: $ singleTableTypeField ; $ attributes = ( array ) $ attributes ; $ classType = array_key_exists ( $ typeField , $ attributes ) ? $ attributes [ $ typeField ] : null ; if ( $ classType !== null ) { $ childTypes = static :: getSingleTableTypeMap ( ) ; if ( array_key_exists ( $ classType , $ childTypes ) ) { $ class = $ childTypes [ $ classType ] ; $ instance = ( new $ class ) -> newInstance ( [ ] , true ) ; $ instance -> setFilteredAttributes ( $ attributes ) ; $ instance -> setConnection ( $ connection ? : $ this -> getConnectionName ( ) ) ; $ instance -> fireModelEvent ( 'retrieved' , false ) ; return $ instance ; } else { throw new SingleTableInheritanceException ( "Cannot construct newFromBuilder for unrecognized $typeField=$classType" ) ; } } else { return parent :: newFromBuilder ( $ attributes , $ connection ) ; } }
|
Override the Eloquent method to construct a model of the type given by the value of singleTableTypeField
|
49,047
|
public function arrayFilter ( array $ array , array $ callback = [ 'self' , 'filter' ] ) : array { foreach ( $ array as $ k => $ v ) { if ( \ is_array ( $ v ) ) { $ array [ $ k ] = $ this -> arrayFilter ( $ v , $ callback ) ; } } return array_filter ( $ array , $ callback ) ; }
|
Enhanced version of array_filter which allow to filter recursively .
|
49,048
|
public function handle ( MaintenanceModeDisabled $ maintenanceMode ) { $ startingTime = $ maintenanceMode -> time ; Log :: notice ( "Maintenance Mode Disabled, total downtime was " . Carbon :: now ( ) -> diffForHumans ( $ startingTime , true , true , 6 ) ) ; }
|
Log when maintenance mode ends and for how long it was down
|
49,049
|
protected function loadViews ( ) { $ this -> loadViewsFrom ( $ this -> getRelativePath ( 'views' ) , 'maintenancemode' ) ; $ this -> publishes ( [ $ this -> getRelativePath ( 'views' ) => base_path ( 'resources/views/vendor/maintenancemode' ) , ] , 'views' ) ; }
|
Register our view files
|
49,050
|
public function toResponse ( $ request ) { $ headers = array ( ) ; if ( $ this -> retryAfter ) { $ headers = array ( 'Retry-After' => $ this -> retryAfter ) ; } $ view = view ( ) -> first ( [ $ this -> view , config ( "maintenancemode.view" ) , "errors/503" , "maintenancemode::app-down" ] , [ ] ) ; return response ( $ view , 503 ) -> withHeaders ( $ headers ) ; }
|
Build a response for Laravel to show
|
49,051
|
protected function injectIntoViews ( $ info ) { if ( $ this -> inject ) { foreach ( $ info as $ key => $ value ) { $ this -> app [ 'view' ] -> share ( $ this -> prefix . $ key , $ value ) ; } } }
|
Inject the prefixed data into the views
|
49,052
|
protected function isExempt ( $ data , $ request ) { $ exemptions = $ this -> app [ 'config' ] -> get ( 'maintenancemode.exemptions' , [ ] ) ; foreach ( $ exemptions as $ className ) { if ( class_exists ( $ className ) ) { $ exemption = new $ className ( $ this -> app ) ; if ( $ exemption instanceof MaintenanceModeExemption ) { if ( $ exemption -> isExempt ( ) ) { return true ; } } else { throw new InvalidExemption ( $ this -> app [ 'translator' ] -> get ( $ this -> language . '.exceptions.invalid' , [ 'class' => $ className ] ) ) ; } } else { throw new ExemptionDoesNotExist ( $ this -> app [ 'translator' ] -> get ( $ this -> language . '.exceptions.missing' , [ 'class' => $ className ] ) ) ; } } if ( isset ( $ data [ 'allowed' ] ) && IpUtils :: checkIp ( $ request -> ip ( ) , ( array ) $ data [ 'allowed' ] ) ) { return true ; } return false ; }
|
Check if a user is exempt from the maintenance mode page
|
49,053
|
protected function getDownFilePayload ( ) { $ data = parent :: getDownFilePayload ( ) ; $ data [ 'view' ] = $ this -> option ( 'view' ) ; if ( ! isset ( $ data [ 'allowed' ] ) ) { $ data [ 'allowed' ] = $ this -> option ( 'allow' ) ; } return $ data ; }
|
Get the payload to be placed in the down file .
|
49,054
|
public function sync_config ( ) { $ db_class_vars = get_class_vars ( 'DB' ) ; foreach ( DB :: $ variables_to_sync as $ variable ) { if ( $ this -> $ variable !== $ db_class_vars [ $ variable ] ) { $ this -> $ variable = $ db_class_vars [ $ variable ] ; } } }
|
suck in config settings from static class
|
49,055
|
protected static function getReflectionClassWithProperty ( $ class , $ propertyName ) { Assert :: string ( $ class , 'First argument to Reflection::getReflectionClassWithProperty must be string. Variable of type "%s" was given.' ) ; Assert :: classExists ( $ class , 'Could not find class "%s"' ) ; $ refl = new \ ReflectionClass ( $ class ) ; if ( $ refl -> hasProperty ( $ propertyName ) ) { return $ refl ; } if ( false === $ parent = get_parent_class ( $ class ) ) { return ; } return self :: getReflectionClassWithProperty ( $ parent , $ propertyName ) ; }
|
Get a reflection class that has this property .
|
49,056
|
protected static function getAccessibleReflectionProperty ( $ objectOrClass , $ propertyName ) { Assert :: string ( $ propertyName , 'Property name must be a string. Variable of type "%s" was given.' ) ; $ class = $ objectOrClass ; if ( ! is_string ( $ objectOrClass ) ) { Assert :: object ( $ objectOrClass , 'Can not get a property of a non object. Variable of type "%s" was given.' ) ; Assert :: notInstanceOf ( $ objectOrClass , '\stdClass' , 'Can not get a property of \stdClass.' ) ; $ class = get_class ( $ objectOrClass ) ; } if ( null === $ refl = static :: getReflectionClassWithProperty ( $ class , $ propertyName ) ) { throw new \ LogicException ( sprintf ( 'The property %s does not exist on %s or any of its parents.' , $ propertyName , $ class ) ) ; } $ property = $ refl -> getProperty ( $ propertyName ) ; $ property -> setAccessible ( true ) ; if ( ! $ property -> isStatic ( ) ) { Assert :: object ( $ objectOrClass , 'Can not access non-static property without an object.' ) ; } return $ property ; }
|
Get an reflection property that you can access directly .
|
49,057
|
public static function getProperties ( $ objectOrClass ) { $ class = $ objectOrClass ; if ( ! is_string ( $ objectOrClass ) ) { Assert :: object ( $ objectOrClass , 'Can not get a property of a non object. Variable of type "%s" was given.' ) ; Assert :: notInstanceOf ( $ objectOrClass , '\stdClass' , 'Can not get a property of \stdClass.' ) ; $ class = get_class ( $ objectOrClass ) ; } $ refl = new \ ReflectionClass ( $ class ) ; $ properties = $ refl -> getProperties ( ) ; while ( false !== $ parent = get_parent_class ( $ class ) ) { $ parentRefl = new \ ReflectionClass ( $ parent ) ; $ properties = array_merge ( $ properties , $ parentRefl -> getProperties ( ) ) ; $ class = $ parent ; } return array_map ( function ( $ reflectionProperty ) { return $ reflectionProperty -> name ; } , $ properties ) ; }
|
Get all property names on a class or object
|
49,058
|
private function changeTwitterSettingsIfNeeded ( $ notifiable ) { if ( $ twitterSettings = $ notifiable -> routeNotificationFor ( 'twitter' ) ) { $ this -> twitter = new TwitterOAuth ( $ twitterSettings [ 0 ] , $ twitterSettings [ 1 ] , $ twitterSettings [ 2 ] , $ twitterSettings [ 3 ] ) ; } }
|
Use per user settings instead of default ones .
|
49,059
|
private function addImagesIfGiven ( $ twitterMessage ) { if ( is_a ( $ twitterMessage , TwitterStatusUpdate :: class ) && $ twitterMessage -> getImages ( ) ) { $ this -> twitter -> setTimeouts ( 10 , 15 ) ; $ twitterMessage -> imageIds = collect ( $ twitterMessage -> getImages ( ) ) -> map ( function ( TwitterImage $ image ) { $ media = $ this -> twitter -> upload ( 'media/upload' , [ 'media' => $ image -> getPath ( ) ] ) ; return $ media -> media_id_string ; } ) ; } return $ twitterMessage ; }
|
If it is a status update message and images are provided add them .
|
49,060
|
public function getReceiver ( TwitterOAuth $ twitter ) { if ( is_int ( $ this -> to ) ) { return $ this -> to ; } $ user = $ twitter -> get ( 'users/show' , [ 'screen_name' => $ this -> to , 'include_user_entities' => false , 'skip_status' => true , ] ) ; if ( $ twitter -> getLastHttpCode ( ) === 404 ) { throw CouldNotSendNotification :: userWasNotFound ( $ twitter -> getLastBody ( ) ) ; } return $ user -> id ; }
|
Get Twitter direct message receiver .
|
49,061
|
public function withImage ( $ images ) { collect ( $ images ) -> each ( function ( $ image ) { $ this -> images [ ] = new TwitterImage ( $ image ) ; } ) ; return $ this ; }
|
Set Twitter media files .
|
49,062
|
public function getRequestBody ( ) { $ body = [ 'status' => $ this -> getContent ( ) , ] ; if ( $ this -> imageIds ) { $ body [ 'media_ids' ] = $ this -> imageIds -> implode ( ',' ) ; } return $ body ; }
|
Build Twitter request body .
|
49,063
|
private function messageIsTooLong ( $ content , Brevity $ brevity ) { $ tweetLength = $ brevity -> tweetLength ( $ content ) ; $ exceededLength = $ tweetLength - 280 ; return $ exceededLength > 0 ? $ exceededLength : 0 ; }
|
Check if the message length is too long .
|
49,064
|
public static function boot ( ) { parent :: boot ( ) ; static :: created ( function ( ApiKey $ apiKey ) { self :: logApiKeyAdminEvent ( $ apiKey , self :: EVENT_NAME_CREATED ) ; } ) ; static :: updated ( function ( $ apiKey ) { $ changed = $ apiKey -> getDirty ( ) ; if ( isset ( $ changed ) && $ changed [ 'active' ] === 1 ) { self :: logApiKeyAdminEvent ( $ apiKey , self :: EVENT_NAME_ACTIVATED ) ; } if ( isset ( $ changed ) && $ changed [ 'active' ] === 0 ) { self :: logApiKeyAdminEvent ( $ apiKey , self :: EVENT_NAME_DEACTIVATED ) ; } } ) ; static :: deleted ( function ( $ apiKey ) { self :: logApiKeyAdminEvent ( $ apiKey , self :: EVENT_NAME_DELETED ) ; } ) ; }
|
Bootstrapping event handlers
|
49,065
|
protected static function logApiKeyAdminEvent ( ApiKey $ apiKey , $ eventName ) { $ event = new ApiKeyAdminEvent ; $ event -> api_key_id = $ apiKey -> id ; $ event -> ip_address = request ( ) -> ip ( ) ; $ event -> event = $ eventName ; $ event -> save ( ) ; }
|
Log an API key admin event
|
49,066
|
public function handle ( Request $ request , Closure $ next ) { $ header = $ request -> header ( self :: AUTH_HEADER ) ; $ apiKey = ApiKey :: getByKey ( $ header ) ; if ( $ apiKey instanceof ApiKey ) { $ this -> logAccessEvent ( $ request , $ apiKey ) ; return $ next ( $ request ) ; } return response ( [ 'errors' => [ [ 'message' => 'Unauthorized' ] ] ] , 401 ) ; }
|
Handle the incoming request
|
49,067
|
protected function logAccessEvent ( Request $ request , ApiKey $ apiKey ) { $ event = new ApiKeyAccessEvent ; $ event -> api_key_id = $ apiKey -> id ; $ event -> ip_address = $ request -> ip ( ) ; $ event -> url = $ request -> fullUrl ( ) ; $ event -> save ( ) ; }
|
Log an API key access event
|
49,068
|
protected function updateExtension ( common_ext_Extension $ ext ) { helpers_ExtensionHelper :: checkRequiredExtensions ( $ ext ) ; $ installed = common_ext_ExtensionsManager :: singleton ( ) -> getInstalledVersion ( $ ext -> getId ( ) ) ; $ codeVersion = $ ext -> getVersion ( ) ; if ( $ installed !== $ codeVersion ) { $ report = new common_report_Report ( common_report_Report :: TYPE_INFO , $ ext -> getName ( ) . ' requires update from ' . $ installed . ' to ' . $ codeVersion ) ; $ updaterClass = $ ext -> getManifest ( ) -> getUpdateHandler ( ) ; if ( is_null ( $ updaterClass ) ) { $ report = new common_report_Report ( common_report_Report :: TYPE_WARNING , 'No Updater found for ' . $ ext -> getName ( ) ) ; } elseif ( ! class_exists ( $ updaterClass ) ) { $ report = new common_report_Report ( common_report_Report :: TYPE_ERROR , 'Updater ' . $ updaterClass . ' not found' ) ; } else { $ updater = new $ updaterClass ( $ ext ) ; $ returnedVersion = $ updater -> update ( $ installed ) ; $ currentVersion = common_ext_ExtensionsManager :: singleton ( ) -> getInstalledVersion ( $ ext -> getId ( ) ) ; if ( ! is_null ( $ returnedVersion ) && $ returnedVersion != $ currentVersion ) { common_ext_ExtensionsManager :: singleton ( ) -> updateVersion ( $ ext , $ returnedVersion ) ; $ report -> add ( new common_report_Report ( common_report_Report :: TYPE_WARNING , 'Manually saved extension version' ) ) ; $ currentVersion = $ returnedVersion ; } if ( $ currentVersion == $ codeVersion ) { $ versionReport = new common_report_Report ( common_report_Report :: TYPE_SUCCESS , 'Successfully updated ' . $ ext -> getName ( ) . ' to ' . $ currentVersion ) ; } else { $ versionReport = new common_report_Report ( common_report_Report :: TYPE_WARNING , 'Update of ' . $ ext -> getName ( ) . ' exited with version ' . $ currentVersion ) ; } foreach ( $ updater -> getReports ( ) as $ updaterReport ) { $ versionReport -> add ( $ updaterReport ) ; } $ report -> add ( $ versionReport ) ; common_cache_FileCache :: singleton ( ) -> purge ( ) ; } } else { $ report = new common_report_Report ( common_report_Report :: TYPE_INFO , $ ext -> getName ( ) . ' already up to date' ) ; } return $ report ; }
|
Update a specific extension
|
49,069
|
public function validate ( array $ form ) { $ this -> isValid = true ; foreach ( $ form as $ field => $ value ) { if ( array_key_exists ( $ field , $ this -> validation ) ) { $ this -> validField ( $ field , $ value , $ this -> validation [ $ field ] ) ; } } return $ this ; }
|
valid a form .
|
49,070
|
protected function addError ( $ field , $ message ) { if ( array_key_exists ( $ field , $ this -> errors ) ) { $ this -> errors [ $ field ] [ ] = $ message ; } else { $ this -> errors [ $ field ] = [ $ message ] ; } return $ this ; }
|
add an error message
|
49,071
|
protected function validField ( $ field , $ value , $ config ) { foreach ( $ config as $ validator ) { $ class = $ validator [ 'class' ] ; $ option = $ validator [ 'options' ] ; $ test = new $ class ( $ option ) ; if ( ! $ this -> executeTest ( $ value , $ test ) ) { $ this -> isValid = false ; $ this -> addError ( $ field , $ test -> getMessage ( ) ) ; } } }
|
execute all validation for a field
|
49,072
|
public function getError ( $ field ) { if ( array_key_exists ( $ field , $ this -> errors ) ) { return $ this -> errors [ $ field ] ; } return null ; }
|
return error message for a field
|
49,073
|
public function initFile ( ) { if ( $ this -> maxFileSize > 0 && file_exists ( $ this -> filename ) && filesize ( $ this -> filename ) >= $ this -> maxFileSize ) { if ( $ this -> compression == self :: COMPRESSION_ZIP ) { $ zip = new ZipArchive ; $ res = $ zip -> open ( $ this -> getAvailableArchiveFileName ( ) , ZipArchive :: CREATE ) ; if ( $ res === true ) { $ zip -> addFile ( $ this -> filename , basename ( $ this -> filename ) ) ; $ zip -> close ( ) ; unlink ( $ this -> filename ) ; } else { return false ; } } elseif ( $ this -> compression == self :: COMPRESSION_NONE ) { $ success = rename ( $ this -> filename , $ this -> getAvailableArchiveFileName ( ) ) ; if ( ! $ success ) { return false ; } } else { return false ; } } $ this -> filehandle = @ fopen ( $ this -> filename , 'a' ) ; }
|
Short description of method initFile
|
49,074
|
private function getAvailableArchiveFileName ( ) { $ returnValue = ( string ) '' ; $ filebase = basename ( $ this -> filename ) ; $ dotpos = strrpos ( $ filebase , "." ) ; if ( $ dotpos === false ) { $ dotpos = strlen ( $ filebase ) ; } $ prefix = $ this -> directory . DIRECTORY_SEPARATOR . substr ( $ filebase , 0 , $ dotpos ) . "_" . date ( 'Y-m-d' ) ; $ sufix = substr ( $ filebase , $ dotpos ) . ( $ this -> compression === self :: COMPRESSION_ZIP ? '.zip' : '' ) ; $ count_string = "" ; $ count = 0 ; while ( file_exists ( $ prefix . $ count_string . $ sufix ) ) { $ count_string = "_" . ++ $ count ; } $ returnValue = $ prefix . $ count_string . $ sufix ; return ( string ) $ returnValue ; }
|
Short description of method getAvailableArchiveFileName
|
49,075
|
public static function getMicroTime ( ) { $ returnValue = ( float ) 0.0 ; list ( $ ms , $ s ) = explode ( " " , microtime ( ) ) ; $ returnValue = $ s + $ ms ; return ( float ) $ returnValue ; }
|
Short description of method getMicroTime
|
49,076
|
public static function singleton ( ) { $ returnValue = null ; if ( ! isset ( self :: $ instance ) ) { $ c = __CLASS__ ; self :: $ instance = new $ c ( ) ; } $ returnValue = self :: $ instance ; return $ returnValue ; }
|
Entry point . Enables you to retrieve staticly the DbWrapper instance .
|
49,077
|
public function getRowCount ( $ tableName , $ column = 'id' ) { $ sql = 'SELECT count("' . $ column . '") FROM "' . $ tableName . '"' ; $ result = $ this -> persistence -> query ( $ sql ) ; $ returnValue = intval ( $ result -> fetchColumn ( 0 ) ) ; $ result -> closeCursor ( ) ; return ( int ) $ returnValue ; }
|
Get the row count of a given table . The column to count is specified for performance reasons .
|
49,078
|
public function unregisterEvent ( $ event , $ callback ) { $ eventManager = $ this -> getServiceLocator ( ) -> get ( EventManager :: CONFIG_ID ) ; $ eventManager -> detach ( $ event , $ callback ) ; $ this -> getServiceManager ( ) -> register ( EventManager :: CONFIG_ID , $ eventManager ) ; }
|
remove event listener
|
49,079
|
protected function load ( core_kernel_classes_Class $ class , $ offset ) { $ results = $ this -> loadResources ( $ class , $ offset ) ; $ this -> instanceCache = array ( ) ; foreach ( $ results as $ resource ) { $ this -> instanceCache [ $ offset ] = $ resource -> getUri ( ) ; $ offset ++ ; } $ this -> endOfClass = count ( $ results ) < self :: CACHE_SIZE ; return count ( $ results ) > 0 ; }
|
Load instances into cache
|
49,080
|
public function quote ( $ parameter , $ parameter_type = PDO :: PARAM_STR ) { return $ this -> getDriver ( ) -> quote ( $ parameter , $ parameter_type ) ; }
|
Convenience access to quote .
|
49,081
|
function connect ( $ key , array $ params ) { $ this -> params = $ params ; $ this -> connectionSet ( $ params ) ; return new common_persistence_AdvKeyValuePersistence ( $ params , $ this ) ; }
|
store connection params and try to connect
|
49,082
|
function connectionSet ( array $ params ) { $ this -> connection = new Redis ( ) ; if ( $ this -> connection == false ) { throw new common_exception_Error ( "Redis php module not found" ) ; } if ( ! isset ( $ params [ 'host' ] ) ) { throw new common_exception_Error ( 'Missing host information for Redis driver' ) ; } $ host = $ params [ 'host' ] ; $ port = isset ( $ params [ 'port' ] ) ? $ params [ 'port' ] : self :: DEFAULT_PORT ; $ timeout = isset ( $ params [ 'timeout' ] ) ? $ params [ 'timeout' ] : self :: DEFAULT_TIMEOUT ; $ persist = isset ( $ params [ 'pconnect' ] ) ? $ params [ 'pconnect' ] : true ; $ this -> params [ 'attempt' ] = isset ( $ params [ 'attempt' ] ) ? $ params [ 'attempt' ] : self :: DEFAULT_ATTEMPT ; if ( $ persist ) { $ this -> connection -> pconnect ( $ host , $ port , $ timeout ) ; } else { $ this -> connection -> connect ( $ host , $ port , $ timeout ) ; } }
|
create a new connection using stored parameters
|
49,083
|
public function getInstances ( $ recursive = false , $ params = array ( ) ) { return ( array ) $ this -> getImplementation ( ) -> getInstances ( $ this , $ recursive , $ params ) ; }
|
return direct instances of this class as a collection
|
49,084
|
public function getInstancesPropertyValues ( core_kernel_classes_Property $ property , $ propertyFilters = array ( ) , $ options = array ( ) ) { return ( array ) $ this -> getImplementation ( ) -> getInstancesPropertyValues ( $ this , $ property , $ propertyFilters , $ options ) ; }
|
Get instances property values . The instances can be filtered .
|
49,085
|
public function deleteInstances ( $ resources , $ deleteReference = false ) { return ( bool ) $ this -> getImplementation ( ) -> deleteInstances ( $ this , $ resources , $ deleteReference ) ; }
|
Delete instances of a Class from the database .
|
49,086
|
protected function cleanSerial ( $ serial ) { if ( $ serial instanceof \ core_kernel_classes_Resource ) { $ serial = $ serial -> getUri ( ) ; } elseif ( $ serial instanceof \ core_kernel_classes_Literal ) { $ serial = $ serial -> __toString ( ) ; } elseif ( ! is_string ( $ serial ) ) { throw new FileSerializerException ( 'Unsupported serial "' . gettype ( $ serial ) . '" in ' . __CLASS__ ) ; } return $ serial ; }
|
Ensure serial is a string
|
49,087
|
protected function extract ( $ serial ) { $ serial = $ this -> cleanSerial ( $ serial ) ; $ parts = explode ( '/' , substr ( $ serial , strpos ( $ serial , '://' ) + 3 ) , 2 ) ; if ( count ( $ parts ) != 2 ) { throw new FileSerializerException ( 'Unsupported dir in ' . __CLASS__ ) ; } return [ 'fs' => $ parts [ 0 ] , 'path' => $ parts [ 1 ] ] ; }
|
Extract filesystem id and path from serial
|
49,088
|
public function addReadableModel ( $ id ) { common_Logger :: i ( 'ADDING MODEL ' . $ id ) ; $ readables = $ this -> getOption ( self :: OPTION_READABLE_MODELS ) ; $ this -> setOption ( self :: OPTION_READABLE_MODELS , array_unique ( array_merge ( $ readables , array ( $ id ) ) ) ) ; ModelManager :: setModel ( $ this ) ; }
|
Defines a model as readable
|
49,089
|
public static function getReadableModelIds ( ) { $ model = ModelManager :: getModel ( ) ; if ( ! $ model instanceof self ) { throw new common_exception_Error ( __FUNCTION__ . ' called on ' . get_class ( $ model ) . ' model implementation' ) ; } return $ model -> getReadableModels ( ) ; }
|
Returns the submodel ids that are readable
|
49,090
|
public static function getUpdatableModelIds ( ) { $ model = ModelManager :: getModel ( ) ; if ( ! $ model instanceof self ) { throw new common_exception_Error ( __FUNCTION__ . ' called on ' . get_class ( $ model ) . ' model implementation' ) ; } return $ model -> getWritableModels ( ) ; }
|
Returns the submodel ids that are updatable
|
49,091
|
public function addComponent ( common_configuration_Component $ component ) { $ components = $ this -> getComponents ( ) ; foreach ( $ components as $ c ) { if ( $ c === $ component ) { return ; } } $ components [ ] = $ component ; $ this -> setComponents ( $ components ) ; }
|
Short description of method addComponent
|
49,092
|
public function addDependency ( common_configuration_Component $ component , common_configuration_Component $ dependency ) { $ dependencies = $ this -> getDependencies ( ) ; $ found = false ; foreach ( $ dependencies as $ dep ) { if ( $ dependency === $ dep [ 'component' ] && $ component === $ dep [ 'isDependencyOf' ] ) { $ found = true ; break ; } } if ( false == $ found ) { $ dependencies [ ] = array ( 'component' => $ dependency , 'isDependencyOf' => $ component ) ; $ this -> setDependencies ( $ dependencies ) ; } }
|
Short description of method addDependency
|
49,093
|
public function check ( ) { $ returnValue = array ( ) ; $ this -> setCheckedComponents ( array ( ) ) ; $ this -> setReports ( array ( ) ) ; $ components = $ this -> getComponents ( ) ; $ dependencies = $ this -> getDependencies ( ) ; $ traversed = array ( ) ; foreach ( $ components as $ c ) { $ found = false ; foreach ( $ this -> getDependencies ( ) as $ d ) { if ( $ c === $ d [ 'isDependencyOf' ] ) { $ found = true ; break ; } } if ( $ found === false && $ c !== $ this -> getRootComponent ( ) ) { $ this -> addDependency ( $ c , $ this -> getRootComponent ( ) ) ; } } if ( count ( $ components ) > 0 ) { if ( true == $ this -> isAcyclic ( ) ) { $ stack = array ( ) ; $ node = $ components [ 0 ] ; $ status = $ this -> checkComponent ( $ node ) ; array_push ( $ traversed , $ node ) ; if ( $ status == common_configuration_Report :: VALID ) { $ stack = self :: pushTransitionsOnStack ( $ stack , $ this -> getTransitions ( $ node ) ) ; while ( count ( $ stack ) > 0 ) { $ transition = array_pop ( $ stack ) ; $ node = $ transition [ 'isDependencyOf' ] ; if ( false == in_array ( $ node , $ traversed ) ) { $ status = $ this -> checkComponent ( $ node ) ; array_push ( $ traversed , $ node ) ; if ( $ status == common_configuration_Report :: VALID ) { $ stack = self :: pushTransitionsOnStack ( $ stack , $ this -> getTransitions ( $ node ) ) ; } } } } $ returnValue = $ this -> getReports ( ) ; } else { throw new common_configuration_CyclicDependencyException ( "The dependency graph is cyclic. Please review your dependencies." ) ; } } return ( array ) $ returnValue ; }
|
Returns an array of Reports .
|
49,094
|
private function isAcyclic ( ) { $ returnValue = ( bool ) false ; $ l = array ( ) ; $ q = array ( ) ; $ components = $ this -> getComponents ( ) ; $ dependencies = $ this -> getDependencies ( ) ; foreach ( $ components as $ c ) { $ incomingEdges = false ; foreach ( $ dependencies as $ d ) { if ( $ c === $ d [ 'isDependencyOf' ] ) { $ incomingEdges = true ; break ; } } if ( $ incomingEdges == false ) { array_push ( $ q , $ c ) ; } } while ( count ( $ q ) > 0 ) { $ n = array_pop ( $ q ) ; array_push ( $ l , $ n ) ; foreach ( $ components as $ m ) { foreach ( $ dependencies as $ k => $ dep ) { if ( $ dep [ 'component' ] === $ n && $ dep [ 'isDependencyOf' ] === $ m ) { unset ( $ dependencies [ $ k ] ) ; foreach ( $ dependencies as $ dep ) { if ( $ dep [ 'isDependencyOf' ] === $ m ) { break 2 ; } } array_push ( $ q , $ m ) ; } } } } $ returnValue = count ( $ dependencies ) == 0 ; return ( bool ) $ returnValue ; }
|
Short description of method isAcyclic
|
49,095
|
private function getTransitions ( common_configuration_Component $ component ) { $ returnValue = array ( ) ; $ dependencies = $ this -> dependencies ; foreach ( $ dependencies as $ d ) { if ( $ d [ 'component' ] === $ component ) { array_push ( $ returnValue , $ d ) ; } } return ( array ) $ returnValue ; }
|
Short description of method getTransitions
|
49,096
|
public function getCheckedComponents ( ) { $ returnValue = array ( ) ; $ components = $ this -> getComponents ( ) ; $ checkedComponents = array ( ) ; foreach ( $ components as $ c ) { foreach ( $ this -> checkedComponents as $ cC ) { if ( $ cC === $ c ) { array_push ( $ checkedComponents , $ cC ) ; } } } $ returnValue = $ checkedComponents ; return ( array ) $ returnValue ; }
|
Short description of method getCheckedComponents
|
49,097
|
public function getUncheckedComponents ( ) { $ returnValue = array ( ) ; $ rootMock = $ this -> getRootComponent ( ) ; foreach ( $ this -> getComponents ( ) as $ c ) { if ( false === in_array ( $ c , $ this -> getCheckedComponents ( ) ) && $ c !== $ rootMock ) { array_push ( $ returnValue , $ c ) ; } } $ components = $ this -> getComponents ( ) ; $ uncheckedComponents = array ( ) ; foreach ( $ components as $ c ) { foreach ( $ returnValue as $ uC ) { if ( $ uC === $ c ) { array_push ( $ uncheckedComponents , $ uC ) ; } } } $ returnValue = $ uncheckedComponents ; return ( array ) $ returnValue ; }
|
Short description of method getUncheckedComponents
|
49,098
|
public static function pushTransitionsOnStack ( $ stack , $ transitions ) { $ returnValue = array ( ) ; foreach ( $ transitions as $ t ) { array_push ( $ stack , $ t ) ; } $ returnValue = $ stack ; return ( array ) $ returnValue ; }
|
Short description of method pushTransitionsOnStack
|
49,099
|
public function getReports ( ) { $ returnValue = array ( ) ; if ( count ( $ this -> reports ) == 0 ) { return $ returnValue ; } else { $ components = $ this -> getComponents ( ) ; $ reports = array ( ) ; foreach ( $ components as $ c ) { foreach ( $ this -> reports as $ r ) { if ( $ r -> getComponent ( ) === $ c ) { array_push ( $ reports , $ r ) ; } } } } $ returnValue = $ reports ; return ( array ) $ returnValue ; }
|
Short description of method getReports
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.