idx
int64
0
60.3k
question
stringlengths
64
4.24k
target
stringlengths
5
618
3,400
private function flatten ( ? array $ arr , string $ group , ? string $ lang = null ) : ? array { if ( $ arr === null ) { return null ; } if ( ! isset ( $ this -> arrayGroups [ $ group ] ) ) { throw new \ OutOfBoundsException ( "Invalid group: $group" ) ; } if ( $ lang === null ) { $ lang = $ this -> lang ; } if ( ! isset ( $ this -> arrayGroups [ $ group ] [ $ lang ] ) ) { throw new \ OutOfBoundsException ( "Invalid language: $lang" ) ; } $ keep = $ this -> arrayGroups [ $ group ] [ $ lang ] ; if ( ! array_key_exists ( $ keep , $ arr ) ) { throw new \ OutOfBoundsException ( "Invalid array index: $keep" ) ; } $ arr [ $ group ] = $ arr [ $ keep ] ; foreach ( $ this -> arrayGroups [ $ group ] as $ g ) { unset ( $ arr [ $ g ] ) ; } return $ arr ; }
Flattens an array group
3,401
public function save ( ) { foreach ( $ this -> data as $ key => $ value ) { if ( ! empty ( $ value ) ) { $ this -> parametersStorage -> set ( $ key , $ value ) ; } else { $ this -> parametersStorage -> remove ( $ key ) ; } } }
Save current model in the storage
3,402
private function registerConfig ( ) { $ this -> getContainer ( ) [ Config :: CONTAINER_ID ] = function ( Container $ di ) { $ loader = $ di [ ConfigLoaderInterface :: CONTAINER_ID ] ; $ params = $ loader -> load ( ) ; $ config = new Config ( ) ; $ config -> setParams ( $ params ) ; return $ config ; } ; }
Register the config to the DI container
3,403
public function getRepository ( DocumentManager $ documentManager , $ modelName , $ collectionName , CacheProvider $ repositoryCache = null ) { $ repIndex = $ modelName . $ collectionName ; if ( false != ( $ repository = $ this -> cache -> fetch ( $ repIndex ) ) ) { return $ repository ; } $ classMetadata = $ this -> classMetadataFactory -> getMetadataForClass ( $ modelName ) ; if ( ! isset ( $ collectionName ) ) { $ collectionName = $ classMetadata -> getCollection ( ) ; } $ repositoryClass = $ classMetadata -> getRepositoryClass ( ) ; if ( is_a ( $ repositoryClass , "JPC\MongoDB\ODM\GridFS\Repository" , true ) && false === strstr ( $ collectionName , ".files" ) ) { $ bucketName = $ collectionName ; $ collectionName .= ".files" ; } else if ( is_a ( $ repositoryClass , "JPC\MongoDB\ODM\GridFS\Repository" , true ) && false !== strstr ( $ collectionName , ".files" ) ) { $ bucketName = strstr ( $ collectionName , ".files" , true ) ; } $ repIndex = $ modelName . $ collectionName ; if ( false != ( $ repository = $ this -> cache -> fetch ( $ repIndex ) ) ) { return $ repository ; } $ collection = $ this -> createCollection ( $ documentManager , $ classMetadata , $ collectionName ) ; $ hydratorClass = $ classMetadata -> getHydratorClass ( ) ; if ( ! isset ( $ hydratorClass ) ) { throw new \ Exception ( $ classMetadata -> getName ( ) . ' is not a valid model class. Maybe it doesn\'t have a "Document" annotation.' ) ; } $ hydrator = new $ hydratorClass ( $ this -> classMetadataFactory , $ classMetadata , $ documentManager , $ this ) ; $ queryCaster = new QueryCaster ( $ classMetadata , $ this -> classMetadataFactory ) ; if ( isset ( $ bucketName ) ) { $ bucket = $ documentManager -> getDatabase ( ) -> selectGridFSBucket ( [ "bucketName" => $ bucketName ] ) ; $ repository = new $ repositoryClass ( $ documentManager , $ collection , $ classMetadata , $ hydrator , $ queryCaster , null , $ repositoryCache , $ bucket ) ; } else { $ repository = new $ repositoryClass ( $ documentManager , $ collection , $ classMetadata , $ hydrator , $ queryCaster , null , $ repositoryCache ) ; } $ this -> cache -> save ( $ repIndex , $ repository , 120 ) ; return $ repository ; }
Get a repository
3,404
private function createCollection ( DocumentManager $ documentManager , ClassMetadata $ classMetadata , $ collectionName ) { $ database = $ documentManager -> getDatabase ( ) ; $ exists = false ; foreach ( $ database -> listCollections ( ) as $ collection ) { if ( $ collection -> getName ( ) == $ collectionName ) { $ exists = true ; } } $ creationOptions = $ classMetadata -> getCollectionCreationOptions ( ) ; if ( ! empty ( $ creationOptions ) && ! $ exists ) { $ database -> createCollection ( $ collectionName , $ creationOptions ) ; } $ collectionOptions = $ classMetadata -> getCollectionOptions ( ) ; return $ database -> selectCollection ( $ collectionName , $ collectionOptions ) ; }
Create the collection
3,405
protected function getOptions ( $ level ) { $ lineBreak = "\r\n" ; $ intendChar = "\t" ; $ intendNum = 1 ; $ baseIntend = str_repeat ( $ intendChar , $ intendNum * $ level ) ; $ nextIntend = str_repeat ( $ intendChar , $ intendNum * ( $ level + 1 ) ) ; $ extraLineBreak = ( $ level === 0 ? $ lineBreak : '' ) ; return [ "BaseAddComments" => true , "BaseLastDeclarationSemicolon" => true , "BaseIntend" => $ baseIntend , "CommentIntend" => $ baseIntend , "CommentLineBreak" => $ lineBreak , "CharsetLineBreak" => $ lineBreak , "DocumentFilterSeparator" => ", " , "DocumentRuleSetOpen" => " {" . $ lineBreak , "DocumentRuleSetClose" => $ baseIntend . "}" . $ lineBreak . $ extraLineBreak , "FontFaceCommentLineBreak" => $ lineBreak , "FontFaceRuleSetOpen" => " {" . $ lineBreak , "FontFaceRuleSetIntend" => str_repeat ( $ intendChar , $ intendNum ) , "FontFaceRuleSetClose" => $ baseIntend . "}" . $ lineBreak . $ extraLineBreak , "FontFaceDeclarationIntend" => $ nextIntend , "FontFaceDeclarationSeparator" => ": " , "FontFaceDeclarationLineBreak" => $ lineBreak , "ImportLineBreak" => $ lineBreak , "NamespaceLineBreak" => $ lineBreak , "MediaQuerySeparator" => ", " . $ lineBreak , "MediaRuleSetOpen" => " {" . $ lineBreak , "MediaRuleSetClose" => $ baseIntend . "}" . $ lineBreak . $ extraLineBreak , "PageCommentLineBreak" => $ lineBreak , "PageRuleSetOpen" => " {" . $ lineBreak , "PageRuleSetClose" => $ baseIntend . "}" . $ lineBreak . $ extraLineBreak , "PageDeclarationIntend" => $ nextIntend , "PageDeclarationSeparator" => ": " , "PageDeclarationLineBreak" => $ lineBreak , "SupportsRuleSetOpen" => " {" . $ lineBreak , "SupportsRuleSetClose" => $ baseIntend . "}" . $ lineBreak . $ extraLineBreak , "StyleCommentLineBreak" => $ lineBreak , "StyleDeclarationsOpen" => " {" . $ lineBreak , "StyleDeclarationsClose" => $ baseIntend . "}" . $ lineBreak . $ extraLineBreak , "StyleSelectorSeparator" => "," . $ lineBreak . $ baseIntend , "StyleDeclarationIntend" => $ nextIntend , "StyleDeclarationSeparator" => ": " , "StyleDeclarationLineBreak" => $ lineBreak , "KeyframesRuleSetOpen" => " {" . $ lineBreak , "KeyframesRuleSetClose" => $ baseIntend . "}" . $ lineBreak . $ extraLineBreak , "KeyframesSelectorSeparator" => "," . $ lineBreak . $ baseIntend , "KeyframesDeclarationsOpen" => " {" . $ lineBreak , "KeyframesDeclarationsClose" => $ baseIntend . "}" . $ lineBreak , "KeyframesDeclarationIntend" => $ nextIntend , "KeyframesDeclarationSeparator" => ": " , "KeyframesDeclarationLineBreak" => $ lineBreak , ] ; }
Gets the options for the CSS generation .
3,406
public function execute ( $ pipelineName = null ) { $ request = $ this -> requestFactory -> newIncomingRequest ( ) ; if ( $ this -> adaptor -> isDoublePass ( ) ) { $ response = $ this -> responseFactory -> newResponse ( ) ; } else { $ response = null ; } return $ this -> chain ( $ pipelineName , $ request , $ response ) ; }
Create and execute the named pipeline as an initial entry pipeline .
3,407
public function addMethodCall ( $ methodName ) { $ arguments = func_get_args ( ) ; array_shift ( $ arguments ) ; $ this -> methodCalls [ ] = new MethodCall ( $ methodName , $ arguments ) ; return $ this ; }
Set a method to be called after instantiating the class .
3,408
private function readNumber ( ) { if ( false === $ this -> handle = fopen ( $ this -> path , 'c+' ) ) { throw new RuntimeException ( "Failed to open file {$this->path}." ) ; } if ( ! flock ( $ this -> handle , LOCK_EX ) ) { throw new RuntimeException ( "Failed to lock file {$this->path}." ) ; } if ( false !== $ number = fread ( $ this -> handle , 10 ) ) { return intval ( $ number ) ; } return 0 ; }
Reads the previous number .
3,409
private function writeNumber ( $ number ) { if ( ! ftruncate ( $ this -> handle , 0 ) ) { throw new RuntimeException ( "Failed to truncate file {$this->path}." ) ; } if ( 0 > fseek ( $ this -> handle , 0 ) ) { throw new RuntimeException ( "Failed to move pointer at the beginning of the file {$this->path}." ) ; } if ( ! fwrite ( $ this -> handle , $ number ) ) { throw new RuntimeException ( "Failed to write file {$this->path}." ) ; } if ( ! fflush ( $ this -> handle ) ) { throw new RuntimeException ( "Failed to flush file {$this->path}." ) ; } if ( ! flock ( $ this -> handle , LOCK_UN ) ) { throw new RuntimeException ( "Failed to unlock file {$this->path}." ) ; } fclose ( $ this -> handle ) ; }
Writes the new number .
3,410
private function _output ( ) { $ output = \ wp_cache_get ( $ this -> key , $ this -> group ) ; if ( $ output !== false ) { echo $ output ; return true ; } ob_start ( ) ; return false ; }
Outputs cached content if available otherwise begins capturing output for caching .
3,411
private function _store ( ) { $ output = ob_get_flush ( ) ; \ wp_cache_add ( $ this -> key , $ output , $ this -> group , $ this -> expires ) ; }
Stores the rendered snippet in the object cache .
3,412
public static function extIs ( $ value ) { return static :: is ( $ value ) || ( is_string ( $ value ) && ( strval ( intval ( $ value ) ) === strval ( $ value ) ) ) ; }
Tests if the given value is an int or a string representation of an int .
3,413
public static function compare ( $ int1 , $ int2 ) { if ( ! static :: is ( $ int1 ) || ! static :: is ( $ int2 ) ) { throw new \ InvalidArgumentException ( "The \$int1 and \$int2 parameters must be of type int." ) ; } return ( $ int1 - $ int2 ) ; }
Compares two int values .
3,414
public static function random ( $ min = 0 , $ max = 1 , $ seed = null ) { if ( ! static :: is ( $ min ) || ! static :: is ( $ max ) ) { throw new \ InvalidArgumentException ( "The \$min and \$max parameters must be of type int." ) ; } if ( $ min > $ max ) { trigger_error ( "The \$min value cannot be greater than the \$max value." , E_USER_WARNING ) ; return false ; } if ( ! is_null ( $ seed ) && static :: is ( $ seed ) ) { mt_srand ( $ seed ) ; } $ rand = mt_rand ( $ min , $ max ) ; mt_srand ( ) ; return $ rand ; }
Generates a random integer number between min and max .
3,415
protected function registerApiHelper ( Application $ app ) { $ app -> singleton ( Factory :: class , function ( $ app ) { $ request = $ app [ 'request' ] ; $ config = $ app [ 'config' ] ; return new Factory ( $ request , $ config ) ; } ) ; $ app -> alias ( Factory :: class , 'apihelper' ) ; }
Register the helper class .
3,416
public static function autoCreateDirectory ( $ path_name ) { if ( ! File :: exists ( dirname ( $ path_name ) ) ) { $ isMadeDir = mkdir ( dirname ( $ path_name ) , 0777 , true ) ; if ( ! $ isMadeDir ) { return false ; } } return true ; }
auto create directory if not exists
3,417
public function getUser ( ConnectionInterface $ con = null ) { if ( $ this -> aUser === null && ( $ this -> user_id !== null ) ) { $ this -> aUser = ChildUserQuery :: create ( ) -> findPk ( $ this -> user_id , $ con ) ; } return $ this -> aUser ; }
Get the associated ChildUser object
3,418
public function getRole ( ConnectionInterface $ con = null ) { if ( $ this -> aRole === null && ( $ this -> role_id !== null ) ) { $ this -> aRole = ChildRoleQuery :: create ( ) -> findPk ( $ this -> role_id , $ con ) ; } return $ this -> aRole ; }
Get the associated ChildRole object
3,419
public function setOrderParameters ( $ idAttr , $ orderAttr , $ labelAttr ) { $ this -> orderParameters = [ 'idAttr' => $ idAttr , 'orderAttr' => $ orderAttr , 'labelAttr' => $ labelAttr ] ; return $ this ; }
Sets the Ordered list param .
3,420
private function setMapAction ( ) { array_push ( $ this -> actions , 'map' ) ; $ this -> addForm = array_diff ( $ this -> addForm , [ 'map_lat' , 'map_lng' , 'map_address' , 'map_province' , 'map_locality' , 'map_postal_code' ] ) ; $ this -> editForm = array_diff ( $ this -> addForm , [ 'map_lat' , 'map_lng' , 'map_address' , 'map_province' , 'map_locality' , 'map_postal_code' ] ) ; return $ this ; }
Set map action
3,421
private function setFileAction ( ) { array_push ( $ this -> actions , 'file' ) ; $ this -> addForm = array_diff ( $ this -> addForm , [ 'files' ] ) ; $ this -> editForm = array_diff ( $ this -> addForm , [ 'files' ] ) ; $ this -> setModelDefaults ( 'files' , [ ] ) ; $ this -> setColumnFormat ( 'files' , 'files' ) ; return $ this ; }
Set file action
3,422
public function getPhoto ( $ photoId ) { $ resource = '/photos/' . $ photoId ; $ response = $ this -> makeApiRequest ( $ resource ) ; return $ response -> photo ; }
Check a user to a photo and maybe to a event too .
3,423
public static function compare ( $ float1 , $ float2 ) { if ( ! static :: is ( $ float1 ) || ! static :: is ( $ float2 ) ) { throw new \ InvalidArgumentException ( "The \$float1 and \$float2 parameters must be of type float." ) ; } return ( $ float1 - $ float2 ) ; }
Compares two float values .
3,424
public static function random ( $ min = 0.0 , $ max = 1.0 , $ round = null , $ seed = null ) { if ( ! static :: is ( $ min ) || ! static :: is ( $ max ) ) { throw new \ InvalidArgumentException ( "The \$min and \$max parameters must be of type float." ) ; } if ( $ min > $ max ) { trigger_error ( "The \$min value cannot be greater than the \$max value." , E_USER_WARNING ) ; return false ; } ! is_null ( $ seed ) && Int :: is ( $ seed ) && mt_srand ( $ seed ) ; $ rand = $ min + ( ( ( mt_rand ( ) - 1 ) / mt_getrandmax ( ) ) * abs ( $ max - $ min ) ) ; ( ! is_null ( $ round ) && Int :: is ( $ round ) && $ round > 0 ) && ( $ rand = round ( $ rand , $ round ) ) ; mt_srand ( ) ; return $ rand ; }
Generates a random float number between min and max .
3,425
private function setColour ( $ colour ) { if ( ! in_array ( $ colour , $ this -> getDefaultColours ( ) ) && ! preg_match ( '_^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$_' , $ colour ) ) { throw new InvalidColourException ( sprintf ( 'The colour "%s" is not a valid colour. Possible options are "%s" or a valid hex colour' , $ colour , implode ( '", "' , $ this -> getDefaultColours ( ) ) ) ) ; } $ this -> colour = $ colour ; }
Set the colour if it is a valid colour .
3,426
public function request ( string $ request_uri = null , string $ request_method = 'GET' , array $ args = [ ] , array $ cookie = [ ] ) { self :: $ core -> deinit ( ) -> reset ( ) ; self :: $ core -> config ( 'home' , '/' ) ; $ _SERVER [ 'REQUEST_URI' ] = $ request_uri ? $ request_uri : '/' ; $ _SERVER [ 'REQUEST_METHOD' ] = $ request_method ; $ _COOKIE = $ cookie ; if ( $ args ) self :: $ core -> override_callback_args ( $ args ) ; return self :: $ core ; }
Fake request .
3,427
private function prepareLogsDir ( $ logsDir ) { if ( ! is_dir ( $ logsDir ) ) { if ( false === @ mkdir ( $ logsDir , 0777 , true ) && ! is_dir ( $ logsDir ) ) { throw new \ RuntimeException ( sprintf ( "Unable to create the logs directory (%s)\n" , $ logsDir ) ) ; } } elseif ( ! is_writable ( $ logsDir ) ) { throw new \ RuntimeException ( sprintf ( "Unable to write in the logs directory (%s)\n" , $ logsDir ) ) ; } }
Create logs dir if does not exist .
3,428
public function _before ( TestInterface $ test ) { if ( $ this -> config [ 'reconnect' ] ) { $ this -> connect ( ) ; } $ this -> removeInserted ( ) ; parent :: _before ( $ test ) ; }
Code to run before each test
3,429
public function _after ( TestInterface $ test ) { if ( $ this -> config [ 'reconnect' ] ) { $ this -> disconnect ( ) ; } parent :: _after ( $ test ) ; }
Code to run after each test
3,430
public function grabValueFromAerospike ( $ key ) { $ akey = $ this -> buildKey ( $ key ) ; $ status = $ this -> aerospike -> get ( $ akey , $ data ) ; if ( $ status != \ Aerospike :: OK ) { $ this -> fail ( strtr ( "[:errno:] Unable to grab ':key:' from the database: :error:" , [ ':errno:' => $ this -> aerospike -> errorno ( ) , ':key:' => $ key , ':error:' => $ this -> aerospike -> error ( ) ] ) ) ; } $ this -> debugSection ( 'Value' , $ data [ 'bins' ] [ 'value' ] ) ; return $ data [ 'bins' ] [ 'value' ] ; }
Grabs value from Aerospike by key .
3,431
public function seeInAerospike ( $ key , $ value = false ) { $ akey = $ this -> buildKey ( $ key ) ; $ status = $ this -> aerospike -> get ( $ akey , $ actual ) ; if ( $ status != \ Aerospike :: OK ) { $ this -> fail ( strtr ( "[:errno:] Unable to get ':key:' from the database: :error:" , [ ':errno:' => $ this -> aerospike -> errorno ( ) , ':key:' => $ key , ':error:' => $ this -> aerospike -> error ( ) ] ) ) ; } $ this -> debugSection ( 'Value' , $ actual [ 'bins' ] [ 'value' ] ) ; $ this -> assertEquals ( $ value , $ actual [ 'bins' ] [ 'value' ] ) ; }
Checks item in Aerospike exists and the same as expected .
3,432
public function dontSeeInAerospike ( $ key , $ value = false ) { $ akey = $ this -> buildKey ( $ key ) ; if ( $ value === false ) { $ status = $ this -> aerospike -> get ( $ akey , $ record ) ; $ this -> assertSame ( \ Aerospike :: ERR_RECORD_NOT_FOUND , $ status ) ; return ; } $ this -> aerospike -> get ( $ akey , $ actual ) ; if ( isset ( $ actual [ 'bins' ] [ 'value' ] ) ) { $ actual = $ actual [ 'bins' ] [ 'value' ] ; } $ this -> debugSection ( 'Value' , $ actual ) ; $ this -> assertNotEquals ( $ value , $ actual ) ; }
Checks item in Aerospike does not exist or is the same as expected .
3,433
public function haveInAerospike ( $ key , $ value , $ ttl = 0 ) { $ akey = $ this -> buildKey ( $ key ) ; $ bins = [ 'value' => $ value ] ; $ status = $ this -> aerospike -> put ( $ akey , $ bins , $ ttl , [ \ Aerospike :: OPT_POLICY_KEY => \ Aerospike :: POLICY_KEY_SEND ] ) ; if ( $ status != \ Aerospike :: OK ) { $ this -> fail ( strtr ( "[:errno:] Unable to store ':key:' to the database: :error:" , [ ':errno:' => $ this -> aerospike -> errorno ( ) , ':key:' => $ key , ':error:' => $ this -> aerospike -> error ( ) ] ) ) ; } $ this -> keys [ ] = $ akey ; $ this -> debugSection ( 'Aerospike' , [ $ key , $ value ] ) ; return $ akey ; }
Inserts data into Aerospike database .
3,434
protected function buildKey ( $ key ) { return $ this -> aerospike -> initKey ( $ this -> config [ 'namespace' ] , $ this -> config [ 'set' ] , $ this -> config [ 'prefix' ] . $ key ) ; }
Generates a unique key used for storing cache in Aerospike DB .
3,435
public function file_permissions ( $ file ) { $ numeric_perms = fileperms ( $ file ) ; $ octal_perms = sprintf ( '%o' , $ numeric_perms ) ; return substr ( $ octal_perms , - 4 ) ; }
Returns the file permissions in octal format .
3,436
protected function arbitrate ( NumericTypeInterface $ a , NumericTypeInterface $ b ) { $ pairing = $ this -> getTypePairing ( $ a , $ b ) ; if ( $ pairing == 'complex:complex' ) { return 'complex' ; } if ( strpos ( $ pairing , 'complex' ) === 0 ) { return 'complex:numeric' ; } if ( strpos ( $ pairing , 'complex' ) !== false ) { return 'numeric:complex' ; } if ( strstr ( $ pairing , 'rational' ) !== false ) { return 'rational' ; } if ( strstr ( $ pairing , 'float' ) !== false ) { return 'float' ; } if ( strstr ( $ pairing , 'wholeint' ) !== false ) { return 'whole' ; } if ( strstr ( $ pairing , 'naturalint' ) !== false ) { return 'natural' ; } if ( $ pairing == 'int:int' ) { return 'int' ; } }
Arbitrate the return type from the operation
3,437
private function getTypePairing ( NumericTypeInterface $ a , NumericTypeInterface $ b ) { $ search = [ 'Chippyash\Type\Number\Rational\\' , 'Chippyash\Type\Number\Complex\\' , 'Chippyash\Type\Number\\' , 'Type' ] ; $ replace = [ '' , '' , '' , '' ] ; $ tA = strtolower ( str_replace ( $ search , $ replace , get_class ( $ a ) ) ) ; $ tB = strtolower ( str_replace ( $ search , $ replace , get_class ( $ b ) ) ) ; return "{$tA}:{$tB}" ; }
Work out the type of the number pairs
3,438
public static function render ( Query \ Insert $ query ) { return Compiler :: withDb ( $ query -> getDb ( ) , function ( ) use ( $ query ) { $ table = $ query -> getTable ( ) ; $ select = $ query -> getSelect ( ) ; return Compiler :: expression ( array ( 'INSERT' , $ query -> getType ( ) , Compiler :: word ( 'INTO' , $ table !== null ? Aliased :: render ( $ table ) : null ) , Columns :: render ( $ query -> getColumns ( ) ) , Compiler :: word ( 'VALUES' , Values :: combine ( $ query -> getValues ( ) ) ) , Compiler :: word ( 'SET' , Set :: combine ( $ query -> getSet ( ) ) ) , $ select !== null ? Select :: render ( $ select ) : null , ) ) ; } ) ; }
Render a Insert object
3,439
public function binaryUuid ( $ column = 'id' , $ primary = true ) { $ column = $ this -> addColumn ( 'binaryuuid' , $ column , [ 'length' => 16 ] ) ; if ( $ primary ) { $ column -> primary ( ) ; } return $ column ; }
Ajoute une column de type binary UUID
3,440
public function stringId ( $ column = 'id' , $ size = 32 , $ primary = true ) { $ column = $ this -> string ( $ column , $ size ) ; if ( $ primary ) { $ column -> primary ( ) ; } return $ column ; }
Ajoute une colonne id de type string
3,441
public function getDirectoryTreeList ( ) { $ finder = new Finder ( ) ; $ finder -> in ( $ this -> rootPath ) -> directories ( ) ; $ directories = array ( ) ; $ rootFinder = new Finder ( ) ; $ rootFinder -> in ( $ this -> rootPath ) -> depth ( 0 ) ; $ directories [ ] = new Directory ( $ this -> virtualRootPath , $ rootFinder -> directories ( ) -> count ( ) , $ rootFinder -> files ( ) -> count ( ) ) ; foreach ( $ finder as $ dir ) { $ dirFinder = new Finder ( ) ; $ dirFinder -> in ( $ dir -> getPathname ( ) ) -> depth ( 0 ) ; $ virtualAbsolutePath = substr ( $ this -> fs -> makePathRelative ( $ dir -> getPathname ( ) , $ this -> rootPath ) , 0 , - 1 ) ; $ directories [ ] = new Directory ( $ this -> virtualRootPath . '/' . $ virtualAbsolutePath , $ dirFinder -> files ( ) -> count ( ) , $ dirFinder -> directories ( ) -> count ( ) ) ; } return $ directories ; }
Return the directory tree in the form of a list
3,442
private function getRealPath ( $ path ) { if ( strpos ( $ path , '../' ) !== false ) { throw new AccessDeniedException ( 'Path cannot contain "../" pattern' ) ; } return str_replace ( $ this -> virtualRootPath , $ this -> rootPath , $ path ) ; }
Return local path from remote query
3,443
public function routeSave ( MvcEvent $ event ) { $ match = $ event -> getRouteMatch ( ) ; if ( ! $ match ) { return ; } if ( $ event -> getParam ( 'route-cached' ) || ! $ event -> getParam ( 'route-cacheable' ) ) { return ; } $ path = $ event -> getRequest ( ) -> getUri ( ) -> getPath ( ) ; $ cache = $ event -> getApplication ( ) -> getServiceManager ( ) -> get ( 'var-cache' ) ; $ cacheKey = $ this -> getCacheKey ( $ path ) ; $ data = array ( 'name' => $ event -> getRouteMatch ( ) -> getMatchedRouteName ( ) , 'route' => $ path , 'defaults' => $ event -> getRouteMatch ( ) -> getParams ( ) , ) ; $ cache -> setItem ( $ cacheKey , $ data ) ; }
Method that tries to save a route match into a cache system
3,444
public function find ( $ id ) { return new self ( $ this -> _user , self :: get ( $ this -> _user , $ id ) ) ; }
Class method to find a Subscription
3,445
public function findAll ( $ page = 1 , $ per_page = 20 , $ order_by = self :: ORDERBY_CREATED_AT , $ order_dir = self :: ORDERDIR_ASC ) { $ results = self :: getAll ( $ this -> _user , $ page , $ per_page , $ order_by , $ order_dir ) ; if ( isset ( $ results [ 'subscriptions' ] ) ) { $ results = $ results [ 'subscriptions' ] ; } $ retval = array ( ) ; foreach ( $ results as $ pylon ) { $ retval [ ] = new self ( $ this -> _user , $ pylon ) ; } return $ retval ; }
Class method to find all Subscriptions
3,446
public static function get ( $ user , $ id = false ) { $ params = array ( ) ; if ( $ id ) { $ params [ 'id' ] = $ id ; } return $ user -> get ( 'pylon/get' , $ params ) ; }
Get an existing recordings .
3,447
private function load ( $ data ) { if ( empty ( $ data ) ) { throw new DataSift_Exception_InvalidData ( 'No data found' ) ; } foreach ( $ data as $ key => $ value ) { $ this -> { '_' . $ key } = $ value ; } }
Loads an pylon object from the get data
3,448
public function reload ( ) { if ( strlen ( $ this -> _id ) == 0 ) { throw new DataSift_Exception_InvalidData ( 'Unable to reload pylon without an ID' ) ; } $ this -> load ( self :: get ( $ this -> _user , $ this -> _id ) ) ; }
Updates the object with fresh results from get
3,449
public function compile ( $ csdl = false ) { if ( $ csdl ) { $ this -> _csdl = $ csdl ; } if ( strlen ( $ this -> _csdl ) == 0 ) { throw new DataSift_Exception_InvalidData ( 'Cannot compile an empty definition.' ) ; } $ res = $ this -> _user -> post ( 'pylon/compile' , array ( 'csdl' => $ this -> _csdl ) ) ; $ this -> _hash = $ res [ 'hash' ] ; return $ res ; }
Compiles the CSDL of this object
3,450
public function start ( $ hash = false , $ name = false ) { if ( $ hash ) { $ this -> _hash = $ hash ; } if ( $ name ) { $ this -> _name = $ name ; } if ( ! empty ( $ this -> _id ) ) { $ this -> restart ( ) ; } else { $ this -> create ( ) ; } }
Creates a new recording or restarts an existing one if an ID is present
3,451
public function restart ( $ id = false ) { if ( $ id ) { $ this -> _id = $ id ; } $ this -> _user -> put ( 'pylon/start' , array ( 'id' => $ this -> _id ) ) ; }
Restarts the pylon recording
3,452
public function stop ( $ id = false ) { if ( $ id ) { $ this -> _id = $ id ; } if ( strlen ( $ this -> _id ) == 0 ) { throw new DataSift_Exception_InvalidData ( 'Unable to reload pylon without an ID' ) ; } $ this -> _user -> post ( 'pylon/stop' , array ( 'id' => $ this -> _id ) ) ; }
Stops the pylon recording
3,453
public function analyze ( $ parameters , $ filter = false , $ start = false , $ end = false , $ id = false ) { if ( $ id ) { $ this -> _id = $ id ; } if ( ! is_array ( $ parameters ) ) { $ parameters = json_decode ( $ parameters ) ; } if ( empty ( $ parameters ) ) { throw new DataSift_Exception_InvalidData ( 'Parameters must be supplied as an array or valid JSON' ) ; } $ params = array ( 'id' => $ this -> _id , 'parameters' => $ parameters ) ; if ( $ filter ) { $ params [ 'filter' ] = $ filter ; } if ( $ start ) { $ params [ 'start' ] = $ start ; } if ( $ end ) { $ params [ 'end' ] = $ end ; } return $ this -> _user -> post ( 'pylon/analyze' , $ params ) ; }
Analyze the recording
3,454
public function tags ( $ id = false ) { if ( $ id ) { $ this -> _id = $ id ; } if ( strlen ( $ this -> _id ) == 0 ) { throw new DataSift_Exception_InvalidData ( 'Unable to get tags without an ID' ) ; } return $ this -> _user -> get ( 'pylon/tags' , array ( 'id' => $ this -> _id ) ) ; }
Analyze the tags in the data set
3,455
public function update ( $ id = false , $ hash = false , $ name = false ) { if ( $ id ) { $ this -> _id = $ id ; } if ( $ hash ) { $ this -> _hash = $ hash ; } if ( $ name ) { $ this -> _name = $ name ; } $ params = array ( 'id' => $ this -> _id , 'hash' => $ this -> _hash , 'name' => $ this -> _name ) ; $ this -> _user -> put ( 'pylon/update' , $ params ) ; }
Updates a recording with a new hash and or name
3,456
public function applyRequestQueryParams ( AbstractPaginator $ paginator ) { foreach ( array_except ( Request :: instance ( ) -> query -> all ( ) , [ self :: PAGINATION_CURRENT_PAGE , self :: PAGINATION_PER_PAGE ] ) as $ key => $ value ) { $ paginator -> addQuery ( $ key , $ value ) ; } $ paginator -> addQuery ( self :: PAGINATION_PER_PAGE , $ paginator -> perPage ( ) ) ; }
Find all the query parameters passed in the request and apply them to the paginator so we can build a useful URL .
3,457
protected function checkCache ( $ name ) { if ( ! isset ( $ this -> cache [ $ name ] ) ) { try { $ config = $ this -> db -> from ( $ this -> table ) -> where ( $ this -> columns [ 'name' ] ) -> eq ( $ name ) -> select ( ) -> fetchAssoc ( ) -> first ( ) ; if ( ! $ config ) { return false ; } $ this -> cache [ $ name ] = new ArrayHelper ( unserialize ( $ config [ $ this -> columns [ 'data' ] ] ) ) ; } catch ( PDOException $ e ) { return false ; } } return true ; }
Check if an item was cached
3,458
public function write ( $ name , $ value ) { $ path = explode ( '.' , $ name ) ; $ key = array_shift ( $ path ) ; $ exists = $ this -> checkCache ( $ key ) ; if ( $ path ) { if ( ! $ exists ) { $ this -> cache [ $ key ] = new ArrayHelper ( ) ; } $ this -> cache [ $ key ] -> set ( $ path , $ value ) ; } else { $ this -> cache [ $ key ] = new ArrayHelper ( $ value ) ; } return $ exists ? $ this -> updateRecord ( $ key ) : $ this -> insertRecord ( $ key ) ; }
Write config data
3,459
public function read ( $ name , $ default = null ) { $ path = explode ( '.' , $ name ) ; $ key = array_shift ( $ path ) ; if ( $ this -> checkCache ( $ key ) ) { return $ path ? $ this -> cache [ $ key ] -> get ( $ path , $ default ) : $ this -> cache [ $ key ] -> toArray ( ) ; } return $ default ; }
Read config data
3,460
public function has ( $ name ) { $ path = explode ( '.' , $ name ) ; $ key = array_shift ( $ path ) ; if ( $ this -> checkCache ( $ key ) ) { return $ path ? $ this -> cache [ $ key ] -> has ( $ path ) : true ; } return false ; }
Check if the config exists
3,461
public function delete ( $ name ) { $ path = explode ( '.' , $ name ) ; $ key = array_shift ( $ path ) ; if ( $ path ) { if ( $ this -> checkCache ( $ key ) && $ this -> cache [ $ key ] -> delete ( $ path ) ) { return $ this -> updateRecord ( $ key ) ; } return false ; } unset ( $ this -> cache [ $ key ] ) ; return $ this -> deleteRecord ( $ key ) ; }
Delete a config
3,462
public function params ( ... $ params ) : self { $ this -> params = $ params ; array_push ( $ this -> params , $ this -> event ) ; return $ this ; }
All arguments passed to this method will be forwarded to callback functions of all listeners
3,463
public function cachedData ( ) { if ( ! $ this -> isCached ( ) ) { return null ; } $ contents = file_get_contents ( $ this -> file ) ; $ serializationEnabled = static :: config ( 'serialize' ) ; $ data = $ serializationEnabled ? unserialize ( $ contents ) : $ contents ; return $ data ; }
Retrieves the cached data that is refered by this object
3,464
public static function clearAll ( ) { $ dir = new \ DirectoryIterator ( static :: config ( 'directory' ) ) ; foreach ( $ dir as $ fileinfo ) { if ( $ fileinfo -> isFile ( ) ) { $ cacheKey = $ fileinfo -> getFilename ( ) ; static :: clear ( $ cacheKey ) ; } } }
Clear all the cache data stored in the cache directory
3,465
public static function countAll ( ) { $ count = 0 ; $ dir = new \ DirectoryIterator ( static :: config ( 'directory' ) ) ; foreach ( $ dir as $ fileinfo ) { if ( $ fileinfo -> isFile ( ) ) { $ count ++ ; } } return $ count ; }
Returns the total number of unique cached data
3,466
public static function slugify ( $ text , $ lowercase = true , $ skip_chars = '' ) { $ text = preg_replace ( '~[^\\pL\d' . $ skip_chars . ']+~u' , '-' , $ text ) ; $ text = trim ( $ text , '-' ) ; $ text = iconv ( 'utf-8' , 'us-ascii//TRANSLIT' , $ text ) ; if ( $ lowercase ) $ text = strtolower ( $ text ) ; $ text = preg_replace ( '~[^-\w' . $ skip_chars . ']+~' , '' , $ text ) ; if ( empty ( $ text ) ) { return 'n-a' ; } return $ text ; }
Convert a string to friendly SEO string
3,467
public static function set_values ( $ defaults , $ values , $ default_key = "" ) { if ( $ default_key != "" ) { if ( ! is_array ( $ values ) ) { if ( isset ( $ defaults [ $ default_key ] ) ) $ defaults [ $ default_key ] = $ values ; return $ defaults ; } } if ( $ values ) { foreach ( $ values as $ key => $ value ) { if ( array_key_exists ( $ key , $ defaults ) ) $ defaults [ $ key ] = $ value ; } } return $ defaults ; }
Set values from default properties of an array
3,468
public static function read_csv ( $ filename , $ with_header = true , $ headers = null , $ delimiter = ',' ) { $ data = [ ] ; $ index = 0 ; $ header_count = $ headers ? count ( $ headers ) : 0 ; $ handle = @ fopen ( $ filename , "r" ) or false ; if ( $ handle !== FALSE ) { while ( ( $ row = fgetcsv ( $ handle , 0 , $ delimiter ) ) !== FALSE ) { if ( $ index == 0 && $ with_header ) { if ( ! $ headers ) $ headers = $ row ; $ header_count = count ( $ headers ) ; } else { if ( $ headers ) { $ column_count = count ( $ row ) ; if ( $ header_count > $ column_count ) { $ row = array_merge ( $ row , array_fill_keys ( range ( $ column_count , $ header_count - 1 ) , null ) ) ; } else if ( $ header_count < $ column_count ) { $ extracted = array_splice ( $ row , $ header_count ) ; $ row [ $ header_count - 1 ] = $ row [ $ header_count - 1 ] . '|' . implode ( '|' , $ extracted ) ; trigger_error ( 'read_csv: row ' . $ index . ' column mismatch. headers: ' . $ header_count . ', columns: ' . $ column_count ) ; } $ data [ ] = array_combine ( $ headers , $ row ) ; } else { $ data [ ] = $ row ; } } $ index ++ ; } fclose ( $ handle ) ; } return $ data ; }
Read CSV from URL or File
3,469
public static function parse_email ( $ str , $ separator = "," ) { $ str = trim ( preg_replace ( '/\s+/' , ' ' , $ str ) ) ; $ all = [ ] ; $ emails = preg_split ( '/(".*?"\s*<.+?>)\s*' . $ separator . '*|' . $ separator . '+/' , $ str , - 1 , PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY ) ; foreach ( $ emails as $ email ) { $ name = "" ; $ email = trim ( $ email ) ; $ email_info = new stdClass ; if ( preg_match ( '/(.*?)<(.*)>/' , $ email , $ regs ) ) { $ email_info -> name = trim ( trim ( $ regs [ 1 ] ) , '"' ) ; $ email_info -> email = trim ( $ regs [ 2 ] ) ; } else { $ email_info -> name = $ email ; $ email_info -> email = $ email ; } if ( strpos ( $ email_info -> email , $ separator ) !== false ) { $ addtl_emails = parse_email ( $ email_info -> email , $ separator ) ; foreach ( $ addtl_emails as $ addtl_email_info ) { if ( $ addtl_email_info -> name == "" || $ addtl_email_info -> name == $ addtl_email_info -> email ) $ addtl_email_info -> name = $ email_info -> name ; $ all [ ] = $ addtl_email_info ; } } else { if ( filter_var ( $ email_info -> email , FILTER_VALIDATE_EMAIL ) ) $ all [ ] = $ email_info ; } } return $ all ; }
Parse email address string
3,470
public static function get_session_info ( ) { $ browser_info = get_browser_info ( ) ; $ result = new stdClass ; $ result -> ip = get_client_ip ( ) ; $ result -> browser_info = ( object ) $ browser_info ; return $ result ; }
Store client session info to an object
3,471
public static function get_client_ip ( ) { $ ipaddress = '' ; if ( getenv ( 'HTTP_CLIENT_IP' ) ) $ ipaddress = getenv ( 'HTTP_CLIENT_IP' ) ; else if ( getenv ( 'HTTP_X_FORWARDED_FOR' ) ) $ ipaddress = getenv ( 'HTTP_X_FORWARDED_FOR' ) ; else if ( getenv ( 'HTTP_X_FORWARDED' ) ) $ ipaddress = getenv ( 'HTTP_X_FORWARDED' ) ; else if ( getenv ( 'HTTP_FORWARDED_FOR' ) ) $ ipaddress = getenv ( 'HTTP_FORWARDED_FOR' ) ; else if ( getenv ( 'HTTP_FORWARDED' ) ) $ ipaddress = getenv ( 'HTTP_FORWARDED' ) ; else if ( getenv ( 'REMOTE_ADDR' ) ) $ ipaddress = getenv ( 'REMOTE_ADDR' ) ; else $ ipaddress = 'UNKNOWN' ; return $ ipaddress ; }
Get the client s IP Address
3,472
public static function get_browser_info ( ) { $ u_agent = isset ( $ _SERVER [ 'HTTP_USER_AGENT' ] ) ? $ _SERVER [ 'HTTP_USER_AGENT' ] : 'UNKNOWN' ; $ bname = 'Unknown' ; $ platform = 'Unknown' ; $ ub = 'Unknown' ; $ version = "" ; if ( preg_match ( '/linux/i' , $ u_agent ) ) { $ platform = 'linux' ; } elseif ( preg_match ( '/macintosh|mac os x/i' , $ u_agent ) ) { $ platform = 'mac' ; } elseif ( preg_match ( '/windows|win32/i' , $ u_agent ) ) { $ platform = 'windows' ; } if ( preg_match ( '/MSIE/i' , $ u_agent ) && ! preg_match ( '/Opera/i' , $ u_agent ) ) { $ bname = 'Internet Explorer' ; $ ub = "MSIE" ; } elseif ( preg_match ( '/Firefox/i' , $ u_agent ) ) { $ bname = 'Mozilla Firefox' ; $ ub = "Firefox" ; } elseif ( preg_match ( '/Chrome/i' , $ u_agent ) ) { $ bname = 'Google Chrome' ; $ ub = "Chrome" ; } elseif ( preg_match ( '/Safari/i' , $ u_agent ) ) { $ bname = 'Apple Safari' ; $ ub = "Safari" ; } elseif ( preg_match ( '/Opera/i' , $ u_agent ) ) { $ bname = 'Opera' ; $ ub = "Opera" ; } elseif ( preg_match ( '/Netscape/i' , $ u_agent ) ) { $ bname = 'Netscape' ; $ ub = "Netscape" ; } $ known = [ 'Version' , $ ub , 'other' ] ; $ pattern = '#(?<browser>' . join ( '|' , $ known ) . ')[/ ]+(?<version>[0-9.|a-zA-Z.]*)#' ; if ( ! preg_match_all ( $ pattern , $ u_agent , $ matches ) ) { } else { $ i = count ( $ matches [ 'browser' ] ) ; if ( $ i != 1 ) { if ( strripos ( $ u_agent , "Version" ) < strripos ( $ u_agent , $ ub ) ) { $ version = $ matches [ 'version' ] [ 0 ] ; } else { $ version = $ matches [ 'version' ] [ 1 ] ; } } else { $ version = $ matches [ 'version' ] [ 0 ] ; } } if ( $ version == null || $ version == "" ) { $ version = "?" ; } return [ 'user_agent' => $ u_agent , 'name' => $ bname , 'version' => $ version , 'platform' => $ platform , 'pattern' => $ pattern ] ; }
Get your browser s info
3,473
public static function encrypt ( $ data , $ key , $ iv ) { $ output = false ; $ encrypt_method = "AES-256-CBC" ; $ key = hash_hmac ( 'sha256' , $ data , $ iv ) ; $ iv = substr ( $ iv , 0 , 16 ) ; $ output = openssl_encrypt ( $ data , $ encrypt_method , $ key , 0 , $ iv ) ; $ output = base64_encode ( $ output ) ; return $ output ; }
Returns an base64 encoded encrypted string
3,474
public static function decrypt ( $ data , $ key , $ iv ) { $ output = false ; $ encrypt_method = "AES-256-CBC" ; $ key = hash_hmac ( 'sha256' , $ data , $ iv ) ; $ iv = substr ( $ iv , 0 , 16 ) ; $ output = openssl_decrypt ( base64_decode ( $ data ) , $ encrypt_method , $ key , 0 , $ iv ) ; return $ output ; }
Returns decrypted original string
3,475
public static function to_array ( $ object ) { if ( is_array ( $ object ) ) return $ object ; if ( ! is_object ( $ object ) && ! is_array ( $ object ) ) return $ object ; if ( is_object ( $ object ) ) $ object = get_object_vars ( $ object ) ; return array_map ( [ __CLASS__ , 'to_array' ] , $ object ) ; }
Convert an object to an array
3,476
public static function zip ( $ files = [ ] , $ destination = '' , $ overwrite = false ) { if ( file_exists ( $ destination ) && ! $ overwrite ) { return false ; } $ valid_files = [ ] ; $ files = is_array ( $ files ) ? $ files : [ $ files ] ; if ( $ files ) { foreach ( $ files as $ filename => $ file ) { if ( file_exists ( $ file ) ) { if ( is_int ( $ filename ) ) $ filename = basename ( $ file ) ; $ valid_files [ $ filename ] = $ file ; } } } if ( count ( $ valid_files ) ) { $ zip = new \ ZipArchive ( ) ; if ( $ zip -> open ( $ destination , \ ZipArchive :: OVERWRITE | \ ZipArchive :: CREATE ) !== true ) { return false ; } foreach ( $ valid_files as $ filename => $ file ) { $ zip -> addFile ( $ file , $ filename ) ; } $ zip -> close ( ) ; return file_exists ( $ destination ) ; } else { return false ; } }
Create a compressed zip file
3,477
public function init ( ) { $ this -> version = $ this -> read ( true ) ; if ( ! $ this -> login ( ) ) return false ; return true ; }
Initializes Connection and Log s In
3,478
public function connect ( & $ cn = 1 , & $ cs = "Unknown error" ) { $ fp = fsockopen ( $ this -> ip , $ this -> port , $ cn , $ cs , 3 ) or die ( "Could not connect. " . date ( "Y-m-d H:i:s" ) . PHP_EOL ) ; if ( ! $ fp ) { return false ; } else { self :: $ socket = $ fp ; return true ; } }
Connect with server
3,479
protected function login ( ) { return $ this -> query ( 'login ' . md5 ( substr ( $ this -> read ( true ) , 17 ) . $ this -> pwd ) ) == 'Authentication successful, rcon ready.' ; }
Tries to Login
3,480
public static function query ( $ line , $ bare = false ) { self :: write ( $ line , $ bare ) ; if ( strpos ( $ result = self :: read ( $ bare ) , 'rcon: unknown command:' ) === 0 ) return false ; return $ result ; }
Executes a Query on the Server
3,481
protected static function read ( $ bare = false ) { $ delim = $ bare ? "\n" : "\x04" ; for ( $ buffer = '' ; ( $ char = fgetc ( self :: $ socket ) ) != $ delim ; $ buffer .= $ char ) ; return trim ( $ buffer ) ; }
Reads the Buffer
3,482
private function cleanOrderBy ( $ table , $ orderBy ) { if ( ! empty ( $ orderBy ) ) { $ orderByArray = explode ( ',' , $ orderBy ) ; foreach ( $ orderByArray as $ k => $ order ) { $ orderByArray [ $ k ] = $ table . '.' . $ order ; } $ orderBy = implode ( ',' , $ orderByArray ) ; } return $ orderBy ; }
Cleans order by clause
3,483
protected function mergeRecords ( array $ records ) { foreach ( $ records as $ key => $ record ) { if ( null === $ id = array_get ( $ record , static :: ID_FIELD ) ) { throw new InternalServerErrorException ( 'No ' . static :: ID_FIELD . ' field found in supplied record(s). Cannot merge record(s) for PATCH operation.' ) ; } $ rs = $ this -> getConnection ( ) -> getDocument ( $ this -> transactionTable , $ id ) ; $ record = array_merge ( $ rs , $ record ) ; $ records [ $ key ] = $ record ; } return $ records ; }
Merges new record with existing record to perform PATCH operation
3,484
public static function getProperty ( $ object , string $ propertyName ) { $ reflection = new \ ReflectionObject ( $ object ) ; $ property = $ reflection -> getProperty ( $ propertyName ) ; $ property -> setAccessible ( true ) ; return $ property -> getValue ( $ object ) ; }
Reads also private and protected properties
3,485
public function parse ( $ pattern ) { $ lexer = $ this -> createLexer ( ) ; try { $ result = $ lexer -> lex ( $ pattern ) ; } catch ( LexingException $ e ) { $ message = sprintf ( 'Lexing failed with error: %s' , $ e -> getMessage ( ) ) ; throw new TokenizeException ( $ message , 0 , $ e ) ; } if ( $ lexer -> hasPushedStates ( ) ) { throw new TokenizeException ( 'Premature end of pattern' ) ; } return $ result ; }
Parses the pattern to produce an array of token identifiers .
3,486
protected function createInitialDefinition ( ) { return [ '[^\\\\*\[?]+(?:\\\\.[^\\\\*\[?]*)*|(?:\\\\.[^\\\\*\[?]*)+' => self :: T_WORD , '\*' => self :: T_WILDCARD_MULTI , '\?' => self :: T_WILDCARD_SINGLE , '\[([!^]?)(?=(\])?)' => function ( Stateful $ lexer , $ matches ) { $ state = isset ( $ matches [ 2 ] ) ? 'IN_GROUP_SPECIAL_FIRST' : 'IN_GROUP' ; $ lexer -> pushState ( $ state ) ; return $ matches [ 1 ] !== '' ? self :: T_GROUP_BEGIN_NEGATED : self :: T_GROUP_BEGIN ; } ] ; }
Initial state . This is the default state when the lexer enters the pattern .
3,487
protected function createInGroupDefinition ( ) { return [ '\]' => function ( Stateful $ lexer ) { $ lexer -> popState ( ) ; return self :: T_GROUP_END ; } , '.-[^\]]' => self :: T_GROUP_RANGE , '\[:[a-z]+:\]' => self :: T_GROUP_CHARACTER_CLASS , '.' => self :: T_GROUP_CHARACTER ] ; }
In group state . This looks for standard characters ranges and POSIX character classes .
3,488
public function execute ( $ eventName , $ object ) { if ( isset ( $ this -> events [ $ eventName ] ) && is_array ( ( $ this -> events [ $ eventName ] ) ) ) { foreach ( $ this -> events [ $ eventName ] as $ method ) { call_user_func ( [ $ object , $ method ] ) ; } } }
Execute an event
3,489
protected function filter ( & $ value ) { if ( is_scalar ( $ value ) ) { return htmlspecialchars ( $ value , ENT_QUOTES | ENT_SUBSTITUTE , 'UTF-8' ) ; } elseif ( is_array ( $ value ) ) { array_walk_recursive ( $ value , [ $ this , 'filter' ] ) ; } elseif ( is_object ( $ value ) ) { foreach ( get_object_vars ( $ value ) as $ k => $ v ) { $ value -> $ k = $ this -> filter ( $ value ) ; } } return $ value ; }
Filters a variable reference for XSS .
3,490
public function getFileUsage ( ) { if ( empty ( $ this -> fileUsage ) ) { $ this -> fileUsage = \ Drupal :: service ( 'file.usage' ) ; } return $ this -> fileUsage ; }
Gets file usage service .
3,491
public function createImagesFromVideos ( $ source , $ target = 'step-%03d.jpg' ) { try { $ this -> serviceLocator -> setShared ( 'playgroundcore_phpvideotoolkit' , false ) ; $ this -> serviceLocator -> get ( 'playgroundcore_phpvideotoolkit' ) -> addPreInputCommand ( '-y' ) -> addCommand ( '-i' , $ source ) -> setOutputPath ( $ target ) -> execute ( ) ; } catch ( FfmpegProcessOutputException $ e ) { throw new \ PHPVideoToolkit \ InvalidArgumentException ( 'Error when merging videos' ) ; } catch ( \ PHPVideoToolkit \ Exception $ e ) { throw new \ PHPVideoToolkit \ InvalidArgumentException ( 'Error when merging videos' ) ; } return $ target ; }
This method create images from a video . ffmpeg - i input . mov output_%03d . png
3,492
public function convertToMp3 ( $ source , $ target ) { $ this -> serviceLocator -> setShared ( 'playgroundcore_phpvideotoolkit' , false ) ; $ this -> serviceLocator -> get ( 'playgroundcore_phpvideotoolkit' ) -> addPreInputCommand ( '-y' ) -> addCommand ( '-i' , $ source ) -> addCommand ( '-vn' ) -> addCommand ( '-ar' , '44100' ) -> addCommand ( '-ac' , '2' ) -> addCommand ( '-ab' , '192' ) -> addCommand ( '-f' , 'mp3' ) -> setOutputPath ( $ target ) -> execute ( ) ; return $ target ; }
ffmpeg - i sound . avi - vn - ar 44100 - ac 2 - ab 192 - f mp3 out . mp3
3,493
protected static function invalidateCache ( $ id ) { $ type = static :: getType ( ) ; $ id = ( string ) $ id ; static :: initializeCache ( $ type ) ; $ collection = self :: $ cache -> { $ type } ; unset ( $ collection -> { $ id } ) ; }
Remove resource from cache used by PUT PATCH and DELETE methods when changing an object
3,494
public function id ( ) : string { if ( null !== $ this -> id ) { return $ this -> id ; } if ( $ this -> headers -> contain ( 'HTTP_X_REQUEST_ID' ) ) { $ this -> id = $ this -> readHeader ( 'HTTP_X_REQUEST_ID' ) -> ifMatches ( '~^([a-zA-Z0-9+/=-]{20,200})$~' ) ; } if ( null === $ this -> id ) { $ this -> id = substr ( str_shuffle ( md5 ( microtime ( ) ) ) , 0 , 25 ) ; } return $ this -> id ; }
returns id of the request
3,495
public function protocolVersion ( ) { if ( ! $ this -> headers -> contain ( 'SERVER_PROTOCOL' ) ) { return new HttpVersion ( 1 , 0 ) ; } try { return HttpVersion :: fromString ( $ this -> headers -> value ( 'SERVER_PROTOCOL' ) -> value ( ) ) ; } catch ( \ InvalidArgumentException $ ex ) { return null ; } }
returns HTTP protocol version of request
3,496
public function originatingIpAddress ( ) { try { if ( $ this -> headers -> contain ( 'HTTP_X_FORWARDED_FOR' ) ) { $ remoteAddresses = explode ( ',' , $ this -> headers -> value ( 'HTTP_X_FORWARDED_FOR' ) -> value ( ) ) ; return new IpAddress ( trim ( $ remoteAddresses [ 0 ] ) ) ; } if ( $ this -> headers -> contain ( 'REMOTE_ADDR' ) ) { return new IpAddress ( $ this -> headers -> value ( 'REMOTE_ADDR' ) -> value ( ) ) ; } } catch ( \ InvalidArgumentException $ iae ) { } return null ; }
returns the ip address which issued the request originally
3,497
public function userAgent ( array $ botSignatures = [ ] ) : UserAgent { return new UserAgent ( $ this -> headers -> value ( 'HTTP_USER_AGENT' ) -> value ( ) , $ this -> cookies -> count ( ) > 0 , $ botSignatures ) ; }
returns the user agent which issued the request
3,498
public function uri ( ) : HttpUri { $ host = ( string ) $ this -> headers -> value ( 'HTTP_HOST' ) -> value ( ) ; return HttpUri :: fromParts ( $ this -> headers -> contain ( 'HTTPS' ) ? Http :: SCHEME_SSL : Http :: SCHEME , $ host , strstr ( $ host , ':' ) === false ? $ this -> headers -> value ( 'SERVER_PORT' ) -> value ( ) : null , ( string ) $ this -> headers -> value ( 'REQUEST_URI' ) -> value ( ) ) ; }
returns the uri of the request
3,499
public function hasRedirectHeader ( string $ headerName ) : bool { return $ this -> hasHeader ( 'REDIRECT_' . $ headerName ) || $ this -> hasHeader ( $ headerName ) ; }
checks whether a request header or it s redirect equivalent is set