idx int64 0 60.3k | question stringlengths 92 4.62k | target stringlengths 7 635 |
|---|---|---|
3,200 | public static function safeFileAppend ( $ filepath , $ str , $ opts = array ( ) ) { $ debug = \ bdk \ Debug :: getInstance ( ) ; $ debug -> groupCollapsed ( __CLASS__ . '->' . __FUNCTION__ , $ filepath ) ; $ return = false ; if ( substr ( $ str , - 1 , 1 ) != "\n" ) { $ str .= "\n" ; } $ opts = array_merge ( array ( 'mode' => 'a' , 'est_size' => strlen ( $ str ) , 'lock' => false , 'keep_open' => false , ) , $ opts ) ; $ fh = self :: safeFopen ( $ filepath , $ opts ) ; if ( $ fh ) { if ( fwrite ( $ fh , $ str ) ) { $ return = true ; } else { trigger_error ( 'Error writing to ' . $ filepath , E_USER_ERROR ) ; } self :: safeFclose ( $ fh ) ; } $ debug -> groupEnd ( ) ; return $ return ; } | Append string to file |
3,201 | public static function writeDelimFile ( $ filepath = null , $ rows = array ( ) , $ opts = array ( ) ) { $ debug = \ bdk \ Debug :: getInstance ( ) ; $ debug -> groupCollapsed ( __CLASS__ . '->' . __FUNCTION__ , $ filepath ) ; $ return = false ; if ( ! is_array ( $ rows ) ) { $ rows = array ( ) ; } $ est_size = 0 ; $ sample_size = ceil ( count ( $ rows ) / 10 ) ; if ( $ sample_size > 1 ) { if ( $ sample_size > 100 ) { $ sample_size = 100 ; } $ rand_keys = array_rand ( $ rows , $ sample_size ) ; foreach ( $ rand_keys as $ k ) { $ est_size += strlen ( implode ( ',' , $ rows [ $ k ] ) ) ; } $ est_size = $ est_size * count ( $ rows ) / $ sample_size ; } $ opts = array_merge ( array ( 'est_size' => $ est_size , 'char' => ',' , 'header' => true , ) , $ opts ) ; $ fh = self :: safeFopen ( $ filepath , $ opts ) ; if ( $ fh ) { $ return = true ; $ keys = ArrayUtil :: columnKeys ( $ rows ) ; if ( $ opts [ 'header' ] ) { $ string = implode ( $ opts [ 'char' ] , $ keys ) . "\n" ; $ return = fwrite ( $ fh , $ string ) !== false ; } foreach ( $ rows as $ row ) { $ values = array ( ) ; foreach ( $ keys as $ key ) { $ values [ ] = isset ( $ row [ $ key ] ) ? $ row [ $ key ] : '' ; } $ string = ArrayUtil :: implodeDelim ( $ values , $ opts [ 'char' ] ) . "\n" ; $ return = fwrite ( $ fh , $ string ) !== false ; if ( ! $ return ) { break ; } } if ( ! $ return ) { trigger_error ( 'Error writing to ' . $ filepath , E_USER_ERROR ) ; } self :: safeFclose ( $ fh ) ; } $ debug -> groupEnd ( ) ; return $ return ; } | Write a delimited file |
3,202 | public static function & factory ( $ key , array $ params = [ ] , $ store = true ) { if ( static :: has ( $ key ) ) { return static :: get ( $ key ) ; } $ namespace = Path :: toNamespace ( $ key ) ; $ reflection = new ReflectionClass ( $ namespace ) ; $ object = $ reflection -> newInstanceArgs ( $ params ) ; if ( $ store ) { $ object = static :: set ( $ object , $ key ) ; } return $ object ; } | Register a file into memory and return an instantiated object . |
3,203 | public static function set ( $ object , $ key = null ) { if ( ! is_object ( $ object ) ) { throw new InvalidObjectException ( 'The object to register must be instantiated' ) ; } if ( ! $ key ) { $ key = get_class ( $ object ) ; } static :: $ _registered [ $ key ] = $ object ; return $ object ; } | Store an object into registry . |
3,204 | protected function getFullPathNameWithHash ( $ fileInfo ) { $ path = $ this -> resourceDirFullPath ; $ path .= '/' . $ fileInfo [ 'hash' ] . '.' . $ fileInfo [ 'ordinal' ] . $ this -> extension ; return $ path ; } | Returns the full path with hash of an resource file . |
3,205 | protected function getInfoResourceFiles ( ) { $ this -> logVerbose ( 'Get resource files info' ) ; $ resource_dir = $ this -> getProject ( ) -> getReference ( $ this -> resourcesFilesetId ) -> getDir ( $ this -> getProject ( ) ) ; foreach ( $ this -> resourceFileNames as $ filename ) { clearstatcache ( ) ; $ path = $ resource_dir . '/' . $ filename ; $ full_path = realpath ( $ path ) ; $ this -> store ( file_get_contents ( $ full_path ) , $ full_path , $ full_path , null ) ; } $ suc = ksort ( $ this -> resourceFilesInfo ) ; if ( $ suc === false ) $ this -> logError ( "ksort failed" ) ; } | Get info about each file in the fileset . |
3,206 | protected function getPathInResources ( $ path ) { if ( strncmp ( $ path , $ this -> parentResourceDirFullPath , strlen ( $ this -> parentResourceDirFullPath ) ) != 0 ) { throw new \ BuildException ( sprintf ( "Resource file '%s' is not under resource dir '%s'." , $ path , $ this -> parentResourceDirFullPath ) ) ; } return substr ( $ path , strlen ( $ this -> parentResourceDirFullPath ) ) ; } | Gets the path name relative to the parent resource directory of a resource file . |
3,207 | protected function getPathInResourcesWithHash ( $ baseUrl , $ resourcePathName ) { foreach ( $ this -> resourceFilesInfo as $ info ) { if ( $ info [ 'path_name_in_sources' ] === $ baseUrl . '/' . $ resourcePathName . $ this -> extension ) { return $ info [ 'path_name_in_sources_with_hash' ] ; } } return $ resourcePathName ; } | Returns path name in sources with hash from the resource info based on the path name in sources . If can t find return path name in sources . |
3,208 | protected function logError ( ) { $ args = func_get_args ( ) ; $ format = array_shift ( $ args ) ; foreach ( $ args as & $ arg ) { if ( ! is_scalar ( $ arg ) ) $ arg = var_export ( $ arg , true ) ; } if ( $ this -> haltOnError ) throw new \ BuildException ( vsprintf ( $ format , $ args ) ) ; if ( sizeof ( $ args ) == 0 ) { $ this -> log ( $ format , \ Project :: MSG_ERR ) ; } else { $ this -> log ( vsprintf ( $ format , $ args ) , \ Project :: MSG_ERR ) ; } } | Prints an error message and depending on HaltOnError throws an exception . |
3,209 | protected function logInfo ( ) { $ args = func_get_args ( ) ; $ format = array_shift ( $ args ) ; foreach ( $ args as & $ arg ) { if ( ! is_scalar ( $ arg ) ) $ arg = var_export ( $ arg , true ) ; } if ( sizeof ( $ args ) == 0 ) { $ this -> log ( $ format , \ Project :: MSG_INFO ) ; } else { $ this -> log ( vsprintf ( $ format , $ args ) , \ Project :: MSG_INFO ) ; } } | Prints an info message . |
3,210 | protected function logVerbose ( ) { $ args = func_get_args ( ) ; $ format = array_shift ( $ args ) ; foreach ( $ args as & $ arg ) { if ( ! is_scalar ( $ arg ) ) $ arg = var_export ( $ arg , true ) ; } if ( sizeof ( $ args ) == 0 ) { $ this -> log ( $ format , \ Project :: MSG_VERBOSE ) ; } else { $ this -> log ( vsprintf ( $ format , $ args ) , \ Project :: MSG_VERBOSE ) ; } } | Prints an verbose level message . |
3,211 | protected function setFilePermissions ( $ destinationFilename , $ referenceFilename ) { clearstatcache ( ) ; $ perms = fileperms ( $ referenceFilename ) ; if ( $ perms === false ) $ this -> logError ( "Unable to get permissions of file '%s'" , $ referenceFilename ) ; $ status = chmod ( $ destinationFilename , $ perms ) ; if ( $ status === false ) $ this -> logError ( "Unable to set permissions for file '%s'" , $ destinationFilename ) ; } | Sets the mode of a file . |
3,212 | protected function setModificationTime ( $ destinationFilename , $ newMtime ) { $ status = touch ( $ destinationFilename , $ newMtime ) ; if ( $ status === false ) { $ this -> logError ( "Unable to set mtime of file '%s'" , $ destinationFilename ) ; } } | Copy the mtime form the source file to the destination file . |
3,213 | protected function store ( $ resource , $ fullPathName , $ parts , $ getInfoBy ) { if ( $ fullPathName !== null ) $ this -> logInfo ( "Minimizing '%s'" , $ fullPathName ) ; $ content_opt = $ this -> minimizeResource ( $ resource , $ fullPathName ) ; $ file_info = [ ] ; $ file_info [ 'hash' ] = md5 ( $ content_opt ) ; $ file_info [ 'content_raw' ] = $ resource ; $ file_info [ 'content_opt' ] = $ content_opt ; $ file_info [ 'ordinal' ] = isset ( $ this -> hashCount [ $ file_info [ 'hash' ] ] ) ? $ this -> hashCount [ $ file_info [ 'hash' ] ] ++ : $ this -> hashCount [ $ file_info [ 'hash' ] ] = 0 ; $ file_info [ 'full_path_name_with_hash' ] = $ this -> resourceDirFullPath . '/' . $ file_info [ 'hash' ] . '.' . $ file_info [ 'ordinal' ] . $ this -> extension ; $ file_info [ 'path_name_in_sources_with_hash' ] = $ this -> getPathInResources ( $ file_info [ 'full_path_name_with_hash' ] ) ; if ( isset ( $ fullPathName ) ) { $ file_info [ 'full_path_name' ] = $ fullPathName ; $ file_info [ 'path_name_in_sources' ] = $ this -> getPathInResources ( $ fullPathName ) ; } if ( isset ( $ parts ) ) { $ file_info [ 'mtime' ] = $ this -> getMaxMtime ( $ parts , $ getInfoBy ) ; } $ this -> resourceFilesInfo [ ] = $ file_info ; return $ file_info ; } | Minimize resource create hash based on optimized content . Add resource info into array . |
3,214 | protected function match ( $ operator , $ pattern , $ value ) { $ value = strtolower ( $ value ) ; $ pattern = strtolower ( $ pattern ) ; switch ( $ operator ) { case '=' : return $ value === $ pattern ; case '!=' : return $ value !== $ pattern ; case '^=' : return preg_match ( '/^' . preg_quote ( $ pattern , '/' ) . '/' , $ value ) ; case '$=' : return preg_match ( '/' . preg_quote ( $ pattern , '/' ) . '$/' , $ value ) ; case '*=' : if ( $ pattern [ 0 ] == '/' ) { return preg_match ( $ pattern , $ value ) ; } return preg_match ( "/" . $ pattern . "/i" , $ value ) ; } return false ; } | Attempts to match the given arguments with the given operator . |
3,215 | static public function toCollections ( $ object ) { if ( $ object === null ) { return null ; } if ( ! is_array ( $ object ) ) { if ( is_object ( $ object ) ) { foreach ( $ object as $ key => $ value ) { $ object -> $ key = self :: toCollections ( $ value ) ; } } return $ object ; } if ( empty ( $ object ) ) { return new Map ( ) ; } $ elements = array ( ) ; $ isList = true ; $ lastKey = - 1 ; foreach ( $ object as $ key => $ element ) { $ elements [ $ key ] = self :: toCollections ( $ element ) ; if ( ! is_int ( $ key ) || intval ( $ key ) != $ lastKey + 1 ) { $ isList = false ; } $ lastKey = intval ( $ key ) ; } if ( $ isList ) { return new Liste ( $ elements ) ; } else { return new Map ( $ elements ) ; } } | Traverses public attributes of objects and arrays and converts all arrays to Lists and Maps |
3,216 | public function filter ( $ matcher ) { $ filtered = array ( ) ; foreach ( $ this as $ key => $ element ) { if ( call_user_func ( $ matcher , $ element , $ key ) ) { $ filtered [ $ key ] = $ element ; } } return new static ( $ filtered ) ; } | Filters all elements out that don t match the given matcher . |
3,217 | public function getExtension ( ) { $ basename = $ this -> getBasename ( ) ; if ( false !== $ pos = strrpos ( $ basename , '.' ) ) { $ ext = substr ( $ basename , $ pos + 1 ) ; } else { $ ext = '' ; } return $ ext ; } | Get filename extension |
3,218 | public function getReadHandler ( ) { if ( null === $ this -> stream ) { $ this -> stream = fopen ( $ this -> uri , 'r' ) ; } return $ this -> stream ; } | Get a handler resource for reading |
3,219 | public function getContents ( ) { if ( self :: SCHEME_RESOURCE === $ this -> getScheme ( ) ) { $ contents = '' ; while ( $ data = fread ( $ this -> stream , 2048 ) ) { $ contents .= $ data ; } } else { $ contents = file_get_contents ( $ this -> uri ) ; } return $ contents ; } | Get file contents as binary string |
3,220 | public function profiler ( $ request , $ response ) { $ this -> _stopTime ( ) ; if ( $ this -> _enabled == true ) { $ dataProfiler = [ ] ; $ dataProfiler [ 'time' ] = round ( $ this -> _time , 2 ) ; $ dataProfiler [ 'timeUser' ] = $ this -> _timeUser ; $ dataProfiler [ 'controller' ] = get_included_files ( ) ; $ dataProfiler [ 'template' ] = $ this -> _template ; $ dataProfiler [ 'request' ] = serialize ( $ request ) ; $ dataProfiler [ 'response' ] = serialize ( $ response ) ; $ dataProfiler [ 'sql' ] = $ this -> _sql ; $ dataProfiler [ 'get' ] = $ _GET ; $ dataProfiler [ 'post' ] = $ _POST ; $ dataProfiler [ 'put' ] = Data :: instance ( ) -> put ; $ dataProfiler [ 'patch' ] = Data :: instance ( ) -> patch ; $ dataProfiler [ 'delete' ] = Data :: instance ( ) -> delete ; $ dataProfiler [ 'session' ] = $ _SESSION ; $ dataProfiler [ 'cookie' ] = $ _COOKIE ; $ dataProfiler [ 'files' ] = $ _FILES ; $ dataProfiler [ 'server' ] = $ _SERVER ; $ dataProfiler [ 'url' ] = $ _SERVER [ 'REQUEST_URI' ] ; if ( $ request -> controller != 'asset' && $ request -> controller != 'profiler' ) { $ cache = new Cache ( 'core-profiler' , 0 ) ; $ cache -> setContent ( $ dataProfiler ) ; $ cache -> setCache ( ) ; } $ cacheId = new Cache ( 'core-profiler-' . $ request -> src . '.' . $ request -> controller . '.' . $ request -> action , 0 ) ; $ cacheId -> setContent ( $ dataProfiler ) ; $ cacheId -> setCache ( ) ; } } | at the end put data in cache |
3,221 | public function addTemplate ( $ name , $ type = self :: TEMPLATE_START , $ file ) { if ( $ this -> _enabled == true ) { switch ( $ type ) { case self :: TEMPLATE_START : $ this -> _template [ $ file ] [ 'name' ] = $ name ; $ this -> _template [ $ file ] [ 'time' ] = microtime ( true ) ; break ; case self :: TEMPLATE_END : $ this -> _template [ $ file ] [ 'time' ] = round ( ( microtime ( true ) - $ this -> _template [ $ file ] [ 'time' ] ) * 1000 , 4 ) ; break ; } } } | add a template |
3,222 | public function addSql ( $ name , $ type = self :: SQL_START , $ value = '' ) { if ( $ this -> _enabled == true ) { switch ( $ type ) { case self :: SQL_START : if ( isset ( $ this -> _sql [ $ name ] ) ) { $ this -> _lastSql = $ name ; } else { $ this -> _lastSql = $ name . rand ( 0 , 10 ) ; } $ this -> _sql [ $ this -> _lastSql ] = [ ] ; $ this -> _sql [ $ this -> _lastSql ] [ 'time' ] = microtime ( true ) ; break ; case self :: SQL_END : $ this -> _sql [ $ this -> _lastSql ] [ 'time' ] = round ( ( microtime ( true ) - $ this -> _sql [ $ this -> _lastSql ] [ 'time' ] ) * 1000 , 4 ) ; $ this -> _sql [ $ this -> _lastSql ] [ 'query' ] = $ value ; break ; } } } | add a sql query |
3,223 | public function addTime ( $ name , $ type = self :: USER_START ) { if ( $ this -> _enabled == true ) { switch ( $ type ) { case self :: USER_START : $ this -> _timeUser [ $ name ] = 0 ; $ this -> _timeUser [ $ name ] = microtime ( true ) ; break ; case self :: USER_END : $ this -> _timeUser [ $ name ] = round ( ( microtime ( true ) - $ this -> _timeUser [ $ name ] ) * 1000 , 4 ) ; break ; } } } | add time to timer |
3,224 | public function setCustomSSLValidation ( $ sslCustomCA = false , $ sslCustomCN = false ) { $ this -> _sslCustomCA = $ sslCustomCA ; $ this -> _sslCustomCN = $ sslCustomCN ; } | Sets custom CA and Common Name for SSL certificate validation for cases when system validation fails . |
3,225 | public function setDebug ( $ debugMode ) { $ this -> _debug = $ debugMode ; if ( isset ( $ this -> _connectionSwitcher ) ) { $ this -> _connectionSwitcher -> setDebug ( $ debugMode ) ; } } | Sets the debugging mode |
3,226 | private function _renderRequest ( CPS_Request & $ request ) { $ envelopeFields = array ( 'storage' => $ this -> _storageName , 'user' => $ this -> _username , 'password' => $ this -> _password , 'command' => $ request -> getCommand ( ) , ) ; if ( count ( $ this -> _customEnvelopeParams ) > 0 ) { foreach ( $ this -> _customEnvelopeParams as $ key => $ val ) { $ envelopeFields [ $ key ] = $ val ; } } if ( strlen ( $ request -> getRequestId ( ) ) > 0 ) $ envelopeFields [ 'requestid' ] = $ request -> getRequestId ( ) ; if ( strlen ( $ this -> _applicationId ) > 0 ) $ envelopeFields [ 'application' ] = $ this -> _applicationId ; if ( ! is_null ( $ reqType = $ request -> getRequestType ( ) ) ) $ envelopeFields [ 'type' ] = $ reqType ; if ( strlen ( $ reqLabel = $ request -> getClusterLabel ( ) ) ) $ envelopeFields [ 'label' ] = $ reqLabel ; return $ request -> getRequestXml ( $ this -> _documentRootXpath , $ this -> _documentIdXpath , $ envelopeFields , $ this -> _resetDocIds ) ; } | Renders the request as XML |
3,227 | function getLastRequestQuery ( $ stripEnvelope = false ) { $ html = $ this -> _lastRequestQuery ; if ( php_sapi_name ( ) == 'cli' ) { if ( ! $ this -> _debug ) { $ html = preg_replace ( array ( "<\<cps:user\>(.*)\<\/cps:user\>>" , "<\<cps:password\>(.*)\<\/cps:password\>>" ) , array ( '<cps:user>CPS_USER</cps:user>' , '<cps:password>CPS_PASSWORD</cps:password>' ) , $ this -> _lastRequestQuery ) ; } if ( $ stripEnvelope ) { preg_match ( "<\<cps:content\>([\s\S.]*)\<\/cps:content\>>" , $ html , $ matches ) ; $ html = @ $ matches [ 1 ] ; } return "Sent:\n" . $ html . '\n' ; } else { try { $ doc = new DOMDocument ( ) ; $ doc -> strictErrorChecking = false ; $ doc -> preserveWhiteSpace = false ; $ doc -> formatOutput = true ; @ $ doc -> loadXML ( $ this -> _lastRequestQuery ) ; $ html = $ doc -> saveXML ( ) ; } catch ( Exception $ e ) { } if ( ! $ this -> _debug ) { $ html = preg_replace ( array ( "<\<cps:user\>(.*)\<\/cps:user\>>" , "<\<cps:password\>(.*)\<\/cps:password\>>" ) , array ( '<cps:user>CPS_USER</cps:user>' , '<cps:password>CPS_PASSWORD</cps:password>' ) , $ html ) ; } if ( $ stripEnvelope ) { preg_match ( "<\<cps:content\>([\s\S.]*)\<\/cps:content\>>" , $ html , $ matches ) ; $ html = @ $ matches [ 1 ] ; } return 'Sent: <br /><pre>' . htmlspecialchars ( $ html ) . '</pre>' ; } } | returns raw query XML from the last request |
3,228 | private function _parseConnectionString ( $ string ) { $ res = array ( ) ; if ( ( $ string == '' ) || ( $ string == 'unix://' ) ) { $ res [ 'type' ] = 'socket' ; $ res [ 'host' ] = 'unix:///usr/local/cps2/storages/' . str_replace ( '/' , '_' , $ this -> _storageName ) . '/storage.sock' ; $ res [ 'port' ] = 0 ; } else if ( strncmp ( $ string , 'http://' , 7 ) == 0 ) { $ res [ 'type' ] = 'http' ; $ res [ 'url' ] = $ string ; } else if ( strncmp ( $ string , 'unix://' , 7 ) == 0 ) { $ res [ 'type' ] = 'socket' ; $ res [ 'host' ] = $ string ; $ res [ 'port' ] = 0 ; } else if ( strncmp ( $ string , 'tcp://' , 6 ) == 0 || strncmp ( $ string , 'tcps://' , 7 ) == 0 ) { $ res [ 'type' ] = 'socket' ; $ uc = parse_url ( $ string ) ; if ( ! isset ( $ uc [ 'host' ] ) ) { throw new CPS_Exception ( array ( array ( 'long_message' => 'Invalid connection string' , 'code' => ERROR_CODE_INVALID_CONNECTION_STRING , 'level' => 'REJECTED' , 'source' => 'CPS_API' ) ) ) ; } $ res [ 'host' ] = $ uc [ 'host' ] ; if ( isset ( $ uc [ 'port' ] ) ) { $ res [ 'port' ] = $ uc [ 'port' ] ; } else { $ res [ 'port' ] = 5550 ; } if ( strncmp ( $ string , 'tcps://' , 7 ) == 0 ) $ res [ 'ssl' ] = true ; } else { throw new CPS_Exception ( array ( array ( 'long_message' => 'Invalid connection string' , 'code' => ERROR_CODE_INVALID_CONNECTION_STRING , 'level' => 'REJECTED' , 'source' => 'CPS_API' ) ) ) ; } return $ res ; } | returns an array with parsed connection string data |
3,229 | public function newRequest ( CPS_Request & $ request ) { if ( ! array_search ( strtolower ( $ request -> getCommand ( ) ) , $ this -> _non_retry_cmds ) ) { $ this -> _retryRequests = true ; } else { $ this -> _retryRequests = false ; } if ( $ this -> _numUsed == count ( $ this -> _connectionStrings ) ) { $ this -> _usedConnections = array ( ) ; $ this -> _numUsed = 0 ; $ this -> _lastReturnedIndex = - 1 ; $ this -> _lastSuccess = false ; } } | This is called by CPS_Connection whenever there is a new request to be sent . This method should not be used directly . |
3,230 | private function logFailure ( ) { if ( $ this -> _debug ) { printf ( "[LoadBalancer] Failed for %s<br />\n" , $ this -> _connectionStrings [ $ this -> _lastReturnedIndex ] . ( isset ( $ this -> _storageNames [ $ this -> _lastReturnedIndex ] ) ? '|' . $ this -> _storageNames [ $ this -> _lastReturnedIndex ] : '' ) ) ; } $ hash = md5 ( $ this -> _connectionStrings [ $ this -> _lastReturnedIndex ] . ( isset ( $ this -> _storageNames [ $ this -> _lastReturnedIndex ] ) ? '|' . $ this -> _storageNames [ $ this -> _lastReturnedIndex ] : '' ) ) ; touch ( $ this -> _statusFilePrefix . $ hash ) ; } | This function is called whenever there was a sending failure - an error received or an exception raised |
3,231 | public function logSuccess ( ) { $ this -> _lastSuccess = true ; if ( $ this -> _debug ) { printf ( "[LoadBalancer] Success for %s<br />\n" , $ this -> _connectionStrings [ $ this -> _lastReturnedIndex ] . ( isset ( $ this -> _storageNames [ $ this -> _lastReturnedIndex ] ) ? '|' . $ this -> _storageNames [ $ this -> _lastReturnedIndex ] : '' ) ) ; } $ hash = md5 ( $ this -> _connectionStrings [ $ this -> _lastReturnedIndex ] . ( isset ( $ this -> _storageNames [ $ this -> _lastReturnedIndex ] ) ? '|' . $ this -> _storageNames [ $ this -> _lastReturnedIndex ] : '' ) ) ; if ( file_exists ( $ this -> _statusFilePrefix . $ hash ) ) { unlink ( $ this -> _statusFilePrefix . $ hash ) ; } } | This function is called whenever there was a sending success - no error received and no exception raised |
3,232 | public function shouldRetry ( & $ responseString , $ exception , $ transaction_id ) { if ( $ transaction_id ) return false ; if ( ! $ this -> _retryRequests ) return false ; if ( ! is_null ( $ exception ) ) { $ this -> logFailure ( ) ; if ( $ this -> _numUsed == count ( $ this -> _connectionStrings ) ) { return false ; } $ errors = $ exception -> errors ( ) ; if ( $ exception -> code ( ) == 9006 && $ errors [ 0 ] [ 'source' ] == "CPS_API" ) return true ; return false ; } $ this -> logSuccess ( ) ; return false ; } | This function should return whether a request should be retried depending on response |
3,233 | public static function _parse_conditions ( $ rights ) { if ( is_array ( $ rights ) ) { return $ rights ; } if ( ! is_string ( $ rights ) or strpos ( $ rights , '.' ) === false ) { throw new \ InvalidArgumentException ( 'Given rights where not formatted proppery. Formatting should be like area.right or area.[right, other_right]. Received: ' . $ rights ) ; } list ( $ area , $ rights ) = explode ( '.' , $ rights ) ; if ( substr ( $ rights , 0 , 1 ) == '[' and substr ( $ rights , - 1 , 1 ) == ']' ) { $ rights = preg_split ( '#( *)?,( *)?#' , trim ( substr ( $ rights , 1 , - 1 ) ) ) ; } return array ( $ area , $ rights ) ; } | Parses a conditions string into it s array equivalent |
3,234 | protected function populateState ( $ ordering = 'a.lft' , $ direction = 'asc' ) { $ app = JFactory :: getApplication ( ) ; $ forcedLanguage = $ app -> input -> get ( 'forcedLanguage' , '' , 'cmd' ) ; if ( $ layout = $ app -> input -> get ( 'layout' ) ) { $ this -> context .= '.' . $ layout ; } if ( $ forcedLanguage ) { $ this -> context .= '.' . $ forcedLanguage ; } $ extension = $ app -> getUserStateFromRequest ( $ this -> context . '.filter.extension' , 'extension' , 'com_content' , 'cmd' ) ; $ this -> setState ( 'filter.extension' , $ extension ) ; $ parts = explode ( '.' , $ extension ) ; $ this -> setState ( 'filter.component' , $ parts [ 0 ] ) ; $ this -> setState ( 'filter.section' , ( count ( $ parts ) > 1 ) ? $ parts [ 1 ] : null ) ; $ this -> setState ( 'filter.search' , $ this -> getUserStateFromRequest ( $ this -> context . '.search' , 'filter_search' , '' , 'string' ) ) ; $ this -> setState ( 'filter.published' , $ this -> getUserStateFromRequest ( $ this -> context . '.filter.published' , 'filter_published' , '' , 'string' ) ) ; $ this -> setState ( 'filter.access' , $ this -> getUserStateFromRequest ( $ this -> context . '.filter.access' , 'filter_access' , '' , 'cmd' ) ) ; $ this -> setState ( 'filter.language' , $ this -> getUserStateFromRequest ( $ this -> context . '.filter.language' , 'filter_language' , '' , 'string' ) ) ; $ this -> setState ( 'filter.level' , $ this -> getUserStateFromRequest ( $ this -> context . '.filter.level' , 'filter_level' , '' , 'string' ) ) ; parent :: populateState ( 'a.lft' , 'asc' ) ; parent :: populateState ( $ ordering , $ direction ) ; if ( ! empty ( $ forcedLanguage ) ) { $ this -> setState ( 'filter.language' , $ forcedLanguage ) ; } } | Method to auto - populate the model state . |
3,235 | protected function getStoreId ( $ id = '' ) { $ id .= ':' . $ this -> getState ( 'filter.extension' ) ; $ id .= ':' . $ this -> getState ( 'filter.search' ) ; $ id .= ':' . $ this -> getState ( 'filter.published' ) ; $ id .= ':' . $ this -> getState ( 'filter.access' ) ; $ id .= ':' . $ this -> getState ( 'filter.language' ) ; $ id .= ':' . $ this -> getState ( 'filter.level' ) ; $ id .= ':' . $ this -> getState ( 'filter.tag' ) ; return parent :: getStoreId ( $ id ) ; } | Method to get a store id based on model configuration state . |
3,236 | public function getItems ( ) { $ items = parent :: getItems ( ) ; if ( $ items != false ) { $ extension = $ this -> getState ( 'filter.extension' ) ; $ this -> countItems ( $ items , $ extension ) ; } return $ items ; } | Method to get an array of data items . |
3,237 | public function countItems ( & $ items , $ extension ) { $ parts = explode ( '.' , $ extension ) ; $ component = $ parts [ 0 ] ; $ section = null ; if ( count ( $ parts ) > 1 ) { $ section = $ parts [ 1 ] ; } $ eName = str_replace ( 'com_' , '' , $ component ) ; $ file = JPath :: clean ( JPATH_ADMINISTRATOR . '/components/' . $ component . '/helpers/' . $ eName . '.php' ) ; if ( file_exists ( $ file ) ) { require_once $ file ; $ prefix = ucfirst ( $ eName ) ; $ cName = $ prefix . 'Helper' ; if ( class_exists ( $ cName ) && is_callable ( array ( $ cName , 'countItems' ) ) ) { $ cName :: countItems ( $ items , $ section ) ; } } } | Method to load the countItems method from the extensions |
3,238 | public function each ( callable $ callback ) { foreach ( $ this -> all ( ) as $ key => $ value ) { $ callback ( $ key , $ value ) ; } return $ this ; } | Walk thru the elements of the array and apply a function to each |
3,239 | public function reduce ( callable $ callback , $ initial = null ) : self { return new static ( ( array ) array_reduce ( $ this -> all ( ) , $ callback , $ initial ) ) ; } | Iteratively reduce the array to a single value |
3,240 | public function reverse ( callable $ callback , bool $ keep_keys = false ) : self { return new static ( array_reverse ( $ this -> all ( ) , $ keep_keys ) ) ; } | Return an array with elements in reverse order |
3,241 | public function getItemsAction ( Meeting $ meeting ) { $ em = $ this -> getDoctrine ( ) -> getManager ( ) ; $ items = $ meeting -> getItems ( ) ; $ view = $ this -> view ( $ items , Response :: HTTP_OK ) ; return $ this -> handleView ( $ view ) ; } | Gets the list of all Items for a specific Meeting . |
3,242 | public function getItemAction ( Item $ item ) { $ view = $ this -> view ( $ item , Response :: HTTP_OK ) ; return $ this -> handleView ( $ view ) ; } | Gets a specific Item . |
3,243 | static public function endWith ( $ haystack , $ needle ) { if ( substr ( $ haystack , - strlen ( $ needle ) ) === ( string ) $ needle ) { return true ; } return false ; } | end with string |
3,244 | protected function _setExpiry ( $ expiry ) { if ( is_object ( $ expiry ) && in_array ( get_class ( $ expiry ) , [ Date :: class , FrozenDate :: class , FrozenTime :: class , Time :: class ] ) ) { return $ expiry ; } return new Time ( $ expiry ) ; } | set mutators for expiry property |
3,245 | protected function _setToken ( $ token ) { if ( ! $ token ) { return $ token ; } $ token = is_string ( $ token ) ? $ token : serialize ( $ token ) ; return substr ( Security :: hash ( $ token , 'sha1' , Configure :: read ( 'Tokens.tokenSalt' ) ) , 0 , 25 ) ; } | set mutators for token property |
3,246 | public function orderBy ( $ column , $ how = 'ASC' ) { if ( ! array_key_exists ( 'order_by' , $ this -> query ) ) { $ this -> query [ 'order_by' ] = array ( ) ; } if ( is_array ( $ column ) ) { foreach ( $ column as $ col => $ how ) { $ this -> orderBy ( $ col , $ how ) ; } } else { $ this -> query [ 'order_by' ] [ ] = $ this -> columnName ( $ column ) . " {$how}" ; } return $ this ; } | Orders the query rows . |
3,247 | public function where ( $ column , $ value = null ) { if ( ! isset ( $ this -> query [ 'where' ] ) ) { $ this -> query [ 'where' ] = array ( ) ; } if ( $ this -> mergeNextWhere and count ( $ this -> query [ 'where' ] ) > 0 ) { $ this -> mergeNextWhere = false ; return $ this -> _and ( $ column , $ value ) ; } if ( is_array ( $ column ) ) { $ this -> query [ 'where' ] [ ] = $ column ; } else { $ this -> query [ 'where' ] [ ] = array ( $ column => $ value ) ; } return $ this ; } | Easily add a table = something to the query . |
3,248 | public function _and ( $ column , $ value = null ) { if ( ! is_array ( $ column ) ) { $ column = array ( $ column => $ value ) ; } $ this -> query [ 'where' ] [ count ( $ this -> query [ 'where' ] ) - 1 ] = array_merge ( $ this -> query [ 'where' ] [ count ( $ this -> query [ 'where' ] ) - 1 ] , $ column ) ; return $ this ; } | Adds a filter to the last condition group . |
3,249 | public function join ( $ table , $ on , array $ columns = array ( ) ) { if ( ! array_key_exists ( 'joins' , $ this -> query ) ) { $ this -> query [ 'joins' ] = array ( ) ; } $ this -> query [ 'select' ] = array_merge ( $ this -> query [ 'select' ] , $ columns ) ; $ this -> query [ 'joins' ] [ ] = array ( $ table , $ on ) ; return $ this ; } | Join another table . |
3,250 | public function exec ( ) { $ result = $ this -> connection ( ) -> prepare ( $ this -> assemble ( ) ) ; foreach ( $ this -> valuesToBind as $ key => $ value ) { $ result -> bindValue ( ":{$key}" , $ value ) ; } return $ result -> model ( $ this -> model ) -> exec ( ) ; } | Executes the query and return the statement . |
3,251 | public function assemble ( ) { $ queryString = array ( ) ; $ queryString [ ] = $ this -> query [ 'type' ] ; if ( $ this -> query [ 'type' ] == "SELECT" or $ this -> query [ 'type' ] == "SELECT DISTINCT" ) { $ queryString [ ] = $ this -> buildSelectColumns ( ) ; $ queryString [ ] = "FROM `{$this->query['table']}`" ; if ( array_key_exists ( 'joins' , $ this -> query ) ) { $ queryString [ ] = $ this -> buildJoins ( ) ; } $ queryString [ ] = $ this -> buildWhere ( ) ; if ( array_key_exists ( 'sql' , $ this -> query ) ) { $ queryString [ ] = $ this -> query [ 'sql' ] ; } if ( array_key_exists ( 'order_by' , $ this -> query ) ) { $ queryString [ ] = "ORDER BY " . implode ( ", " , $ this -> query [ 'order_by' ] ) ; } } elseif ( $ this -> query [ 'type' ] == "INSERT INTO" ) { $ queryString [ ] = "`{$this->query['table']}`" ; $ columns = $ values = array ( ) ; foreach ( $ this -> query [ 'data' ] as $ column => $ value ) { $ columns [ ] = $ this -> columnName ( $ column ) ; $ values [ ] = $ this -> processValue ( $ value ) ; } $ queryString [ ] = "(" . implode ( ',' , $ columns ) . ")" ; $ queryString [ ] = "VALUES (" . implode ( ',' , $ values ) . ")" ; } elseif ( $ this -> query [ 'type' ] == "UPDATE" ) { $ queryString [ ] = "`{$this->query['table']}`" ; $ values = array ( ) ; foreach ( $ this -> query [ 'data' ] as $ column => $ value ) { $ column = $ this -> columnName ( $ column ) ; $ valueBindKey = "new_" . str_replace ( array ( '.' , '`' ) , array ( '_' , '' ) , $ column ) ; $ this -> valuesToBind [ $ valueBindKey ] = $ value ; $ values [ ] = $ column . " = :{$valueBindKey}" ; } $ queryString [ ] = "SET " . implode ( ", " , $ values ) ; $ queryString [ ] = $ this -> buildWhere ( ) ; } elseif ( $ this -> query [ 'type' ] == "DELETE" ) { $ queryString [ ] = "FROM `{$this->query['table']}`" ; $ queryString [ ] = $ this -> buildWhere ( ) ; } return implode ( " " , str_replace ( "{prefix}" , $ this -> prefix , $ queryString ) ) ; } | Private method used to compile the query into a string . |
3,252 | private function buildSelectColumns ( ) { $ columns = array ( ) ; foreach ( $ this -> query [ 'select' ] as $ column => $ as ) { if ( is_numeric ( $ column ) ) { $ columns [ ] = $ this -> columnName ( $ as ) ; } else { $ columns [ ] = $ this -> columnName ( $ column ) . " AS `{$as}`" ; } } return implode ( ', ' , $ columns ) ; } | Builds the columns for the select queries . |
3,253 | private function columnName ( $ column ) { if ( $ column == '*' ) { return "`{$this->query['table']}`.*" ; } if ( strpos ( $ column , '.' ) === false ) { $ column = $ this -> query [ 'table' ] . ".{$column}" ; } if ( strpos ( $ column , '(' ) === false ) { return str_replace ( array ( '.' ) , array ( '`.`' ) , "`{$column}`" ) ; } else { return trim ( str_replace ( array ( '(' , ')' , '.' ) , array ( '(`' , '`)' , '`.`' ) , $ column ) , '`' ) ; } } | Makes the column name safe for queries . |
3,254 | private function buildWhere ( ) { $ query = array ( ) ; if ( isset ( $ this -> query [ 'where' ] ) and count ( $ this -> query [ 'where' ] ) ) { foreach ( $ this -> query [ 'where' ] as $ group => $ conditions ) { $ group = array ( ) ; foreach ( $ conditions as $ condition => $ value ) { $ cond = explode ( " " , $ condition ) ; $ column = str_replace ( '`' , '' , $ cond [ 0 ] ) ; $ safeColumn = $ this -> columnName ( $ column ) ; $ condition = str_replace ( $ column , $ safeColumn , $ condition ) ; $ valueBindKey = str_replace ( array ( '.' , '`' ) , array ( '_' , '' ) , $ safeColumn ) ; if ( ! empty ( $ value ) or $ value !== null ) { $ this -> valuesToBind [ $ valueBindKey ] = $ value ; } $ group [ ] = str_replace ( "?" , ":{$valueBindKey}" , $ condition ) ; } $ query [ ] = "(" . implode ( " AND " , $ group ) . ")" ; } return "WHERE " . implode ( " OR " , $ query ) ; } } | Compiles the where conditions . |
3,255 | private function buildJoins ( ) { $ joins = array ( ) ; foreach ( $ this -> query [ 'joins' ] as $ join ) { if ( is_array ( $ join [ 0 ] ) ) { $ joins [ ] = "LEFT JOIN `{$join[0][0]}` `{$join[0][1]}` on {$join[1]}" ; } else { $ joins [ ] = "LEFT JOIN `{$join[0]}` on {$join[1]}" ; } } return implode ( " " , $ joins ) ; } | Compiles the joins . |
3,256 | private function processValue ( $ value ) { if ( $ value === "NOW()" ) { return $ this -> connection ( ) -> quote ( gmdate ( "Y-m-d H:i:s" ) ) ; } elseif ( $ value === "NULL" ) { return 'NULL' ; } elseif ( is_array ( $ value ) ) { return $ this -> connection ( ) -> quote ( json_encode ( $ value ) ) ; } else { return $ this -> connection ( ) -> quote ( $ value ) ; } } | Processes the value . |
3,257 | public function format ( ) { if ( $ this -> format === null ) { if ( null !== ( $ format = $ this -> parameters -> getParam ( 'format' ) ) ) { $ this -> format = $ format ; } else { $ headers = getallheaders ( ) ; if ( isset ( $ headers [ 'Accept' ] ) ) { $ acceptHeader = $ headers [ 'Accept' ] ; $ negotiator = new FormatNegotiator ( ) ; $ priorities = [ 'html' , 'json' , 'xml' , 'js' , '*.*' ] ; $ this -> format = $ negotiator -> getBestFormat ( $ acceptHeader , $ priorities ) ? : 'html' ; } else { $ this -> format = 'html' ; } } } return $ this -> format ; } | Looks for the best format that fits the request . If format is not specified in the request parameters FormatNegotiator is used to determine the best format . If everything fails html is assumed . |
3,258 | public function uploadedFiles ( ) { if ( ! $ this -> files ) { $ this -> files = new UploadedFiles ( $ _FILES ) ; } return $ this -> files -> files ( ) ; } | Get uploaded files . |
3,259 | public function render ( $ template , array $ vars = [ ] , array $ blocks = [ ] ) { $ directory = rtrim ( $ this -> directory , DIRECTORY_SEPARATOR ) . DIRECTORY_SEPARATOR ; $ file = $ directory . trim ( $ template , DIRECTORY_SEPARATOR ) . $ this -> suffix ; $ vars += $ this -> vars ; $ sandbox = new Template ( $ this , $ file , $ blocks , $ this -> helpers ) ; return $ sandbox -> compile ( $ vars ) ; } | Generate content from template compilation |
3,260 | public static function make ( $ template , array $ vars = [ ] , array $ blocks = [ ] ) { if ( ! static :: $ instance ) { static :: $ instance = new static ; } return static :: $ instance -> render ( $ template , $ vars , $ blocks ) ; } | Generate content from static template compilation |
3,261 | public function getSex ( ) { $ result = null ; if ( isset ( $ this -> userInfo [ 'sex' ] ) ) { $ result = $ this -> userInfo [ 'sex' ] == 1 ? 'female' : 'male' ; } return $ result ; } | Get user sex or null if it is not set |
3,262 | public static function getInstance ( $ p_file ) { if ( self :: $ instance === null ) { self :: $ instance = new static ( $ p_file ) ; } return self :: $ instance ; } | Retourne une instance |
3,263 | public function addBuilds ( BuildIterator $ builds ) { foreach ( $ builds as $ build ) { $ this -> builds -> add ( $ build ) ; } } | Adds a number of builds to the queue . |
3,264 | public function getNextBuildTime ( ) { $ nextBuildTime = null ; $ build = null ; while ( $ this -> builds -> valid ( ) ) { $ build = $ this -> builds -> current ( ) ; if ( $ build -> getNextBuildTime ( ) <= $ nextBuildTime || $ nextBuildTime === null ) { if ( $ build -> getStatus ( ) != BuildInterface :: STOPPED ) { $ buildTime = $ build -> getNextBuildTime ( ) ; if ( $ buildTime !== null && ! $ build -> isQueued ( ) ) { $ nextBuildTime = $ buildTime ; $ this -> queue [ ] = $ build ; $ build -> enqueue ( ) ; } else { $ nextBuildTime = $ buildTime ; } } } $ this -> builds -> next ( ) ; } usort ( $ this -> queue , array ( $ this , 'sortQueue' ) ) ; $ this -> builds -> rewind ( ) ; return $ nextBuildTime ; } | Returns the next build time of all the builds scheduled in this queue . |
3,265 | public function sortQueue ( $ a , $ b ) { $ buildTimeA = $ a -> getNextBuildTime ( ) ; $ buildTimeB = $ b -> getNextBuildTime ( ) ; if ( $ buildTimeA == $ buildTimeB ) { return 0 ; } return $ buildTimeA < $ buildTimeB ? - 1 : 1 ; } | Sorts the builds in the queue by buildtime . |
3,266 | public function getNextBuild ( ) { usort ( $ this -> queue , array ( $ this , 'sortQueue' ) ) ; if ( isset ( $ this -> queue [ 0 ] ) ) { if ( $ this -> queue [ 0 ] -> getNextBuildTime ( ) <= time ( ) ) { $ build = array_shift ( $ this -> queue ) ; $ build -> dequeue ( ) ; return $ build ; } } return ; } | Removes the next scheduled build from the queue and returns it . |
3,267 | public function isPost ( $ redirectUrl = null ) { if ( $ this -> getRequest ( ) -> isPost ) { return true ; } if ( is_null ( $ redirectUrl ) ) { return false ; } return $ this -> redirect ( $ redirectUrl ) -> send ( ) ; } | Checks if the current request is a POST and handles redirection |
3,268 | function getBaseUrl ( ) { $ filename = $ this -> getServer ( ) -> get ( 'SCRIPT_FILENAME' , '' ) ; $ scriptName = $ this -> getServer ( ) -> get ( 'SCRIPT_NAME' ) ; $ phpSelf = $ this -> getServer ( ) -> get ( 'PHP_SELF' ) ; $ origScriptName = $ this -> getServer ( ) -> get ( 'ORIG_SCRIPT_NAME' , false ) ; if ( $ scriptName !== null && basename ( $ scriptName ) === $ filename ) { $ baseUrl = $ scriptName ; } elseif ( $ phpSelf !== null && basename ( $ phpSelf ) === $ filename ) { $ baseUrl = $ phpSelf ; } elseif ( $ origScriptName !== null && basename ( $ origScriptName ) === $ filename ) { $ baseUrl = $ origScriptName ; } else { $ baseUrl = '/' ; $ basename = basename ( $ filename ) ; if ( $ basename ) { $ path = ( $ phpSelf ? trim ( $ phpSelf , '/' ) : '' ) ; $ baseUrl .= substr ( $ path , 0 , strpos ( $ path , $ basename ) ) . $ basename ; } } $ requestUri = $ this -> getMessageObject ( ) -> getTarget ( ) ; if ( 0 === strpos ( $ requestUri , $ baseUrl ) ) return $ baseUrl ; $ baseDir = str_replace ( '\\' , '/' , dirname ( $ baseUrl ) ) ; if ( 0 === strpos ( $ requestUri , $ baseDir ) ) return $ baseDir ; $ truncatedRequestUri = $ requestUri ; if ( false !== ( $ pos = strpos ( $ requestUri , '?' ) ) ) $ truncatedRequestUri = substr ( $ requestUri , 0 , $ pos ) ; $ basename = basename ( $ baseUrl ) ; if ( empty ( $ basename ) || false === strpos ( $ truncatedRequestUri , $ basename ) ) return '' ; if ( strlen ( $ requestUri ) >= strlen ( $ baseUrl ) && ( false !== ( $ pos = strpos ( $ requestUri , $ baseUrl ) ) && $ pos !== 0 ) ) { $ baseUrl = substr ( $ requestUri , 0 , $ pos + strlen ( $ baseUrl ) ) ; } return $ baseUrl ; } | Detect Base Url |
3,269 | function getBasePath ( ) { $ filename = basename ( $ this -> getServer ( ) -> get ( 'SCRIPT_FILENAME' , '' ) ) ; $ baseUrl = $ this -> getBaseUrl ( ) ; if ( $ baseUrl === '' ) return '' ; if ( basename ( $ baseUrl ) === $ filename ) return str_replace ( '\\' , '/' , dirname ( $ baseUrl ) ) ; return rtrim ( $ baseUrl , '/' ) ; } | Detect Base Path |
3,270 | public function getEvent ( $ id ) { if ( ! array_key_exists ( $ id , $ this -> identifiers ) ) { return false ; } return $ this -> identifiers [ $ id ] ; } | Retrieve event . |
3,271 | protected function addStatusMessage ( $ type , $ messages ) { if ( is_array ( $ messages ) ) { foreach ( $ messages as $ message ) { $ _SESSION [ 'messages' ] [ 'status' ] [ $ type ] [ ] = $ message ; } } else { $ _SESSION [ 'messages' ] [ 'status' ] [ $ type ] [ ] = $ messages ; } } | Adds one or more status messages to the response data . Since this response causes a redirection the data is stored in the session . |
3,272 | public function parse ( Url $ url ) : ? array { $ path = $ url -> path ( ) ; $ pattern = $ this -> buildRoutePattern ( ) ; if ( preg_match ( $ pattern , $ path , $ matches ) === 1 ) { $ variables = [ ] ; $ length = sizeof ( $ matches ) ; for ( $ i = 1 ; $ i < $ length ; $ i ++ ) { $ variables [ $ this -> parameter [ $ i - 1 ] ] = $ matches [ $ i ] ; } return $ variables ; } return null ; } | Trys to extract all route variables of a given Url . When the route doesen match the Url null will be returned . |
3,273 | public function match ( $ request_uri , $ request_method , $ rules = array ( ) ) { $ this -> arguments = array ( ) ; if ( $ this -> method != $ request_method ) return false ; if ( $ this -> action == $ request_uri ) return true ; if ( ( $ strpos = strpos ( $ this -> action , '$' ) ) !== false ) { return $ this -> match_with_arguments ( $ request_uri , $ rules ) ; } return false ; } | verifica se l uri richiesta corrisponde alla seguente rotta |
3,274 | public function call ( $ namespaces = array ( ) ) { foreach ( $ this -> middlewares as $ middleware_class ) { $ middleware = new $ middleware_class ; if ( ! $ middleware -> handle ( ) ) return false ; } return $ this -> call_internal ( $ namespaces ) ; } | ed in seguito chiama la callback |
3,275 | private function call_internal ( $ namespaces = array ( ) ) { if ( is_callable ( $ this -> callback ) ) { call_user_func_array ( $ this -> callback , $ this -> arguments ) ; return true ; } else if ( is_string ( $ this -> callback ) ) { $ classname = $ this -> callback ; $ action = 'index' ; if ( ( $ strpos = strpos ( $ classname , '::' ) ) !== false ) { $ temp = explode ( '::' , $ classname ) ; dd ( $ temp ) ; if ( count ( $ temp ) > 0 ) { $ alias = $ temp [ 0 ] ; if ( array_key_exists ( $ alias , $ namespaces ) ) { if ( ! empty ( $ namespaces [ $ alias ] ) ) { $ classname = str_replace ( "$alias::" , $ namespaces [ $ alias ] . '\\' , $ classname ) ; } else return false ; } } else return false ; } if ( ( $ strpos = strpos ( $ classname , '@' ) ) !== false ) { $ pieces = explode ( '@' , $ classname ) ; $ classname = $ pieces [ 0 ] ; $ action = $ pieces [ 1 ] ; } if ( class_exists ( $ classname ) ) { $ _obj = new $ classname ( ) ; if ( is_callable ( array ( $ _obj , $ action ) ) ) { call_user_func_array ( array ( $ _obj , $ action ) , $ this -> arguments ) ; return true ; } else return false ; } else return false ; } else return false ; } | esegui la callback |
3,276 | public function xgetFieldTypes ( $ onlyUsable = false ) { $ fieldTypes = array_keys ( $ this -> _getFields ( ) ) ; if ( $ onlyUsable ) { unset ( $ fieldTypes [ 'root' ] ) ; unset ( $ fieldTypes [ 'referenceroot' ] ) ; unset ( $ fieldTypes [ 'reference' ] ) ; } sort ( $ fieldTypes ) ; return $ fieldTypes ; } | Returns all titles . |
3,277 | public function setAllData ( $ data ) { array_walk ( $ data , function ( $ value , $ key ) { $ this -> { $ key } = $ value ; } ) ; return $ this ; } | set array of data |
3,278 | public function delocalizeSegments ( array & $ segments ) { if ( count ( $ segments ) > 0 ) { $ locale = $ segments [ 0 ] ; if ( $ this -> localeHelper -> isValidLocale ( $ locale ) ) { array_shift ( $ segments ) ; } } } | Delocalizes segments in path |
3,279 | public function performRedirect ( RedirectContainer $ container ) { $ path = $ container -> getRedirectpath ( ) ; $ request = $ container -> getRequest ( ) ; $ request -> flash ( ) ; if ( $ container -> shouldIncludeQuery ( ) ) { $ path .= $ this -> getQueryStringFromRequest ( $ request ) ; } if ( $ container -> shouldForceSSL ( ) ) { return redirect ( ) -> secure ( $ path ) ; } else { return redirect ( $ path ) ; } } | Redirects to path with or without querystring |
3,280 | public function getUri ( $ data = null ) { if ( isset ( $ data [ 'uriData' ] ) ) { $ this -> uri = str_replace ( '{params}' , implode ( '/' , $ data [ 'uriData' ] ) , $ this -> uri ) ; } return $ this -> uri ; } | get the endpoint uri . |
3,281 | public function getTransformer ( $ type = 'response' ) { return isset ( $ this -> transformers [ $ type ] ) ? $ this -> transformers [ $ type ] : null ; } | Get the endpoint transformer . |
3,282 | public static function create ( $ engine , $ args = null ) { $ engine = strtolower ( $ engine ) ; if ( self :: validEngine ( $ engine ) ) { return ( isset ( $ args ) ) ? self :: createWithArgs ( $ engine , $ args ) : self :: createWithArgs ( $ engine , array ( ) ) ; } throw new \ Franzip \ SerpFetcher \ Exceptions \ UnsupportedEngineException ( 'Invalid SerpFetcher $engine: unknown/unsupported Search Engine. Supported engines are: \'google\', \'ask\', \'bing\', \'yahoo\'' ) ; } | Return a SerpFetcher implementation for a given search engine . |
3,283 | private static function createWithArgs ( $ engine , $ args ) { $ engineName = ucfirst ( $ engine ) ; $ className = self :: FETCHER_CLASS_PREFIX . $ engineName . self :: FETCHER_CLASS_SUFFIX ; return call_user_func_array ( array ( new \ ReflectionClass ( $ className ) , 'newInstance' ) , $ args ) ; } | Use reflection to instantiate the right Fetcher at runtime . |
3,284 | public function add ( $ item , & $ success = null ) { $ result = $ this -> fire ( 'before-add' , $ item ) ; if ( ! $ result -> isPropagationStopped ( ) ) { $ this -> items [ ] = $ this -> decorate ( $ item ) ; $ this -> len ++ ; $ this -> fire ( 'add' , $ item ) ; $ success = true ; } else { $ success = false ; } return $ this ; } | Adds an item to collection . |
3,285 | public function contains ( $ item ) { for ( $ i = 0 ; $ i < $ this -> len ; $ i ++ ) { if ( $ this -> compare ( $ item , $ this -> items [ $ i ] ) === 0 ) { return true ; } } return false ; } | Returns TRUE if this collection contains an item and FALSE otherwise |
3,286 | public function filter ( $ callback ) { $ result = [ ] ; if ( is_callable ( $ callback ) ) { for ( $ i = 0 ; $ i < $ this -> len ; $ i ++ ) { if ( call_user_func ( $ callback , $ this -> items [ $ i ] , $ i , $ this ) ) { $ result [ ] = & $ this -> items [ $ i ] ; } } } $ myName = get_class ( ) ; return new $ myName ( $ result ) ; } | Returns another collection of the same type with items which are passing a filter test . |
3,287 | public function sort ( $ callback = null , $ ascending = true ) { if ( null !== $ callback && ! is_callable ( $ callback ) ) { throw new \ browserfs \ Exception ( 'Invalid argument $callback: Expected callable( any, any ): int | null' ) ; } $ result = [ ] ; for ( $ i = 0 ; $ i < $ this -> len ; $ i ++ ) { $ result [ ] = & $ this -> items [ $ i ] ; } if ( is_callable ( $ callback ) ) { usort ( $ result , $ callback ) ; } else { usort ( $ result , [ $ this , 'compare' ] ) ; } return new static ( $ ascending ? $ result : array_reverse ( $ result ) ) ; } | Returns a sorted collection based on a user - defined function |
3,288 | public function unique ( $ callback = null ) { $ result = [ ] ; if ( $ callback === null ) { $ n = 0 ; for ( $ i = 0 ; $ i < $ this -> len ; $ i ++ ) { $ exists = false ; for ( $ j = 0 ; $ j < $ n ; $ j ++ ) { if ( $ this -> compare ( $ result [ $ j ] , $ this -> items [ $ i ] ) === 0 ) { $ exists = true ; break ; } } if ( ! $ exists ) { $ result [ ] = $ this -> items [ $ i ] ; $ n ++ ; } } } else if ( is_callable ( $ callback ) ) { $ n = 0 ; for ( $ i = 0 ; $ i < $ this -> len ; $ i ++ ) { $ exists = false ; for ( $ j = 0 ; $ j < $ n ; $ j ++ ) { if ( call_user_func ( $ callback , $ result [ $ j ] , $ this -> items [ $ i ] ) === 0 ) { $ exists = true ; break ; } } if ( ! $ exists ) { $ result [ ] = $ this -> items [ $ i ] ; $ n ++ ; } } } else { throw new \ browserfs \ Exception ( 'Invalid argument: $callback. Expected: function( any, any ): int | null' ) ; } return new self ( $ result ) ; } | Returns a collection with unique items . |
3,289 | private static function defaultCompareWrapper ( $ a , $ b ) { if ( $ a === $ b ) { return 0 ; } else { if ( is_string ( $ a ) ) { return strcmp ( $ a , $ b . '' ) ; } else if ( is_int ( $ a ) || is_float ( $ b ) ) { return ( float ) $ a - $ b ; } else return - 1 ; } } | A default compare function used by this generic collection |
3,290 | public function matchRequest ( \ TYPO3 \ Flow \ Mvc \ RequestInterface $ request ) { $ httpRequest = $ request -> getHttpRequest ( ) ; if ( $ httpRequest -> hasHeader ( 'X-Request-Signature' ) ) { $ identifierAndSignature = explode ( ':' , $ httpRequest -> getHeader ( 'X-Request-Signature' ) , 2 ) ; if ( count ( $ identifierAndSignature ) !== 2 ) { throw new \ TYPO3 \ Flow \ Exception ( 'Invalid signature header format, expected "identifier:base64(signature)"' , 1354287886 ) ; } $ identifier = $ identifierAndSignature [ 0 ] ; $ signature = base64_decode ( $ identifierAndSignature [ 1 ] ) ; $ signData = $ this -> requestSigner -> getSignatureContent ( $ httpRequest ) ; $ publicKeyFingerprint = $ this -> publicKeyResolver -> resolveFingerprintByIdentifier ( $ identifier ) ; if ( $ publicKeyFingerprint === NULL ) { throw new \ TYPO3 \ Flow \ Exception ( 'Cannot resolve identifier "' . $ identifier . '"' , 1354288898 ) ; } if ( $ this -> rsaWalletService -> verifySignature ( $ signData , $ signature , $ publicKeyFingerprint ) ) { return FALSE ; } else { $ this -> emitSignatureNotVerified ( $ request , $ identifier , $ signData , $ signature , $ publicKeyFingerprint ) ; } } else { $ this -> emitSignatureHeaderMissing ( $ request ) ; } return TRUE ; } | Matches the current request for an unverified signed request . |
3,291 | public function setTemplatesDirectory ( $ directory ) { $ this -> templatesDirectory = rtrim ( $ directory , DIRECTORY_SEPARATOR ) ; $ this -> engine -> setDirectory ( $ this -> getTemplatesDirectory ( ) ) ; } | Set the base directory that contains view templates |
3,292 | public function isAcceptable ( RequestInterface $ request ) { $ accept = $ request -> getHeaderLine ( 'Accept' ) ; if ( $ accept && preg_match ( '#^application/([^+\s]+\+)?json#' , $ accept ) ) { return true ; } return false ; } | Is the strategy acceptable for this request? |
3,293 | public function handleDevelopmentError ( SystemEvent $ systemEvent , $ exception ) { $ details = [ ] ; $ e = $ exception ; while ( $ e ) { $ item = [ 'class' => get_class ( $ exception ) , 'message' => $ exception -> getMessage ( ) , 'file' => $ exception -> getFile ( ) , 'line' => $ exception -> getLine ( ) , 'trace' => $ exception -> getTraceAsString ( ) , ] ; $ details [ ] = $ item ; $ e = $ e -> getPrevious ( ) ; } $ result = json_encode ( [ 'details' => $ details ] ) ; $ body = Stream :: make ( $ result ) ; $ status = 503 ; if ( $ exception instanceof ExceptionInterface && $ exception -> getCode ( ) ) { $ status = $ exception -> getCode ( ) ; } $ response = new Response ( $ status , $ body , [ 'Content-Type' => 'application/problem+json' ] ) ; $ this -> processResponse ( $ response , $ systemEvent ) ; } | Handles an error in development mode . |
3,294 | public static function v4FromData ( $ data ) { assert ( strlen ( $ data ) == 16 ) ; $ data [ 6 ] = chr ( ord ( $ data [ 6 ] ) & 0x0f | 0x40 ) ; $ data [ 8 ] = chr ( ord ( $ data [ 8 ] ) & 0x3f | 0x80 ) ; return vsprintf ( '%s%s-%s-%s-%s-%s%s%s' , str_split ( bin2hex ( $ data ) , 4 ) ) ; } | Generates a v4 UUID from data . |
3,295 | public static function forge ( $ config = 'default' , $ connect = true ) { $ ftp = new static ( $ config ) ; $ connect === true and $ ftp -> connect ( ) ; return $ ftp ; } | Returns a new Ftp object . If you do not define the file parameter |
3,296 | protected function _is_conn ( ) { if ( ! is_resource ( $ this -> _conn_id ) ) { if ( $ this -> _debug == true ) { throw new \ InvalidArgumentException ( 'Invalid connection' ) ; } return false ; } return true ; } | Validates the connection ID |
3,297 | public function upload ( $ local_path , $ remote_path , $ mode = 'auto' , $ permissions = null ) { if ( ! $ this -> _is_conn ( ) ) { return false ; } if ( ! is_file ( $ local_path ) ) { throw new \ FtpFileAccessException ( 'No source file' ) ; return false ; } if ( $ mode == 'auto' ) { $ ext = pathinfo ( $ local_path , PATHINFO_EXTENSION ) ; $ mode = $ this -> _settype ( $ ext ) ; } $ mode = ( $ mode == 'ascii' ) ? FTP_ASCII : FTP_BINARY ; $ result = @ ftp_put ( $ this -> _conn_id , $ remote_path , $ local_path , $ mode ) ; if ( $ result === false ) { if ( $ this -> _debug == true ) { throw new \ FtpFileAccessException ( 'Unable to upload' ) ; } return false ; } if ( $ permissions !== null ) { $ this -> chmod ( $ remote_path , ( int ) $ permissions ) ; } return true ; } | Upload a file to the server |
3,298 | public function download ( $ remote_path , $ local_path , $ mode = 'auto' ) { if ( ! $ this -> _is_conn ( ) ) { return false ; } if ( $ mode == 'auto' ) { $ ext = pathinfo ( $ remote_path , PATHINFO_BASENAME ) ; $ mode = $ this -> _settype ( $ ext ) ; } $ mode = ( $ mode == 'ascii' ) ? FTP_ASCII : FTP_BINARY ; $ result = @ ftp_get ( $ this -> _conn_id , $ local_path , $ remote_path , $ mode ) ; if ( $ result === false ) { if ( $ this -> _debug === true ) { throw new \ FtpFileAccessException ( 'Unable to download' ) ; } return false ; } return true ; } | Download a file from a remote server to the local server |
3,299 | public function mirror ( $ local_path , $ remote_path ) { if ( ! $ this -> _is_conn ( ) ) { return false ; } if ( $ fp = @ opendir ( $ local_path ) ) { if ( ! $ this -> change_dir ( $ remote_path , true ) ) { if ( ! $ this -> mkdir ( $ remote_path ) or ! $ this -> change_dir ( $ remote_path ) ) { return false ; } } while ( false !== ( $ file = readdir ( $ fp ) ) ) { if ( @ is_dir ( $ local_path . $ file ) and substr ( $ file , 0 , 1 ) != '.' ) { $ this -> mirror ( $ local_path . $ file . "/" , $ remote_path . $ file . "/" ) ; } elseif ( substr ( $ file , 0 , 1 ) != "." ) { $ ext = pathinfo ( $ file , PATHINFO_EXTENSION ) ; $ mode = $ this -> _settype ( $ ext ) ; $ this -> upload ( $ local_path . $ file , $ remote_path . $ file , $ mode ) ; } } return true ; } return false ; } | Read a directory and recreate it remotely |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.