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 [ "Content-Length" ] = strlen ( $ json ) ; $ options [ "body" ] = $ json ; } $ options [ "headers" ] = $ this -> prepareHeaders ( $ signature , $ headers ) ; try { $ this -> httpClient = new Client ( [ "base_uri" => $ this -> host , "timeout" => self :: TIMEOUT ] ) ; return new Result ( $ this -> httpClient -> request ( $ this -> method , $ this -> endpoint , $ options ) ) ; } catch ( TransferException $ e ) { throw new EndpointException ( $ e -> getMessage ( ) , $ e -> getCode ( ) , $ e ) ; } }
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 ( $ digest , $ sign , $ this -> secretKey , OPENSSL_PKCS1_OAEP_PADDING ) ; if ( ! $ result ) { throw new EndpointException ( "Request signing failed" ) ; } return rawurlencode ( base64_encode ( $ sign ) ) ; }
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 -> accessToken ; } return $ headers ; }
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" ] : $ _SERVER [ "SERVER_NAME" ] ) ; } return $ origin ; }
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 ) ; return true ; } return false ; }
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 ) { return false ; } $ this -> object [ 'path' ] = $ path ; $ this -> object [ 'response' ] = $ response ; $ all_headers = array ( ) ; $ cache_headers = array ( ) ; $ headers = explode ( "\r\n" , $ header ) ; foreach ( $ headers as $ h ) { $ a = explode ( ':' , $ h ) ; if ( count ( $ a ) == 2 ) { $ all_headers [ trim ( $ a [ 0 ] ) ] = trim ( $ a [ 1 ] ) ; } } if ( array_key_exists ( 'Cache-Control' , $ all_headers ) ) { preg_match ( '/max-age=(\d+)/' , $ all_headers [ 'Cache-Control' ] , $ cache_headers ) ; } if ( count ( $ cache_headers ) ) { $ this -> __debug ( "got cache-control for $path, cache is valid for {$cache_headers[1]} seconds" ) ; $ this -> object [ 'cache' ] = ( int ) ( time ( ) + $ cache_headers [ 1 ] ) ; } else { $ this -> __debug ( "no cache-control for $path, caching for {$this->cacheTime} seconds" ) ; $ this -> object [ 'cache' ] = ( int ) ( time ( ) + $ this -> cacheTime ) ; } $ etag = array_key_exists ( 'Etag' , $ all_headers ) ? preg_replace ( '/"/' , '' , $ all_headers [ 'Etag' ] ) : null ; if ( strlen ( $ etag ) ) { $ this -> __debug ( "new etag for $path" ) ; $ this -> object [ 'etag' ] = $ etag ; } else { $ this -> __debug ( "no etag for $path" ) ; } $ this -> backend -> delete ( $ path ) ; $ this -> backend -> put ( $ this -> object ) ; return true ; }
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 ) { foreach ( $ this -> nodes as $ c ) { $ c -> dump ( $ show_attr , $ deep + 1 ) ; } } }
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 -> outertext ( ) ; } return $ ret ; }
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 ( ) ) { return true ; } throw new NotFound ( ) ; }
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' ] ) ) { throw new NotFound ( ) ; } if ( ! $ this -> endpointMethodExists ( $ cachedRoutes [ $ this -> requestUri ] [ 'matchedEndpoint' ] , $ this -> requestMethod ) ) { throw new MethodNotAllowed ( ) ; } $ this -> matchedRoute = $ cachedRoutes [ $ this -> requestUri ] [ 'matchedRoute' ] ; $ this -> matchedEndpoint = $ cachedRoutes [ $ this -> requestUri ] [ 'matchedEndpoint' ] ; $ this -> matchedMethod = $ this -> requestMethod ; $ this -> params = ( isset ( $ cachedRoutes [ $ this -> requestUri ] [ 'params' ] ) ) ? $ cachedRoutes [ $ this -> requestUri ] [ 'params' ] : [ ] ; return true ; } } } return false ; }
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 ) ) { throw new NotFound ( ) ; } elseif ( ! $ this -> endpointMethodExists ( $ endpoint , $ this -> requestMethod ) ) { throw new MethodNotAllowed ( ) ; } $ this -> matchedRoute = $ route ; $ this -> matchedEndpoint = $ endpoint ; $ this -> matchedMethod = $ this -> requestMethod ; $ matches = array_diff ( $ matches , [ '/' ] ) ; array_shift ( $ matches ) ; foreach ( $ paramNames as $ key => $ name ) { $ this -> params [ $ name ] = ( isset ( $ matches [ $ key ] ) ) ? $ matches [ $ key ] : null ; } $ this -> addToCache ( $ this -> requestUri ) ; return true ; } } return false ; }
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' ) ) { $ cachedRoutes [ $ requestUri ] = $ toCache ; } else { $ cachedRoutes = [ $ requestUri => $ toCache ] ; } $ this -> cache -> set ( 'routeMiddlewareRoutes' , $ cachedRoutes ) ; } }
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 -> setPersistence ( $ persistence ) ; return $ 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 ( $ mapping ) ; $ metadata -> setSearch ( $ search ) ; return $ metadata ; }
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 ; } if ( ! isset ( $ mapping [ 'entity' ] ) ) { $ mapping [ 'entity' ] = null ; } if ( $ metadata instanceof Metadata \ EmbedMetadata && $ mapping [ 'entity' ] === $ metadata -> name ) { $ embedMeta = $ metadata ; } else { $ embedMeta = $ this -> loadMetadataForEmbed ( $ mapping [ 'entity' ] ) ; } if ( null === $ embedMeta ) { continue ; } $ property = new Metadata \ EmbeddedPropMetadata ( $ key , $ mapping [ 'type' ] , $ embedMeta , $ this -> isMixin ( $ metadata ) ) ; if ( isset ( $ mapping [ 'serialize' ] ) ) { $ property -> enableSerialize ( $ mapping [ 'serialize' ] ) ; } $ metadata -> addEmbed ( $ property ) ; } return $ metadata ; }
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 ] , 'disconnected' ) ) { $ workingSlaves [ ] = new Client ( $ slave [ 3 ] , $ slave [ 5 ] , null , '' , 0 , $ this -> _authPassword ) ; } } return $ workingSlaves ; }
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 -> _cluster [ $ name ] ; }
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' , 'password' ] , $ config_keys ) ; if ( count ( $ missing ) > 0 ) { throw new DatabaseConnectionException ( 'LDAP configuration missing ' . implode ( ', ' , $ missing ) ) ; } return true ; }
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 -> handle ) ) ) ; if ( ldap_errno ( $ this -> handle ) == '49' ) { throw new DatabaseConnectionException ( 'Unable to connect to LDAP server.' ) ; } else { throw new DatabaseConnectionException ( 'A problem occurred when binding to the LDAP server.' ) ; } } }
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 , $ item = $ this -> children [ $ parentId ] ) ; $ parentId = $ item -> getParentId ( ) ; } return $ 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 = strpos ( $ line , ' ' ) ) { $ key = substr ( $ line , 1 ) ; $ val = true ; } else { $ key = substr ( $ line , 1 , $ fws - 1 ) ; $ val = trim ( substr ( $ line , $ fws ) ) ; } $ this -> lines [ ] = [ $ key , $ val ] ; $ this -> declares [ $ key ] [ ] = $ val ; } }
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 ) ) ; } $ builder -> add ( 'text' , TextareaType :: class , array ( 'attr' => array ( 'class' => empty ( $ options [ 'html' ] [ 'enabled' ] ) ? 'synapse-simple-editor' : 'synapse-rich-editor' , 'data-editor-config' => json_encode ( $ options [ 'ckeditor_config' ] ) , ) , ) ) ; if ( ! empty ( $ options [ 'images' ] ) ) { $ builder -> add ( 'images' , ImageChoiceType :: class , array ( 'image_formats' => $ options [ 'images' ] [ 'format' ] , 'required' => false , 'expanded' => false , 'multiple' => ! empty ( $ options [ 'images' ] [ 'multiple' ] ) , ) ) ; } if ( ! empty ( $ options [ 'read_more' ] [ 'enabled' ] ) ) { $ builder -> add ( 'link' , SymfonyTextType :: class , array ( 'required' => false , ) ) -> add ( 'link_label' , SymfonyTextType :: 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 -> parseUrlComponents ( $ str ) ; $ components = array_replace ( [ 'scheme' => '' , 'host' => '' , 'port' => '' , 'user' => '' , 'pass' => '' , 'path' => '' , 'query' => '' , 'fragment' => '' ] , $ components ) ; $ this -> scheme -> parseComponent ( $ components [ 'scheme' ] ) ; $ this -> host -> parseComponent ( $ components [ 'host' ] ) ; $ this -> port -> parseComponent ( strval ( $ components [ 'port' ] ) ) ; if ( empty ( $ components [ 'user' ] ) && empty ( $ components [ 'pass' ] ) ) { $ this -> credentials -> username = null ; $ this -> credentials -> password = null ; } else { $ this -> credentials -> parseComponent ( $ components [ 'user' ] . ':' . $ components [ 'pass' ] ) ; } $ this -> path -> parseComponent ( $ components [ 'path' ] ) ; $ this -> query -> parseComponent ( $ components [ 'query' ] ) ; $ this -> fragment -> parseComponent ( $ components [ 'fragment' ] ) ; return $ this ; }
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 ( ) ) { throw new InvalidUrlException ( sprintf ( 'Cannot make absolute URL from "%s" because the given base URL "%s" is not absolute.' , $ this , $ baseUrl ) ) ; } if ( $ this -> isAbsolute ( ) ) { if ( $ this -> scheme -> isEmpty ( ) ) { $ this -> scheme -> set ( $ baseUrl -> scheme ) ; } return $ this ; } if ( ! $ this -> path -> isAbsolute ( ) ) { $ relPath = Path :: info ( $ this -> path -> get ( ) ) ; $ baseDir = $ baseUrl -> path -> isEmpty ( ) ? '/' : Path :: info ( $ baseUrl -> path -> get ( ) ) -> dir ( ) ; $ absPath = $ relPath -> abs ( $ baseDir ) -> normalize ( ) ; $ this -> path -> set ( $ absPath ) ; } $ this -> scheme -> set ( $ baseUrl -> scheme ) ; $ this -> credentials -> username = $ baseUrl -> credentials -> username ; $ this -> credentials -> password = $ baseUrl -> credentials -> password ; $ this -> host -> set ( $ baseUrl -> host ) ; $ this -> port -> set ( $ baseUrl -> port ) ; return $ this ; }
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 ( ) ; } if ( $ baseUrl -> isEmpty ( ) ) { throw new InvalidUrlException ( ) ; } if ( ! $ baseUrl -> path -> isAbsolute ( ) ) { throw new InvalidUrlException ( ) ; } if ( $ this -> isAbsolute ( ) ) { return $ this ; } if ( ! $ this -> path -> isAbsolute ( ) ) { $ relPath = Path :: info ( $ this -> path -> get ( ) ) ; $ baseDir = Path :: info ( $ baseUrl -> path -> get ( ) ) -> dir ( ) ; $ absPath = $ relPath -> abs ( $ baseDir ) -> normalize ( ) ; $ this -> path -> set ( $ absPath ) ; } return $ this ; }
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 ; $ creds = ( $ opt & self :: CREDENTIALS ) === self :: CREDENTIALS ; $ path = ( $ opt & self :: PATH ) === self :: PATH ; $ query = ( $ opt & self :: QUERY ) === self :: QUERY ; $ fragment = ( $ opt & self :: FRAGMENT ) === self :: FRAGMENT ; if ( $ scheme ) { $ this -> scheme -> clear ( ) ; } if ( $ host ) { $ this -> host -> clear ( ) ; } if ( $ port ) { $ this -> port -> clear ( ) ; } if ( $ creds ) { $ this -> credentials -> clear ( ) ; } if ( $ path ) { $ this -> path -> clear ( ) ; } if ( $ query ) { $ this -> query -> clear ( ) ; } if ( $ fragment ) { $ this -> fragment -> clear ( ) ; } return $ this ; }
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 ( $ query ) { $ this -> query -> clear ( ) ; } if ( $ fragment ) { $ this -> fragment -> clear ( ) ; } return $ this ; }
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 ) === self :: CREDENTIALS ; if ( $ scheme ) { $ this -> scheme -> clear ( ) ; } if ( $ host ) { $ this -> host -> clear ( ) ; } if ( $ port ) { $ this -> port -> clear ( ) ; } if ( $ creds ) { $ this -> credentials -> clear ( ) ; } return $ this ; }
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 InvalidUrlException ( ) ; } $ scheme = ( $ opt & self :: SCHEME ) === self :: SCHEME ; $ host = ( $ opt & self :: HOST ) === self :: HOST ; $ port = ( $ opt & self :: PORT ) === self :: PORT ; $ creds = ( $ opt & self :: CREDENTIALS ) === self :: CREDENTIALS ; $ path = ( $ opt & self :: PATH ) === self :: PATH ; $ query = ( $ opt & self :: QUERY ) === self :: QUERY ; $ fragment = ( $ opt & self :: FRAGMENT ) === self :: FRAGMENT ; if ( $ scheme ) { $ this -> scheme -> set ( $ url -> scheme -> get ( ) ) ; } if ( $ host ) { $ this -> host -> set ( $ url -> host -> get ( ) ) ; } if ( $ port ) { $ this -> port -> set ( $ url -> port -> get ( ) ) ; } if ( $ creds ) { $ this -> credentials -> username = $ url -> credentials -> username ; $ this -> credentials -> password = $ url -> credentials -> password ; } if ( $ path ) { $ this -> path -> set ( $ url -> path -> get ( ) ) ; } if ( $ query ) { $ this -> query -> parseComponent ( $ url -> query -> __toString ( ) ) ; } if ( $ fragment ) { $ this -> fragment -> set ( $ url -> fragment -> get ( ) ) ; } return $ this ; }
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 :: SCHEME ) === self :: SCHEME ; $ host = ( $ opt & self :: HOST ) === self :: HOST ; $ port = ( $ opt & self :: PORT ) === self :: PORT ; $ creds = ( $ opt & self :: CREDENTIALS ) === self :: CREDENTIALS ; if ( $ scheme ) { $ this -> scheme -> set ( $ url -> scheme -> get ( ) ) ; } if ( $ host ) { $ this -> host -> set ( $ url -> host -> get ( ) ) ; } if ( $ port ) { $ this -> port -> set ( $ url -> port -> get ( ) ) ; } if ( $ creds ) { $ this -> credentials -> username = $ url -> credentials -> username ; $ this -> credentials -> password = $ url -> credentials -> password ; } return $ this ; }
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 ) ; } else { throw new InvalidUrlException ( ) ; } $ path = ( $ opt & self :: PATH ) === self :: PATH ; $ query = ( $ opt & self :: QUERY ) === self :: QUERY ; $ fragment = ( $ opt & self :: FRAGMENT ) === self :: FRAGMENT ; if ( $ path ) { $ this -> path -> set ( $ url -> path -> get ( ) ) ; } if ( $ query ) { $ this -> query -> parseComponent ( $ url -> query -> __toString ( ) ) ; } if ( $ fragment ) { $ this -> fragment -> set ( $ url -> fragment -> get ( ) ) ; } return $ this ; }
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 InvalidUrlException ( ) ; } $ scheme = ( $ opt & self :: SCHEME ) === self :: SCHEME ; $ host = ( $ opt & self :: HOST ) === self :: HOST ; $ port = ( $ opt & self :: PORT ) === self :: PORT ; $ creds = ( $ opt & self :: CREDENTIALS ) === self :: CREDENTIALS ; $ path = ( $ opt & self :: PATH ) === self :: PATH ; $ query = ( $ opt & self :: QUERY ) === self :: QUERY ; $ fragment = ( $ opt & self :: FRAGMENT ) === self :: FRAGMENT ; if ( $ scheme && ! $ this -> scheme -> equals ( $ url -> scheme ) ) { return false ; } if ( $ host && ! $ this -> host -> equals ( $ url -> host ) ) { return false ; } if ( $ port && ! $ this -> port -> equals ( $ url -> port ) ) { return false ; } if ( $ creds && ! $ this -> credentials -> equals ( $ url -> credentials ) ) { return false ; } if ( $ path && ! $ this -> path -> equals ( $ url -> path ) ) { return false ; } if ( $ query && ! $ this -> query -> equals ( $ url -> query ) ) { return false ; } if ( $ fragment && ! $ this -> fragment -> equals ( $ url -> fragment ) ) { return false ; } return true ; }
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 false ; } $ requiresPath = ( ! $ this -> query -> isEmpty ( ) || ! $ this -> fragment -> isEmpty ( ) ) && ( ! $ this -> scheme -> isEmpty ( ) || ! $ this -> host -> isEmpty ( ) || ! $ this -> port -> isEmpty ( ) || ! $ this -> credentials -> isEmpty ( ) ) ; if ( $ requiresPath && $ this -> path -> isEmpty ( ) ) { return false ; } return true ; }
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 ( \ Exception $ e ) { $ result = [ 'error' => $ e -> getMessage ( ) ] ; } return $ this -> jsonResponse ( $ result ) ; }
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 ( ) ; break ; case 'object' : $ value = ( array ) $ value ; ksort ( $ value ) ; break ; case 'mixed' : $ value = serialize ( $ value ) ; break ; case 'array' : sort ( $ value ) ; break ; } $ hash [ $ key ] = $ value ; } foreach ( $ this -> metadata -> getEmbeds ( ) as $ key => $ embbedPropMeta ) { if ( true === $ embbedPropMeta -> isOne ( ) ) { $ embed = $ this -> get ( $ key ) ; $ hash [ $ key ] = ( null === $ embed ) ? null : $ embed -> getHash ( ) ; } else { $ collection = $ this -> get ( $ key ) ; $ hash [ $ key ] = $ collection -> getHash ( ) ; } } ksort ( $ hash ) ; return md5 ( serialize ( $ hash ) ) ; }
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 ) { if ( substr ( $ key , - 2 ) === '[]' ) { $ this -> keys [ substr ( $ key , 0 , - 2 ) ] = $ value ; } else { $ this -> keys [ $ key ] = $ value ; } } return true ; }
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 isset ( $ matches [ 0 ] ) === true ; }
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 ( $ id_properties ) == 1 ) { $ ref -> id = $ properties [ $ id_properties [ 0 ] ] ; } else { $ id = array ( ) ; foreach ( $ id_properties as $ k ) { $ id [ ] = $ properties [ $ k ] ; } $ ref -> id = $ id ; } return $ ref ; }
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 -> targetClass ) ; }
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 '%s' was defined as target to annotations handling." , $ this -> targetClass ) ) ; } $ annotationsObjects = array ( ) ; $ this -> annotations [ $ this -> targetMethod ] = $ this -> getMethodAnnotationsObjects ( $ this -> targetClass , $ this -> targetMethod ) ; }
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_' , $ this -> annotations ) ) { $ this -> loadClassAnnotations ( ) ; } if ( array_key_exists ( $ annotationName , $ this -> annotations [ '_class_' ] ) ) { $ annotationInstance = $ this -> annotations [ '_class_' ] [ $ annotationName ] ; } } else { if ( ! array_key_exists ( $ this -> targetMethod , $ this -> annotations ) ) { $ this -> loadMethodAnnotations ( ) ; } if ( array_key_exists ( $ annotationName , $ this -> annotations [ $ this -> targetMethod ] ) ) { $ annotationInstance = $ this -> annotations [ $ this -> targetMethod ] [ $ annotationName ] ; } } return $ annotationInstance ; }
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 += [ "driver" => "pdo_mysql" ] ; } if ( ! isset ( $ parameters [ "charset" ] ) ) { $ parameters += [ "charset" => "utf8" , "driverOptions" => [ 1002 => "SET NAMES UTF8" ] ] ; } return $ parameters ; }
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 ( 'Scheme must be one of http or https' ) ; } if ( empty ( $ info [ 'port' ] ) ) { $ port = $ info [ 'scheme' ] == 'https' ? 443 : 80 ; } else { $ port = intval ( $ info [ 'port' ] ) ; } return array ( 'scheme' => $ info [ 'scheme' ] , 'host' => $ info [ 'host' ] , 'port' => $ port , 'path' => ! empty ( $ info [ 'path' ] ) ? trim ( $ info [ 'path' ] , '/' ) : '' , ) ; }
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 ) ; } $ this -> logger -> info ( 'DB QUERY: ' . $ this -> result -> queryString ) ; $ this -> result -> execute ( $ params ) ; if ( null === $ this -> result -> errorCode ( ) ) { $ this -> logger -> info ( 'PARAMS: ' . implode ( '|' , $ params ) ) ; $ this -> logger -> error ( 'DB ERROR: The query could not be executed - unknown error.' ) ; $ this -> logger -> debug ( 'Test Query: ' . $ test_query ) ; throw new DatabaseQueryException ( $ this -> result -> errorInfo ( ) [ 2 ] ) ; } elseif ( preg_match ( '/^00000$/' , $ this -> result -> errorCode ( ) ) ) { $ this -> logger -> debug ( 'DB Success: ' . implode ( '|' , $ params ) ) ; } elseif ( preg_match ( '/^(00|01)/' , $ this -> result -> errorCode ( ) ) ) { $ this -> logger -> info ( 'PARAMS: ' . implode ( '|' , $ params ) ) ; $ this -> logger -> warning ( 'DB WARN: ' . $ this -> result -> errorCode ( ) . ' -- ' . $ this -> result -> errorInfo ( ) [ 2 ] ) ; $ this -> logger -> debug ( 'Test Query: ' . $ test_query ) ; } else { $ this -> logger -> info ( 'PARAMS: ' . implode ( '|' , $ params ) ) ; $ this -> logger -> error ( 'DB ERROR: ' . $ this -> result -> errorCode ( ) . ' -- ' . $ this -> result -> errorInfo ( ) [ 2 ] ) ; $ this -> logger -> debug ( 'Test Query: ' . $ test_query ) ; throw new DatabaseQueryException ( $ this -> result -> errorInfo ( ) [ 2 ] ) ; } return $ this ; }
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 ) : $ className ; }
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 ( file_exists ( $ path ) ) { require_once ( $ path ) ; } else if ( self :: oldModule ( $ className , $ nameSpace , $ path ) ) { require_once ( $ path ) ; } else { return e ( 'Class name ## not found' , E_SAMSON_CORE_ERROR , $ class ) ; } } else { require_once ( __DIR__ . '/' . $ className . '.php' ) ; } return true ; }
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 ( 'php' , 'js' , 'cms' , 'social' , 'commerce' ) as $ type ) { $ locations = array ( __SAMSON_VENDOR_PATH . str_replace ( 'samson/' , 'samsonos/' , $ ns ) . '/' . strtolower ( $ className ) , __SAMSON_VENDOR_PATH . str_replace ( 'samson/' , 'samsonos/' , $ ns ) , __SAMSON_VENDOR_PATH . str_replace ( 'samson/' , 'samsonos/' . $ type . '/' , $ ns ) , __SAMSON_VENDOR_PATH . str_replace ( 'samson/' , 'samsonos/' . $ type . '/' , $ ns ) . '/api' , __SAMSON_VENDOR_PATH . str_replace ( 'samson/' , 'samsonos/' . $ type . '_' , $ ns ) , strpos ( $ ns , 'cms' ) !== false ? __SAMSON_VENDOR_PATH . 'samsonos/cms_api' : '_' , strpos ( $ ns , 'cms' ) !== false ? __SAMSON_VENDOR_PATH . 'samsonos/cms/api' : '_' , __SAMSON_CWD__ . __SAMSON_MODEL_PATH , ) ; foreach ( $ locations as $ location ) { if ( file_exists ( $ location ) ) { $ path = $ location ; break 2 ; } } } } if ( isset ( $ path ) ) { $ path .= '/' ; if ( ! isset ( self :: $ fileCache [ $ nameSpace ] ) ) { self :: $ fileCache [ $ nameSpace ] = File :: dir ( $ path , 'php' ) ; } if ( sizeof ( $ files = preg_grep ( '/\/' . $ className . '\.php/i' , self :: $ fileCache [ $ nameSpace ] ) ) ) { if ( sizeof ( $ files ) > 1 ) { return e ( 'Cannot autoload class(##), too many files matched ##' , E_SAMSON_CORE_ERROR , array ( $ className , $ files ) ) ; } $ file = end ( $ files ) ; return true ; } } return false ; }
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_Filesystem ( $ viewsDir ) ; $ twig = new \ Twig_Environment ( $ loader , array ( ) ) ; $ twig -> getExtension ( 'core' ) -> setTimezone ( 'Europe/Warsaw' ) ; $ twig -> addExtension ( new EscapePLCharsExtension ( ) ) ; return $ twig ; } catch ( Exception $ e ) { echo "ERR: " . $ e ; } }
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 : { url : \'' . $ url . '\', data: { _token: \'' . csrf_token ( ) . '\' }, loadByIdentifier: true }, unique : true,' . ( Arr :: has ( $ options , 'js.resultFormatterId' ) ? 'resultFormat: $(\'#' . Arr :: get ( $ options , 'js.resultFormatterId' ) . '\').html(),' : '' ) . ' preloaded: ' . Arr :: get ( $ options , 'js.preloaded' , new Collection ( ) ) -> toJson ( ) . ', disabled : ' . ( Arr :: get ( $ options , 'disabled' , false ) ? 'true' : 'false' ) . ' }); }(jQuery));</script>' ; return $ this -> text ( $ name , $ value , $ options ) . $ script ; }
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 ( ) -> fetchAll ( $ sql , [ 'token' => $ accessToken -> getId ( ) ] ) as $ row ) { if ( $ row ) { return ( new SessionEntity ( $ this -> server ) ) -> setId ( $ row [ 'id' ] ) -> setOwner ( $ row [ 'owner_type' ] , $ row [ 'owner_id' ] ) ; } } return null ; }
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 ( ) -> fetchAll ( $ sql , [ 'authCode' => $ authCode -> getId ( ) ] ) as $ row ) { if ( $ row ) { return ( new SessionEntity ( $ this -> server ) ) -> setId ( $ row [ 'id' ] ) -> setOwner ( $ row [ 'owner_type' ] , $ row [ 'owner_id' ] ) ; } } return null ; }
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' => $ session -> getId ( ) ] ) as $ row ) { if ( $ row ) { return ( new ScopeEntity ( $ this -> server ) ) -> hydrate ( [ 'id' => $ row [ 'id' ] , 'description' => $ row [ 'description' ] ] ) ; } } return null ; }
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 .