idx
int64
0
60.3k
question
stringlengths
64
4.24k
target
stringlengths
5
618
55,200
public function decode ( $ string ) { $ i = 0 ; foreach ( str_split ( $ string ) as $ char ) { $ i = $ i * $ this -> radix + array_search ( $ char , $ this -> dictionary ) ; } return $ i ; }
Base 62 decodes a string .
55,201
public function setCredentials ( $ appId , $ secretKey ) { $ this -> appId = $ appId ; $ this -> secretKey = $ secretKey ; return $ this ; }
Sets App credentials
55,202
public function send ( array $ body = null ) { $ json = $ this -> createJsonBody ( $ body ) ; $ signature = $ this -> createSignature ( $ json ) ; $ headers = $ options = [ ] ; $ headers [ "User-Agent" ] = self :: prepareUserAgent ( ) ; if ( $ body ) { $ headers [ "Content-Type" ] = "application/json" ; $ headers [ "Co...
Sends a HTTP request
55,203
private function createJsonBody ( & $ body ) { if ( $ body && $ this -> method != self :: GET ) { return GuzzleHttp \ json_encode ( $ body ) ; } return ; }
Creates a JSON string
55,204
private function createSignature ( & $ json ) { $ string = $ this -> appId . $ this -> method . $ this -> endpoint ; if ( $ json ) { $ string .= $ json ; } if ( $ this -> accessToken ) { $ string .= $ this -> accessToken ; } $ digest = hash ( "sha512" , $ string ) ; $ sign = "" ; $ result = openssl_public_encrypt ( $ d...
Creates a request signature
55,205
private function prepareHeaders ( & $ signature , array $ headers = [ ] ) { $ headers [ "X-Origin" ] = self :: prepareOrigin ( ) ; $ headers [ "X-Ukey1-App" ] = $ this -> appId ; $ headers [ "X-Ukey1-Signature" ] = $ signature ; if ( $ this -> accessToken ) { $ headers [ "Authorization" ] = "Bearer " . $ this -> access...
Prepares request headers
55,206
private static function prepareOrigin ( ) { $ origin = App :: getDomain ( ) ; if ( ! $ origin ) { $ origin = ( isset ( $ _SERVER [ "REQUEST_SCHEME" ] ) ? $ _SERVER [ "REQUEST_SCHEME" ] : "http" . ( isset ( $ _SERVER [ "HTTPS" ] ) ? "s" : "" ) ) . "://" . ( isset ( $ _SERVER [ "HTTP_HOST" ] ) ? $ _SERVER [ "HTTP_HOST" ]...
Prepares X - Origin value
55,207
public function bumpCache ( $ path ) { $ this -> get ( $ path ) ; if ( is_array ( $ this -> object [ 'response' ] ) && count ( $ this -> object [ 'response' ] ) > 0 ) { $ this -> object [ 'cache' ] = ( int ) ( time ( ) + 3600 ) ; $ this -> backend -> delete ( $ path ) ; $ this -> backend -> put ( $ this -> object ) ; r...
Just bump up cache timer used when handling 304 s
55,208
public function save ( $ path , $ response , $ header ) { if ( ! ( is_array ( $ response ) && count ( $ response ) > 0 ) ) { $ this -> __debug ( "no valid response for $path, will not save, invalidating any saved copy" ) ; $ this -> backend -> delete ( $ path ) ; return false ; } if ( $ this -> cacheTime == 0 ) { retur...
Create or replace a current object by its path
55,209
public function getAsset ( $ chunkName , $ pattern = '/.*/' ) { foreach ( $ this -> getAssets ( $ chunkName ) as $ filename ) { if ( preg_match ( $ pattern , $ filename ) ) { return $ filename ; } } return null ; }
Returns the first matching asset in the given chunk . Matches everything by default .
55,210
function dump ( $ show_attr = true , $ deep = 0 ) { $ lead = str_repeat ( ' ' , $ deep ) ; echo $ lead . $ this -> tag ; if ( $ show_attr && count ( $ this -> attr ) > 0 ) { echo '(' ; foreach ( $ this -> attr as $ k => $ v ) { echo "[$k]=>\"" . $ this -> $ k . '", ' ; } echo ')' ; } echo "\n" ; if ( $ this -> nodes ) ...
dump node s tree
55,211
function prev_sibling ( ) { if ( $ this -> parent === null ) { return null ; } $ idx = 0 ; $ count = count ( $ this -> parent -> children ) ; while ( $ idx < $ count && $ this !== $ this -> parent -> children [ $ idx ] ) { ++ $ idx ; } if ( -- $ idx < 0 ) { return null ; } return $ this -> parent -> children [ $ idx ] ...
returns the previous sibling of node
55,212
function innertext ( ) { if ( isset ( $ this -> _ [ HDOM_INFO_INNER ] ) ) { return $ this -> _ [ HDOM_INFO_INNER ] ; } if ( isset ( $ this -> _ [ HDOM_INFO_TEXT ] ) ) { return $ this -> dom -> restore_noise ( $ this -> _ [ HDOM_INFO_TEXT ] ) ; } $ ret = '' ; foreach ( $ this -> nodes as $ n ) { $ ret .= $ n -> outertex...
get dom node s inner html
55,213
public function match ( $ requestUri , $ requestMethod ) { $ this -> requestUri = rtrim ( strtok ( $ requestUri , '?' ) , '/' ) ; $ this -> requestMethod = $ requestMethod ; if ( $ this -> matchDirect ( ) ) { return true ; } elseif ( $ this -> matchCache ( ) ) { return true ; } elseif ( $ this -> matchRegex ( ) ) { ret...
Takes the request uri and matches it against all defined routes . If a route can be found the function looks if the request method has a matching function defined in the endpoint .
55,214
protected function matchCache ( ) { if ( $ this -> cache instanceof Cache ) { if ( $ cachedRoutes = $ this -> cache -> get ( 'routeMiddlewareRoutes' ) ) { if ( isset ( $ cachedRoutes [ $ this -> requestUri ] ) ) { if ( ! $ this -> endpointExists ( $ cachedRoutes [ $ this -> requestUri ] [ 'matchedEndpoint' ] ) ) { thro...
Check if we can find the requested route in cache
55,215
protected function matchRegex ( ) { foreach ( $ this -> routes as $ route => $ endpoint ) { $ result = $ this -> routeParser -> parse ( $ route ) ; $ regex = $ result [ 0 ] ; $ paramNames = $ result [ 1 ] ; if ( preg_match ( $ regex , $ this -> requestUri , $ matches ) ) { if ( ! $ this -> endpointExists ( $ endpoint )...
Try to match against regex this is the last resort usually we first try to find a direct match and look in the cache as well . But if no match has been found yet this is the last try .
55,216
protected function addToCache ( $ requestUri ) { if ( $ this -> cache instanceof Cache ) { $ toCache = [ 'matchedRoute' => $ this -> matchedRoute , 'matchedEndpoint' => $ this -> matchedEndpoint , 'params' => $ this -> params ] ; if ( $ cachedRoutes = $ this -> cache -> get ( 'routeMiddlewareRoutes' ) ) { $ cachedRoute...
Add a match to the cache for later use this makes it easier for the router to find a match the next time the same request uri i requested since the router checks in the cache before it tries to find a match in the route table .
55,217
public function addRoutes ( array $ routes ) { foreach ( $ routes as $ route => $ endpoint ) { $ route = ( $ route !== '/' ) ? rtrim ( $ route , '/' ) : '/' ; $ this -> routes [ $ route ] = $ endpoint ; } }
Add multiple routes to the router table as the same time
55,218
public function setSTSLifetime ( int $ seconds ) { $ seconds = $ seconds ; if ( $ seconds >= 900 && $ seconds <= 3600 ) { $ this -> stsLifetime = $ seconds ; } }
Set lifetime of STS tokens .
55,219
public function addFinder ( FormatFinder ... $ finder ) { foreach ( $ finder as $ f ) { if ( false === array_search ( $ f , $ this -> finders , true ) ) { $ this -> finders [ ] = $ f ; } } }
Adds a FormatFinder to the chain .
55,220
public function removeFinder ( FormatFinder ... $ finder ) { foreach ( $ finder as $ f ) { if ( false !== $ offset = array_search ( $ f , $ this -> finders , true ) ) { unset ( $ this -> finders [ $ offset ] ) ; } } }
Removes a FormatFind from the chain .
55,221
protected function setPersistence ( Metadata \ EntityMetadata $ metadata , array $ mapping ) { $ persisterKey = isset ( $ mapping [ 'key' ] ) ? $ mapping [ 'key' ] : null ; $ factory = $ this -> getPersistenceMetadataFactory ( $ persisterKey ) ; $ persistence = $ factory -> createInstance ( $ mapping ) ; $ metadata -> ...
Sets the entity persistence metadata from the metadata mapping .
55,222
protected function setSearch ( Metadata \ EntityMetadata $ metadata , array $ mapping ) { $ clientKey = isset ( $ mapping [ 'key' ] ) ? $ mapping [ 'key' ] : null ; if ( null === $ clientKey ) { return $ metadata ; } $ factory = $ this -> getSearchMetadataFactory ( $ clientKey ) ; $ search = $ factory -> createInstance...
Sets the entity search metadata from the metadata mapping .
55,223
protected function setEmbeds ( Metadata \ Interfaces \ EmbedInterface $ metadata , array $ embedMapping ) { foreach ( $ embedMapping as $ key => $ mapping ) { if ( ! is_array ( $ mapping ) ) { $ mapping = [ 'type' => null , 'entity' => null ] ; } if ( ! isset ( $ mapping [ 'type' ] ) ) { $ mapping [ 'type' ] = null ; }...
Sets the entity embed metadata from the metadata mapping .
55,224
protected function setMixins ( Metadata \ Interfaces \ MixinInterface $ metadata , array $ mixins ) { foreach ( $ mixins as $ mixinName ) { $ mixinMeta = $ this -> loadMetadataForMixin ( $ mixinName ) ; if ( null === $ mixinMeta ) { continue ; } $ metadata -> addMixin ( $ mixinMeta ) ; } return $ metadata ; }
Sets creates mixin metadata instances from a set of mixin mappings ands sets them to the entity metadata instance .
55,225
private function setRootDefault ( $ key , array $ mapping ) { if ( ! isset ( $ mapping [ $ key ] ) || ! is_array ( $ mapping [ $ key ] ) ) { $ mapping [ $ key ] = [ ] ; } return $ mapping ; }
Sets a root level default value to a metadata mapping array .
55,226
public function createMasterClient ( $ name ) { $ master = $ this -> getMasterAddressByName ( $ name ) ; if ( ! isset ( $ master [ 0 ] ) || ! isset ( $ master [ 1 ] ) ) { throw new Exception ( 'Master not found' ) ; } return new Client ( $ master [ 0 ] , $ master [ 1 ] , null , '' , 0 , $ this -> _authPassword ) ; }
Discover the master node automatically and return an instance of Client that connects to the master
55,227
public function getMasterClient ( $ name ) { if ( ! isset ( $ this -> _master [ $ name ] ) ) { $ this -> _master [ $ name ] = $ this -> createMasterClient ( $ name ) ; } return $ this -> _master [ $ name ] ; }
If a Client object exists for a master return it . Otherwise create one and return it
55,228
public function createSlaveClients ( $ name ) { $ slaves = $ this -> slaves ( $ name ) ; $ workingSlaves = array ( ) ; foreach ( $ slaves as $ slave ) { if ( ! isset ( $ slave [ 9 ] ) ) { throw new Exception ( 'Can\' retrieve slave status' ) ; } if ( ! strstr ( $ slave [ 9 ] , 's_down' ) && ! strstr ( $ slave [ 9 ] , '...
Discover the slave nodes automatically and return an array of Client objects
55,229
public function getSlaveClients ( $ name ) { if ( ! isset ( $ this -> _slaves [ $ name ] ) ) { $ this -> _slaves [ $ name ] = $ this -> createSlaveClients ( $ name ) ; } return $ this -> _slaves [ $ name ] ; }
If an array of Client objects exist for a set of slaves return them . Otherwise create and return them
55,230
public function getCluster ( $ name , $ db = 0 , $ replicas = 128 , $ selectRandomSlave = true , $ writeOnly = false ) { if ( ! isset ( $ this -> _cluster [ $ name ] ) ) { $ this -> _cluster [ $ name ] = $ this -> createCluster ( $ name , $ db , $ replicas , $ selectRandomSlave , $ writeOnly ) ; } return $ this -> _clu...
If a Cluster object exists return it . Otherwise create one and return it .
55,231
public function addChild ( Process $ process ) { $ this -> children -> set ( $ process -> getId ( ) , $ process ) ; return $ this ; }
Add Child Process
55,232
public function getChildById ( $ processId ) { if ( false === $ this -> hasChildById ( $ processId ) ) { throw new MissingChildException ( 'The child process does not exist' ) ; } return $ this -> children -> get ( $ processId ) -> get ( ) ; }
Get Child By ID
55,233
public function removeChild ( Process $ process ) { if ( false === $ this -> hasChildById ( $ process -> getId ( ) ) ) { throw new MissingChildException ( 'The child process does not exist' ) ; } $ this -> children -> remove ( $ process -> getId ( ) ) ; return $ this ; }
Remove Child Process
55,234
protected function getClassMeta ( ReflectionClass $ reflection ) : array { $ doc = $ reflection -> getDocComment ( ) ; $ notations = $ this -> parser -> parse ( $ doc ) ; return $ notations ; }
Get meta for class
55,235
protected function validateConfiguration ( array $ config ) : bool { if ( ! is_array ( $ config ) ) { throw new DatabaseConnectionException ( 'Could not load LDAP configuration settings.' ) ; } $ config_keys = array_keys ( $ config ) ; $ missing = array_diff ( [ 'server' , 'port' , 'domain' , 'base_dn' , 'username' , '...
Checks the configuration array for required elements . By default checks the server username and password elements are set . Override to check for additional elements .
55,236
protected function bindToServer ( ) : void { $ success = @ ldap_bind ( $ this -> handle , $ this -> configuration [ 'username' ] . '@' . $ this -> configuration [ 'domain' ] , $ this -> configuration [ 'password' ] ) ; if ( ! $ success ) { $ this -> logger -> error ( 'LDAP failed: ' . ldap_err2str ( ldap_errno ( $ this...
The binding sends the username domain and password to the remote server . In order to log in the user s information is sent instead of the default account information . After a login the default binding must be reset for additional queries .
55,237
public function getItemById ( $ id ) { if ( ! isset ( $ this -> children [ $ id ] ) ) { throw new \ InvalidArgumentException ( sprintf ( "item with id %d does not exist" , $ id ) ) ; } return $ this -> children [ $ id ] ; }
Get item by identifier
55,238
public function getMostRevelantItemForNode ( $ nodeId ) { if ( isset ( $ this -> perNode [ $ nodeId ] ) ) { return reset ( $ this -> perNode [ $ nodeId ] ) ; } }
Get most revelant item for node
55,239
public function getMostRevelantTrailForNode ( $ nodeId ) { $ trail = [ ] ; $ item = $ this -> getMostRevelantItemForNode ( $ nodeId ) ; if ( ! $ item ) { return $ trail ; } $ trail [ ] = $ item ; $ parentId = $ item -> getParentId ( ) ; while ( isset ( $ this -> children [ $ parentId ] ) ) { array_unshift ( $ trail , $...
Get most revelant trail for node
55,240
private function parsing ( ) : void { $ lines = explode ( "\n" , $ this -> raw ) ; foreach ( $ lines as $ line ) { if ( false === strpos ( $ line , '@' ) ) { continue ; } if ( $ anp = strpos ( $ line , '//' ) ) { $ line = substr ( $ line , 0 , $ anp ) ; } $ line = trim ( ltrim ( $ line , ' *' ) ) ; if ( false === $ fws...
simple comment parsing
55,241
public function buildForm ( FormBuilderInterface $ builder , array $ options ) { $ builder -> add ( 'title' , SymfonyTextType :: class , array ( 'required' => false ) ) ; if ( ! empty ( $ options [ 'headline' ] [ 'enabled' ] ) ) { $ builder -> add ( 'headline' , TextareaType :: class , array ( 'required' => false ) ) ;...
Text component form prototype definition .
55,242
public function parseUrl ( $ str ) { if ( ! is_string ( $ str ) ) { throw new InvalidUrlException ( 'Unexpected type.' ) ; } if ( $ str === '' ) { throw new InvalidUrlException ( 'Empty URL.' ) ; } if ( trim ( $ str , ' ' ) === '' ) { throw new InvalidUrlException ( 'Empty URL.' ) ; } $ components = $ this -> parseUrlC...
Parses an URL .
55,243
public function isAbsolute ( ) { if ( $ this -> isEmpty ( ) ) { return false ; } return ! $ this -> host -> isEmpty ( ) || ! $ this -> scheme -> isEmpty ( ) ; }
Returns true if the URL contains a host false otherwise .
55,244
public function makeAbsolute ( $ base ) { if ( is_string ( $ base ) ) { $ baseUrl = new Url ( $ base ) ; } else if ( $ base instanceof Url ) { $ baseUrl = $ base ; } else { throw new InvalidUrlException ( ) ; } if ( $ baseUrl -> isEmpty ( ) ) { throw new InvalidUrlException ( ) ; } if ( ! $ baseUrl -> isAbsolute ( ) ) ...
Makes the current relative URL absolute to the given base URL .
55,245
public function makeAbsolutePath ( $ base ) { if ( is_string ( $ base ) ) { $ baseUrl = new Url ( $ base ) ; } else if ( $ base instanceof Url ) { $ baseUrl = $ base ; } else if ( $ newUrl instanceof Path ) { $ baseUrl = new Url ( ) ; $ baseUrl -> path -> set ( $ newUrl ) ; } else { throw new InvalidUrlException ( ) ; ...
Makes the path of the current relative URL absolute to the given base URL .
55,246
public function isEmpty ( ) { return $ this -> scheme -> isEmpty ( ) && $ this -> host -> isEmpty ( ) && $ this -> path -> isEmpty ( ) && $ this -> port -> isEmpty ( ) && $ this -> credentials -> isEmpty ( ) && $ this -> query -> isEmpty ( ) && $ this -> fragment -> isEmpty ( ) ; }
Returns true if all components are empty .
55,247
public function clear ( $ opt = self :: SCHEME | self :: HOST | self :: PORT | self :: CREDENTIALS | self :: PATH | self :: QUERY | self :: FRAGMENT ) { $ scheme = ( $ opt & self :: SCHEME ) === self :: SCHEME ; $ host = ( $ opt & self :: HOST ) === self :: HOST ; $ port = ( $ opt & self :: PORT ) === self :: PORT ; $ ...
Clear all or only specific components .
55,248
public function clearPath ( $ opt = self :: PATH | self :: QUERY | self :: FRAGMENT ) { $ path = ( $ opt & self :: PATH ) === self :: PATH ; $ query = ( $ opt & self :: QUERY ) === self :: QUERY ; $ fragment = ( $ opt & self :: FRAGMENT ) === self :: FRAGMENT ; if ( $ path ) { $ this -> path -> clear ( ) ; } if ( $ que...
Clear components at the right starting with the path .
55,249
public function clearHost ( $ opt = self :: SCHEME | self :: HOST | self :: PORT | self :: CREDENTIALS ) { $ scheme = ( $ opt & self :: SCHEME ) === self :: SCHEME ; $ host = ( $ opt & self :: HOST ) === self :: HOST ; $ port = ( $ opt & self :: PORT ) === self :: PORT ; $ creds = ( $ opt & self :: CREDENTIALS ) === se...
Clear components at the left up to the path .
55,250
public function replace ( $ newUrl , $ opt = self :: SCHEME | self :: HOST | self :: PORT | self :: CREDENTIALS | self :: PATH | self :: QUERY | self :: FRAGMENT ) { if ( $ newUrl instanceof Url ) { $ url = $ newUrl ; } else if ( is_string ( $ newUrl ) ) { $ url = new Url ( $ newUrl ) ; } else { throw new InvalidUrlExc...
Replaces all or specific components with the components of the given URL .
55,251
public function replaceHost ( $ newUrl , $ opt = self :: SCHEME | self :: HOST | self :: PORT | self :: CREDENTIALS ) { if ( $ newUrl instanceof Url ) { $ url = $ newUrl ; } else if ( is_string ( $ newUrl ) ) { $ url = new Url ( $ newUrl ) ; } else { throw new InvalidUrlException ( ) ; } $ scheme = ( $ opt & self :: SC...
Replaces the components left of the path with the components of the given URL .
55,252
public function replacePath ( $ newUrl , $ opt = self :: PATH | self :: QUERY | self :: FRAGMENT ) { if ( $ newUrl instanceof Url ) { $ url = $ newUrl ; } else if ( $ newUrl instanceof Path ) { $ url = new Url ( ) ; $ url -> path -> set ( $ newUrl ) ; } else if ( is_string ( $ newUrl ) ) { $ url = new Url ( $ newUrl ) ...
Replaces the components on the right side starting with the path with the components of the given URL .
55,253
public function equals ( $ otherUrl , $ opt = self :: SCHEME | self :: HOST | self :: PORT | self :: CREDENTIALS | self :: PATH | self :: QUERY | self :: FRAGMENT ) { if ( $ otherUrl instanceof Url ) { $ url = $ otherUrl ; } else if ( is_string ( $ otherUrl ) ) { $ url = new Url ( $ otherUrl ) ; } else { throw new Inva...
Compare all or only specific components of this URL with another URL .
55,254
public function isValid ( ) { if ( $ this -> isEmpty ( ) ) { return false ; } $ requiresHost = ! $ this -> port -> isEmpty ( ) || ! $ this -> credentials -> isEmpty ( ) || $ this -> scheme -> equals ( 'http' ) || $ this -> scheme -> equals ( 'https' ) ; if ( $ requiresHost && $ this -> host -> isEmpty ( ) ) { return fa...
If the URL is empty it is invalid . If the URL contains a component that requires a host but the host is empty it is invalid .
55,255
public function updateAction ( Request $ request ) : JsonResponse { $ id = $ request -> request -> get ( 'id' ) ; $ data = $ request -> request -> get ( 'product' ) ; try { $ this -> quickUpdateProduct ( $ id , $ data ) ; $ result = [ 'success' => $ this -> trans ( 'product.flash.success.saved' ) ] ; } catch ( \ Except...
Updates product data from DataGrid request
55,256
public function getHash ( ) { $ hash = [ ] ; foreach ( $ this -> metadata -> getAttributes ( ) as $ key => $ attrMeta ) { $ value = $ this -> get ( $ key ) ; if ( null === $ value ) { $ hash [ $ key ] = $ value ; continue ; } switch ( $ attrMeta -> dataType ) { case 'date' : $ value = $ value -> getTimestamp ( ) ; brea...
Gets the unique hash for this embed .
55,257
private function fetchForm ( ) : bool { $ form_key = preg_grep ( '/^form_' . preg_quote ( $ this -> name , '/' ) . '_[a-f0-9]+$/' , array_keys ( $ _SESSION ) ) ; if ( empty ( $ form_key ) ) { return false ; } $ this -> key = array_values ( $ form_key ) [ 0 ] ; foreach ( $ _SESSION [ $ this -> key ] as $ key => $ value ...
Check if the form has been sent
55,258
public function isFieldSet ( string $ name ) : bool { if ( ! $ this -> fetchForm ( ) ) { return false ; } $ name = trim ( $ name ) ; $ field_key = array_search ( $ name , $ this -> keys ) ; return isset ( $ this -> method [ $ field_key ] ) ? : isset ( $ _FILES [ $ field_key ] ) ; }
Detect if a specific field is defined
55,259
public function getField ( string $ name ) { $ name = trim ( $ name ) ; if ( ! $ this -> isFieldSet ( $ name ) ) { return null ; } $ field_key = array_search ( $ name , $ this -> keys ) ; return $ this -> method [ $ field_key ] ?? $ _FILES [ $ field_key ] ; }
Get a field value
55,260
public function export ( ) : array { return array_combine ( $ this -> keys , array_map ( function ( $ f ) { return $ this -> getField ( $ f ) ; } , $ this -> keys ) ) ; }
Get all the form data
55,261
protected function hasLinks ( $ string ) { $ regex = '(https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|www\.[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9]\.[^\s]{2,}|www\.[a-zA-Z0-9]\.[^\s]{2,})' ; preg_match ( $ regex , $ string , $ matches ) ; return ...
Checks if the specified string contains a URL .
55,262
protected function prefixSuffix ( $ string ) { $ prefix = ltrim ( $ string ) !== $ string ? ' ' : '' ; $ suffix = rtrim ( $ string ) !== $ string ? ' ' : '' ; return ( array ) array ( $ prefix , $ suffix ) ; }
Returns prefix and suffix of a specified string .
55,263
function getReference ( $ table , $ ref = null ) { if ( isset ( $ this -> references [ $ table ] ) ) { if ( ! strlen ( $ ref ) ) { return current ( $ this -> references [ $ table ] ) ; } if ( isset ( $ this -> references [ $ table ] [ $ ref ] ) ) { return $ this -> references [ $ table ] [ $ ref ] ; } } }
Get a reference to a table
55,264
public static function createPreheatedReference ( Smalldb $ smalldb , AbstractMachine $ machine , $ properties ) { $ ref = new static ( $ smalldb , $ machine , null ) ; $ ref -> properties_cache = $ properties ; $ ref -> state_cache = $ properties [ 'state' ] ; $ id_properties = $ machine -> describeId ( ) ; if ( count...
Create pre - heated reference .
55,265
protected function loadClassAnnotations ( ) { if ( empty ( $ this -> targetClass ) ) { throw new \ RuntimeException ( "Runtime Error: Any class was defined as target to annotations handling." ) ; } $ annotationsObjects = array ( ) ; $ this -> annotations [ '_class_' ] = $ this -> getClassAnnotationsObjects ( $ this -> ...
Loads class annotations and persist on the reader
55,266
protected function loadMethodAnnotations ( ) { if ( empty ( $ this -> targetClass ) ) { throw new \ RuntimeException ( "Runtime Error: Any class was defined as target to annotations handling." ) ; } if ( empty ( $ this -> targetMethod ) ) { throw new \ RuntimeException ( sprintf ( "Runtime Error: Any method of class '%...
Loads method annotations form target class and persist on the reader
55,267
public function getAnnotation ( $ annotationName ) { if ( empty ( $ this -> targetClass ) ) { throw new \ RuntimeException ( "Runtime Error: Any class was defined as target to annotations handling." ) ; } $ annotationInstance = null ; if ( empty ( $ this -> targetMethod ) ) { if ( ! array_key_exists ( '_class_' , $ thi...
Gets annotations objects previously loaded on reader
55,268
public function load ( string $ filename ) : array { $ extension = pathinfo ( $ filename , PATHINFO_EXTENSION ) ; if ( method_exists ( $ this , $ extension ) ) { $ parameters = $ this -> { $ extension } ( $ filename ) ; } else { $ parameters = [ ] ; } if ( ! isset ( $ parameters [ "driver" ] ) ) { $ parameters += [ "dr...
Loads parameters from configuration file .
55,269
public function ini ( string $ filename ) : array { $ ini = parse_ini_file ( $ filename , true ) ; if ( $ ini !== false ) { $ parameters = $ ini [ Environment :: choose ( ) ] ; return $ parameters ; } else { return [ ] ; } }
Parses configuration from . ini file .
55,270
public function neon ( string $ filename ) : array { $ neon = file_get_contents ( $ filename ) ; if ( $ neon !== false ) { $ parameters = Neon :: decode ( $ neon ) ; return $ parameters [ "doctrine" ] ; } else { return [ ] ; } }
Parses configuration from . neon file .
55,271
public static function parseUrl ( $ url ) { $ info = parse_url ( $ url ) ; if ( ! $ info || empty ( $ info [ 'scheme' ] ) ) { throw new InvalidUrl ( 'The string must be a valid URL' ) ; } if ( empty ( $ info [ 'scheme' ] ) || ! in_array ( $ info [ 'scheme' ] , array ( 'http' , 'https' ) ) ) { throw new InvalidUrl ( 'Sc...
Return an array of 4 elements containing the scheme hostname port and a boolean representing whether the connection should use SSL or not .
55,272
public function execute ( array $ params ) : ResultSet { $ this -> logger -> info ( 'DB PREPARE: Preparing query.' ) ; $ test_query = $ this -> result -> queryString ; foreach ( $ params as $ name => $ val ) { $ test_query = str_replace ( $ name , '\'' . str_replace ( "'" , "''" , $ val ) . '\'' , $ test_query ) ; } $ ...
Rerun a query using the prepared statement . This is more efficent than creating new prepared statements when doing bulk operations .
55,273
public function current ( ) : array { return $ this -> result -> fetch ( \ PDO :: FETCH_ASSOC , \ PDO :: FETCH_ORI_ABS , $ this -> pointer ) ; }
Returns the current element in the result set as an array
55,274
public static function className ( $ className , $ namespace = null ) { if ( class_exists ( $ className , false ) ) { return $ className ; } else if ( strpos ( $ className , '\\' ) === false ) { $ className = $ namespace . '\\' . $ className ; } return __SAMSON_PHP_OLD ? self :: oldClassName ( $ className ) : $ classNa...
Generate correct class name dependently on the current PHP version if PHP version is lower 5 . 3 . 0 it does not supports namespaces and function will convert class name with namespace to class name
55,275
public static function oldClassName ( $ className ) { if ( $ className { 0 } == self :: NS_SEPARATOR ) { $ className = substr ( $ className , 1 ) ; } return strtolower ( str_replace ( self :: NS_SEPARATOR , '_' , $ className ) ) ; }
Convert class name to old PHP format not supporting name spaces
55,276
public static function load ( $ class ) { $ className = self :: getOnlyClass ( $ class ) ; $ nameSpace = self :: getOnlyNameSpace ( $ class ) ; if ( $ nameSpace != __NAMESPACE__ ) { $ path = __SAMSON_VENDOR_PATH . str_replace ( '\\' , DIRECTORY_SEPARATOR , $ nameSpace ) . DIRECTORY_SEPARATOR . $ className . '.php' ; if...
Auto loader main logic
55,277
public static function getOnlyClass ( $ className ) { if ( ( $ p = strrpos ( $ className , self :: NS_SEPARATOR ) ) !== false ) { $ className = substr ( $ className , $ p + 1 ) ; } return $ className ; }
Return only class name without namespace
55,278
public static function getOnlyNameSpace ( $ className ) { if ( ( $ p = strrpos ( $ className , self :: NS_SEPARATOR ) ) !== false ) { $ className = substr ( $ className , 0 , $ p ) ; } return $ className ; }
Return only namespace name from class name
55,279
protected static function oldModule ( $ className , $ nameSpace , & $ file = null ) { $ ns = str_replace ( self :: NS_SEPARATOR , '/' , $ nameSpace ) ; if ( isset ( self :: $ moduleMap [ $ nameSpace ] ) ) { $ path = self :: $ moduleMap [ $ nameSpace ] ; } else { $ locations = null ; $ path = null ; foreach ( array ( 'p...
All our modules do not follow PSR - 0 and classes located as they wish to so we will have to scan all files in module location and build all classes tree .
55,280
public function getDriver ( ) : Driver { if ( is_null ( $ this -> driver ) ) { $ this -> driver = $ this -> driverFactory -> createDriver ( ) ; $ this -> driver -> connect ( ) ; } return $ this -> driver ; }
Get the Driver instance wrapped in the context .
55,281
public static function load ( $ viewsDir ) { if ( ! class_exists ( 'Twig_Loader_Filesystem' ) ) { echo 'Twig not activated. Make sure you activate the plugin in <a href="/wp-admin/plugins.php#timber">/wp-admin/plugins.php</a>' ; return ; } \ Twig_Autoloader :: register ( ) ; try { $ loader = new \ Twig_Loader_Filesy...
Loads Twig with polish settings .
55,282
public function text ( $ name , $ value = null , array $ options = [ ] ) { return $ this -> form -> text ( $ name , $ value , $ this -> addFormControlClass ( $ this -> getFieldOptions ( $ name , $ options ) ) ) ; }
Create text input field
55,283
public function password ( $ name , array $ options = [ ] ) { return $ this -> form -> password ( $ name , $ this -> addFormControlClass ( $ this -> getFieldOptions ( $ name , $ options ) ) ) ; }
Create password field
55,284
public function file ( $ name , array $ options = [ ] ) { return $ this -> form -> file ( $ name , $ this -> addFormControlClass ( $ this -> getFieldOptions ( $ name , $ options ) ) ) ; }
Create file field
55,285
public function tokenInput ( $ name , $ url , $ value = null , array $ options = [ ] ) { $ script = '<script type="text/javascript"> (function ($, undefined) { var selector = \'#' . $ this -> getFieldId ( $ name , $ options ) . '\'; $(selector).tokenInput({ ajax : { ...
Create token input field
55,286
protected function getFieldId ( $ name , array $ options = [ ] ) { if ( Arr :: has ( $ options , 'field.id' ) ) { return Arr :: get ( $ options , 'field.id' ) ; } return 'field-' . str_replace ( '_' , '-' , $ name ) ; }
Get field id
55,287
private function validateUrl ( string $ url ) { if ( ! ( new UrlSpecification ) -> isSatisfiedBy ( new Url ( $ url ) ) ) { throw new UrlException ( sprintf ( 'The string "%s" is not a valid url' , $ url ) ) ; } }
Check if the given url is indeed one
55,288
private function createUrl ( string $ url ) : Url { $ url = new Url ( $ url ) ; if ( ( new SchemeLess ) -> isSatisfiedBy ( $ url ) ) { $ url = $ url -> appendScheme ( new Scheme ( $ this -> schemes [ 0 ] ?? 'http' ) ) ; } return $ url ; }
Create a Url object from the given string
55,289
public function getByAccessToken ( AccessTokenEntity $ accessToken ) { $ sql = <<<SQLSELECT os.id, os.owner_type, os.owner_id, os.client_id, os.client_redirect_uriFROM oauth_session osINNER JOIN oauth_access_token oat ON(oat.session_id = os.id)WHERE oat.access_token = :tokenSQL ; foreach ( $ this -> getDbConnection ( ...
Get a session from an access token
55,290
public function getByAuthCode ( AuthCodeEntity $ authCode ) { $ sql = <<<SQLSELECT os.id, os.owner_type, os.owner_id, os.client_id, os.client_redirect_uriFROM oauth_session osINNER JOIN oauth_auth_code oac ON(oac.session_id = os.id)WHERE oac.auth_code = :authCodeSQL ; foreach ( $ this -> getDbConnection ( ) -> fetchAl...
Get a session from an auth code
55,291
public function getScopes ( SessionEntity $ session ) { $ sql = <<<SQLSELECT os.* FROM oauth_session osesINNER JOIN oauth_session_scope oss ON(oses.id=oss.session_id)INNER JOIN oauth_scope os ON(os.id=oss.scope)WHERE oses.id = :sessionIdSQL ; foreach ( $ this -> getDbConnection ( ) -> fetchAll ( $ sql , [ 'sessionId' ...
Get a session s scopes
55,292
public function associateScope ( SessionEntity $ session , ScopeEntity $ scope ) { $ this -> getDbConnection ( ) -> insert ( 'oauth_session_scope' , [ 'session_id' => $ session -> getId ( ) , 'scope' => $ scope -> getId ( ) ] ) ; }
Associate a scope with a session
55,293
function fields ( array $ keys , $ def = null ) { $ this -> A = array_fields ( $ this -> A , $ keys , $ def ) ; return $ this ; }
Extracts the values with the given keys from a given array in the same order as the key list .
55,294
function filter ( callable $ fn ) { $ this -> A = array_filter ( $ this -> A , $ fn , ARRAY_FILTER_USE_BOTH ) ; return $ this ; }
Calls a filtering function for each element of an array . The function will receive as arguments the array element and its key . It should return a boolean value that indicates whether the element should not be discarded or not .
55,295
function findAll ( $ fld , $ val , $ strict = false ) { $ this -> A = array_findAll ( $ this -> A , $ fld , $ val , $ strict ) ; return $ this ; }
Extracts from an array all elements where the specified field matches the given value . Supports arrays of objects or arrays of arrays .
55,296
function joinRecords ( $ array , $ field ) { $ this -> A = array_join ( $ this -> A , $ array instanceof self ? $ array -> A : $ array , $ field ) ; return $ this ; }
Merges records from two arrays using the specified primary key field . When keys collide the corresponding values are assumed to be arrays and they are merged .
55,297
function keysOf ( $ value , $ strict = true ) { $ this -> A = array_keys ( $ this -> A , $ value , $ strict ) ; return $ this ; }
Gets all the keys of the array that match a given value .
55,298
function map ( callable $ fn , $ useKeys = true ) { $ this -> A = map ( $ this -> A , $ fn , $ useKeys ) ; return $ this ; }
Calls a transformation function for each element of the array .
55,299
function merge ( $ v ) { if ( is_array ( $ v ) ) array_mergeInto ( $ this -> A , $ v ) ; else if ( $ v instanceof static ) array_mergeInto ( $ this -> A , $ v -> A ) ; else throw new InvalidArgumentException ; }
Merges another array or instance of this class with this one .