idx
int64
0
60.3k
question
stringlengths
92
4.62k
target
stringlengths
7
635
17,300
public function saveCallbackMultiEdit ( $ value , $ dc ) { if ( $ GLOBALS [ 'TL_DCA' ] [ $ dc -> table ] [ 'fields' ] [ $ dc -> field ] [ 'inputType' ] === 'fileTree' || $ GLOBALS [ 'TL_DCA' ] [ $ dc -> table ] [ 'fields' ] [ $ dc -> field ] [ 'inputType' ] === 'fineUploader' ) { $ value = $ this -> uuidBinToText ( $ v...
Field save callback multi edit
17,301
public function saveDataCallback ( $ value , $ dc ) { $ this -> prepareSaveData ( 'rsce_field_' , $ this -> fieldsConfig ) ; $ data = json_encode ( $ this -> saveData ) ; if ( $ data === '[]' ) { $ data = '{}' ; } return $ data ; }
rsce_data field save callback
17,302
protected function prepareSaveData ( $ fieldPrefix , $ fieldsConfig ) { foreach ( $ fieldsConfig as $ fieldName => $ fieldConfig ) { if ( isset ( $ fieldConfig [ 'inputType' ] ) && $ fieldConfig [ 'inputType' ] === 'list' ) { $ fieldData = $ this -> getNestedValueReference ( $ fieldPrefix . $ fieldName ) ; for ( $ data...
prepare the data to save and create empty arrays for empty lists
17,303
protected function createDca ( $ dc , $ type , $ createFromPost = false , $ tmpField = null ) { $ config = static :: getConfigByType ( $ type ) ; if ( ! $ config ) { return ; } $ assetsDir = 'bundles/rocksolidcustomelements' ; if ( TL_MODE === 'BE' ) { $ GLOBALS [ 'TL_JAVASCRIPT' ] [ ] = $ assetsDir . '/js/be_main.js' ...
Create all DCA fields for the specified type
17,304
protected function wasListFieldSubmitted ( $ fieldName , $ dataKey ) { if ( ! is_array ( \ Input :: post ( 'FORM_FIELDS' ) ) ) { return false ; } if ( strpos ( $ fieldName , '__rsce_dummy__' ) !== false ) { return false ; } $ formFields = array_unique ( \ StringUtil :: trimsplit ( '[,;]' , implode ( ',' , \ Input :: po...
Check if a field was sumitted via POST
17,305
protected function createDcaItemListDummy ( $ fieldPrefix , $ fieldName , $ fieldConfig , & $ paletteFields , $ dc , $ createFromPost ) { $ dataKey = 'rsce_dummy' ; $ GLOBALS [ 'TL_DCA' ] [ $ dc -> table ] [ 'fields' ] [ $ fieldPrefix . $ fieldName . '__' . $ dataKey . '_rsce_list_item_start' ] = array ( 'inputType' =>...
Create one list item dummy with the specified parameters
17,306
protected function createDcaMultiEdit ( $ dc ) { $ session = \ System :: getContainer ( ) -> get ( 'session' ) -> all ( ) ; if ( empty ( $ session [ 'CURRENT' ] [ 'IDS' ] ) || ! is_array ( $ session [ 'CURRENT' ] [ 'IDS' ] ) ) { return ; } $ ids = $ session [ 'CURRENT' ] [ 'IDS' ] ; $ types = \ Database :: getInstance ...
Create all DCA standard fields for multi edit mode
17,307
public static function getConfigByType ( $ type ) { $ configPath = null ; try { $ templatePaths = CustomTemplate :: getTemplates ( $ type ) ; if ( ! empty ( $ templatePaths [ 0 ] ) ) { $ configPath = substr ( $ templatePaths [ 0 ] , 0 , - 6 ) . '_config.php' ; } } catch ( \ Exception $ e ) { $ configPath = null ; } if ...
Get configuration array for the specified type
17,308
protected static function generatePalette ( $ table , array $ paletteFields = array ( ) , array $ standardFields = array ( ) ) { $ palette = '' ; if ( $ table === 'tl_module' ) { $ palette .= '{title_legend},name' ; if ( in_array ( 'headline' , $ standardFields ) ) { $ palette .= ',headline' ; } $ palette .= ',type' ; ...
Generates the palette definition
17,309
public static function purgeCache ( ) { $ filePaths = static :: getCacheFilePaths ( ) ; if ( file_exists ( $ filePaths [ 'fullPath' ] ) ) { $ file = new \ File ( $ filePaths [ 'path' ] , true ) ; $ file -> write ( '' ) ; $ file -> close ( ) ; static :: refreshOpcodeCache ( $ filePaths [ 'fullPath' ] ) ; } }
Purge cache file rocksolid_custom_elements_config . php
17,310
public static function getCacheFilePaths ( ) { $ cacheDir = \ System :: getContainer ( ) -> getParameter ( 'kernel.cache_dir' ) . '/contao' ; $ fileFullPath = $ cacheDir . '/rocksolid_custom_elements_config.php' ; $ filePath = $ fileFullPath ; if ( substr ( $ filePath , 0 , strlen ( TL_ROOT ) + 1 ) === TL_ROOT . '/' ||...
Get path and fullPath to the cache file
17,311
protected static function refreshOpcodeCache ( $ path ) { try { if ( function_exists ( 'opcache_invalidate' ) ) { opcache_invalidate ( $ path , true ) ; } if ( function_exists ( 'accelerator_reset' ) ) { accelerator_reset ( ) ; } if ( function_exists ( 'apc_compile_file' ) && ! ini_get ( 'apc.stat' ) ) { apc_compile_fi...
Refreshes all active opcode caches for the specified file
17,312
public static function getLabelTranslated ( $ labelConfig ) { if ( ! is_array ( $ labelConfig ) ) { return $ labelConfig ; } if ( ! count ( array_filter ( array_keys ( $ labelConfig ) , 'is_string' ) ) ) { return $ labelConfig ; } $ language = str_replace ( '-' , '_' , $ GLOBALS [ 'TL_LANGUAGE' ] ) ; if ( isset ( $ lab...
Return translated label if label configuration contains language keys
17,313
public function exportThemeHook ( $ xml , $ zipArchive , $ themeId ) { $ xpath = new \ DOMXPath ( $ xml ) ; $ tlModule = $ xpath -> query ( '/tables/table[@name = \'tl_module\']' ) -> item ( 0 ) ; if ( ! $ tlModule ) { return ; } static :: reloadConfig ( ) ; foreach ( $ tlModule -> childNodes as $ row ) { if ( strtolow...
Convert IDs for theme export
17,314
public function extractThemeFilesHook ( $ xml , $ zipArchive , $ themeId , $ idMappingData ) { $ modules = \ ModuleModel :: findBy ( array ( 'tl_module.pid = ? AND tl_module.type LIKE \'rsce_%\'' ) , $ themeId ) ; if ( ! $ modules || ! count ( $ modules ) ) { return ; } foreach ( $ modules as $ module ) { if ( substr (...
Convert IDs for theme import
17,315
private function uuidBinToText ( $ value ) { if ( trim ( $ value ) && $ value !== 'a:1:{i:0;s:0:"";}' ) { if ( strlen ( $ value ) === 16 ) { return \ StringUtil :: binToUuid ( $ value ) ; } return serialize ( array_map ( 'StringUtil::binToUuid' , \ StringUtil :: deserialize ( $ value ) ) ) ; } return '' ; }
Convert binary UUIDs to text
17,316
private function uuidTextToBin ( $ value ) { if ( substr ( $ value , 0 , 2 ) === 'a:' ) { return serialize ( array_map ( function ( $ value ) { if ( strlen ( $ value ) === 36 ) { $ value = \ StringUtil :: uuidToBin ( $ value ) ; } return $ value ; } , \ StringUtil :: deserialize ( $ value ) ) ) ; } if ( strlen ( $ valu...
Convert text UUIDs to binary
17,317
protected function shouldEncrypt ( $ key ) { $ encrypt = isset ( $ this -> encrypts ) ? $ this -> encrypts : $ this -> encryptable ; return in_array ( $ key , $ encrypt ) ; }
Determine whether an attribute should be encrypted .
17,318
protected function doEncryptAttribute ( $ key ) { if ( $ this -> shouldEncrypt ( $ key ) && ! $ this -> isEncrypted ( $ this -> attributes [ $ key ] ) ) { try { $ this -> attributes [ $ key ] = $ this -> encryptedAttribute ( $ this -> attributes [ $ key ] ) ; } catch ( EncryptException $ e ) { } } }
Encrypt a stored attribute .
17,319
protected function doDecryptAttribute ( $ key , $ value ) { if ( $ this -> shouldEncrypt ( $ key ) && $ this -> isEncrypted ( $ value ) ) { try { return $ this -> decryptedAttribute ( $ value ) ; } catch ( DecryptException $ e ) { } } return $ value ; }
Decrypt an attribute if required .
17,320
public function doDecryptAttributes ( $ attributes ) { foreach ( $ attributes as $ key => $ value ) { $ attributes [ $ key ] = $ this -> doDecryptAttribute ( $ key , $ value ) ; } return $ attributes ; }
Decrypt each attribute in the array as required .
17,321
public function onClientError ( ClientErrorEvent $ event ) { $ conn = $ event -> getConnection ( ) ; $ e = $ event -> getException ( ) ; echo "connection error occurred: " . $ e -> getMessage ( ) . PHP_EOL ; }
Called whenever a client errors
17,322
private function setupServer ( ) { $ this -> setupApp ( ) ; $ this -> loop = \ React \ EventLoop \ Factory :: create ( ) ; $ this -> socket = new \ React \ Socket \ Server ( $ this -> loop ) ; if ( $ this -> host ) { $ this -> socket -> listen ( $ this -> port , $ this -> host ) ; } else { $ this -> socket -> listen ( ...
Sets up loop and server manually to allow periodic timer calls .
17,323
private function setupApp ( ) { if ( $ this -> session instanceof \ SessionHandlerInterface ) { $ serverStack = new SessionProvider ( new WampServer ( $ this -> getContainer ( ) -> get ( "jdare_clank.clank_app" ) ) , $ this -> session ) ; } else { $ serverStack = new WampServer ( $ this -> getContainer ( ) -> get ( "jd...
Sets up clank app to bootstrap Ratchet and handle socket requests
17,324
public function onSubscribe ( Conn $ conn , $ topic ) { $ topic -> broadcast ( $ conn -> resourceId . " has joined " . $ topic -> getId ( ) ) ; }
This will receive any Subscription requests for this exact topic .
17,325
public function onUnSubscribe ( Conn $ conn , $ topic ) { $ topic -> broadcast ( $ conn -> resourceId . " has left " . $ topic -> getId ( ) ) ; }
This will receive any UnSubscription requests for this exact topic .
17,326
public function onPublish ( Conn $ conn , $ topic , $ event , array $ exclude , array $ eligible ) { $ topic -> broadcast ( array ( "sender" => $ conn -> resourceId , "topic" => $ topic -> getId ( ) , "event" => $ event ) ) ; }
This will receive any Publish requests for this exact topic .
17,327
public static function login ( $ ck , $ cs , $ username , $ password , $ proxy = '' ) { $ to = new self ( $ ck , $ cs ) ; $ username = self :: validateString ( '$username' , $ username ) ; $ password = self :: validateString ( '$password' , $ password ) ; $ proxy = self :: validateString ( '$proxy' , $ proxy ) ; $ ch =...
Execute direct OAuth login .
17,328
public function getAuthenticateUrl ( $ force_login = false ) { $ params = http_build_query ( array ( 'oauth_token' => $ this -> ot , 'force_login' => $ force_login ? 1 : null , ) , '' , '&' ) ; return 'https://api.twitter.com/oauth/authenticate?' . $ params ; }
Get URL for authentication .
17,329
public function getAuthorizeUrl ( $ force_login = false ) { $ params = http_build_query ( array ( 'oauth_token' => $ this -> ot , 'force_login' => $ force_login ? 1 : null , ) , '' , '&' ) ; return 'https://api.twitter.com/oauth/authorize?' . $ params ; }
Get URL for authorization .
17,330
public function get ( $ url , $ params = array ( ) , $ proxy = '' ) { $ ch = $ this -> curlGet ( $ url , $ params , $ proxy ) ; $ response = curl_exec ( $ ch ) ; return self :: decode ( $ ch , $ response ) ; }
Execute GET request .
17,331
public function getOut ( $ url , $ params = array ( ) , $ proxy = '' ) { $ ch = $ this -> curlGetOut ( $ url , $ params , $ proxy ) ; $ response = curl_exec ( $ ch ) ; return self :: decode ( $ ch , $ response ) ; }
Execute GET OAuth Echo request .
17,332
public function streaming ( $ url , $ callback , $ params = array ( ) , $ proxy = '' ) { curl_exec ( $ ch = $ this -> curlStreaming ( $ url , $ callback , $ params , $ proxy ) ) ; self :: checkCurlError ( $ ch ) ; }
Execute streaming POST request .
17,333
public function post ( $ url , $ params = array ( ) , $ proxy = '' ) { $ ch = $ this -> curlPost ( $ url , $ params , $ proxy ) ; $ response = curl_exec ( $ ch ) ; return self :: decode ( $ ch , $ response ) ; }
Execute POST request .
17,334
public function postOut ( $ url , $ params = array ( ) , $ proxy = '' ) { $ ch = $ this -> curlPostOut ( $ url , $ params , $ proxy ) ; $ response = curl_exec ( $ ch ) ; return self :: decode ( $ ch , $ response ) ; }
Execute POST OAuth Echo request .
17,335
public function postMultipart ( $ url , $ params = array ( ) , $ proxy = '' ) { $ ch = $ this -> curlPostMultipart ( $ url , $ params , $ proxy ) ; $ response = curl_exec ( $ ch ) ; return self :: decode ( $ ch , $ response ) ; }
Execute multipart POST request .
17,336
public function postMultipartOut ( $ url , $ params = array ( ) , $ proxy = '' ) { $ ch = $ this -> curlPostMultipartOut ( $ url , $ params , $ proxy ) ; $ response = curl_exec ( $ ch ) ; return self :: decode ( $ ch , $ response ) ; }
Execute multipart POST OAuth Echo request .
17,337
public function curlGet ( $ url , $ params = array ( ) , $ proxy = '' ) { return self :: curlGetAction ( $ url , $ params , false , $ proxy ) ; }
Prepare cURL resource for GET request .
17,338
public function curlGetOut ( $ url , $ params = array ( ) , $ proxy = '' ) { return self :: curlGetAction ( $ url , $ params , true , $ proxy ) ; }
Prepare cURL resource for GET OAuth Echo request .
17,339
public function curlStreaming ( $ url , $ callback , $ params = array ( ) , $ proxy = '' ) { static $ decode ; if ( ! $ decode ) { if ( version_compare ( PHP_VERSION , '5.4.0' ) < 0 ) { $ decode = function ( $ ch , $ response ) { static $ rm ; if ( ! $ rm ) { $ rm = new ReflectionMethod ( __CLASS__ , 'decode' ) ; $ rm ...
Prepare cURL resource for streaming POST request .
17,340
public function curlPost ( $ url , $ params = array ( ) , $ proxy = '' ) { return self :: curlPostAction ( $ url , $ params , false , $ proxy ) ; }
Prepare cURL resource for POST request .
17,341
public function curlPostOut ( $ url , $ params = array ( ) , $ proxy = '' ) { return self :: curlPostAction ( $ url , $ params , true , $ proxy ) ; }
Prepare cURL resource for POST OAuth Echo request .
17,342
public function curlPostMultipart ( $ url , $ params = array ( ) , $ proxy = '' ) { return self :: curlPostMultipartAction ( $ url , $ params , false , $ proxy ) ; }
Prepare cURL resource for multipart POST request .
17,343
public function curlPostMultipartOut ( $ url , $ params = array ( ) , $ proxy = '' ) { return self :: curlPostMultipartAction ( $ url , $ params , true , $ proxy ) ; }
Prepare cURL resource for multipart POST OAuth Echo request .
17,344
private static function curlInit ( $ proxy ) { $ ch = curl_init ( ) ; curl_setopt_array ( $ ch , array ( CURLOPT_FOLLOWLOCATION => ! ini_get ( 'safe_mode' ) && ( string ) ini_get ( 'open_basedir' ) === '' , CURLOPT_RETURNTRANSFER => true , CURLOPT_SSL_VERIFYPEER => true , CURLOPT_ENCODING => 'gzip' , CURLOPT_COOKIEJAR ...
Initialize cURL resource .
17,345
private static function curlSetOptForVerifier ( $ ch , $ to , $ authenticity_token , $ username , $ password ) { $ params = array ( 'session[username_or_email]' => $ username , 'session[password]' => $ password , 'authenticity_token' => $ authenticity_token , ) ; curl_setopt_array ( $ ch , array ( CURLOPT_URL => $ to -...
Set cURL options for oauth_verifier .
17,346
private static function validateParams ( $ name , $ params , array $ others ) { if ( is_array ( $ params ) ) { foreach ( $ params + $ others as $ key => $ value ) { if ( $ key === '' || $ value === null ) { unset ( $ params [ $ key ] ) ; continue ; } $ params [ $ key ] = self :: validateString ( "{$name}[$key]" , $ val...
Force parameters 1 - demensional array or query string .
17,347
private static function parseAuthenticityToken ( $ ch , $ response ) { static $ pattern = '@<input name="authenticity_token" type="hidden" value="([^"]++)">@' ; if ( ! preg_match ( $ pattern , $ response , $ matches ) ) { throw new TwistException ( 'Failed to get authenticity_token.' , curl_getinfo ( $ ch , CURLINFO_HT...
Parse authenticity_token .
17,348
private static function parseVerifier ( $ ch , $ response ) { static $ pattern = '@<code>([^<]++)</code>@' ; if ( ! preg_match ( $ pattern , $ response , $ matches ) ) { $ info = curl_getinfo ( $ ch ) ; throw new TwistException ( 'Wrong username or password.' , $ info [ 'http_code' ] ) ; } return $ matches [ 1 ] ; }
Parse oauth_verifier .
17,349
private function getAuthorization ( $ url , $ method , & $ params , $ flags ) { $ oauth = array ( 'oauth_consumer_key' => $ this -> ck , 'oauth_signature_method' => 'HMAC-SHA1' , 'oauth_timestamp' => time ( ) , 'oauth_version' => '1.0a' , 'oauth_nonce' => md5 ( mt_rand ( ) ) , 'oauth_token' => $ this -> ot , ) ; $ key ...
Prepare headers for authorization .
17,350
private function getOAuthEcho ( ) { $ url = 'https://api.twitter.com/1.1/account/verify_credentials.json' ; $ params = array ( ) ; $ headers = $ this -> getAuthorization ( $ url , 'GET' , $ params , 0 ) ; return array ( 'X-Auth-Service-Provider: ' . $ url , 'X-Verify-Credentials-Authorization: OAuth realm="http://api.t...
Prepare headers for OAuth Echo .
17,351
public function launch ( ) { foreach ( $ this -> getServers ( ) as $ server ) { $ server = $ this -> getContainer ( ) -> get ( $ server ) ; if ( ! $ server ) { throw new \ Exception ( "Unable to find Server Service." ) ; } if ( ! ( $ server instanceof ServerTypeInterface ) ) { throw new \ Exception ( "Server Service mu...
Launches the relevant servers needed by Clank .
17,352
protected function generateFilter ( $ bundle , $ entity , $ metadata , $ forceOverwrite = false , $ type = self :: FILTER_TYPE_INPUT ) { $ this -> getFilterGenerator ( $ bundle ) -> generate ( $ bundle , $ entity , $ metadata [ 0 ] , $ forceOverwrite , $ type ) ; }
Tries to generate filtlers if they don t exist yet and if we need write operations on entities .
17,353
public function getLogs ( $ integrationID = false , $ jobID = false ) { $ uri = "logs" ; if ( ! empty ( $ integrationID ) && ! empty ( $ jobID ) ) { $ uri = $ integrationID . "/jobs/" . $ jobID . "/logs" ; } return $ this -> call ( 'GET' , false , $ uri ) ; }
Return all logs
17,354
public function guessChoiceLabelFromClass ( $ entity ) { $ metadata = $ this -> metadataFactory -> getClassMetadata ( $ entity ) -> getMetadata ( ) ; foreach ( $ metadata [ 0 ] -> fieldMappings as $ fieldName => $ field ) { if ( $ field [ 'type' ] == 'string' ) { return $ fieldName ; } } return 'id' ; }
Trying to find string field in relation entity .
17,355
public function getReference ( $ client = false ) { if ( empty ( $ this -> reference ) ) { $ reference = $ this -> createReference ( ) ; if ( $ client ) { if ( isset ( $ _COOKIE [ $ client -> getCookieCartName ( ) ] ) ) { $ reference = $ _COOKIE [ $ client -> getCookieCartName ( ) ] ; } else { setcookie ( $ client -> g...
Get the cart reference If it isn t set or does not exist in storage we will create a new one and add it
17,356
public function addProduct ( $ id , $ qty = 1 , $ spec = [ ] ) { $ body = [ 'data' => [ 'type' => 'cart_item' , 'id' => $ id , 'quantity' => $ qty ] ] ; return $ this -> call ( 'POST' , $ body , $ this -> getReference ( ) . '/items' ) ; }
Add a Product to the Cart
17,357
public function addCustomItem ( $ name , $ sku , $ description , $ price , $ qty = 1 ) { $ body = [ 'data' => [ 'type' => 'custom_item' , 'name' => $ name , 'sku' => $ sku , 'description' => $ description , 'quantity' => $ qty , 'price' => [ 'amount' => $ price ] ] ] ; return $ this -> call ( 'POST' , $ body , $ this -...
Add a Custom Item to the Cart
17,358
public function updateItemQuantity ( $ id , $ quantity ) { $ body = [ 'data' => [ 'id' => $ id , 'quantity' => $ quantity ] ] ; return $ this -> call ( 'PUT' , $ body , $ this -> getReference ( ) . "/items/{$id}" ) ; }
Update an items quantity in a cart
17,359
private function getHeader ( $ name ) { if ( isset ( $ this -> headers [ $ name ] ) ) { return $ this -> headers [ $ name ] ; } return false ; }
Get a specific header
17,360
private function setDefaultHeaders ( ) { $ defaultHeaders = [ 'Content-Type' => 'application/json' , 'Accept' => 'application/json' , 'User-Agent' => Client :: UA , 'X-MOLTIN-SDK-LANGUAGE' => 'php' , 'X-MOLTIN-SDK-VERSION' => 'v2-dev' ] ; foreach ( $ defaultHeaders as $ name => $ value ) { if ( ! $ this -> getHeader ( ...
Set the default request headers
17,361
public function make ( ) { $ this -> setDefaultHeaders ( ) ; $ startTime = microtime ( true ) ; $ result = $ this -> httpClient -> request ( $ this -> getMethod ( ) , $ this -> getURL ( ) , $ this -> getPayload ( ) ) ; $ endTime = microtime ( true ) ; $ this -> response = new Response ( ) ; $ this -> response -> setExe...
Make a request
17,362
public function getAPIEndpoint ( $ uri = false ) { $ endpoint = $ this -> getBase ( ) . '/' . $ this -> getVersion ( ) . '/' ; if ( $ uri ) { $ endpoint .= $ uri ; } return $ endpoint ; }
Get the API endpoint for non authentication calls
17,363
public function pay ( $ gateway , $ method , $ paymentParams ) { return $ this -> call ( 'POST' , [ 'data' => $ this -> mergePayData ( $ gateway , $ method , $ paymentParams ) ] , $ this -> getID ( ) . '/payments' ) ; }
Pay for the order
17,364
public function getFileLocation ( $ file ) { if ( filter_var ( $ file , FILTER_VALIDATE_URL ) ) { $ localFile = '/tmp/moltinfile_' . rand ( 100000 , 900000 ) ; file_put_contents ( $ localFile , file_get_contents ( $ file ) ) ; } else { $ localFile = $ file ; } if ( ! file_exists ( $ localFile ) ) { throw new FileNotFou...
Get the file location given the value passed by the method call Will retrieve a remote file if the passed location is a URL
17,365
public function updateRelationships ( $ from , $ to , $ ids = null ) { return $ this -> makeRelationshipCall ( 'put' , $ from , $ to , $ ids , true ) ; }
Update relationships from a resource to other resources
17,366
public function deleteRelationships ( $ from , $ to , $ ids = null ) { return $ this -> makeRelationshipCall ( 'delete' , $ from , $ to , $ ids ) ; }
Delete relationships from a resource to other resources
17,367
public function buildRelationshipData ( $ type , $ ids ) { if ( $ ids === null || ( is_array ( $ ids ) && empty ( $ ids ) ) ) { return null ; } if ( is_string ( $ ids ) ) { return [ 'type' => $ type , 'id' => $ ids ] ; } $ data = [ ] ; if ( ! empty ( $ ids ) ) { foreach ( $ ids as $ id ) { $ data [ ] = [ 'type' => $ ty...
build the body data for a relationship call
17,368
public function getAccessToken ( ) { $ existing = $ this -> storage -> getKey ( 'authentication' ) ; if ( $ existing && $ existing -> expires > time ( ) ) { return $ existing -> access_token ; } $ authResponse = $ this -> makeAuthenticationCall ( ) ; $ this -> storage -> setKey ( 'authentication' , $ authResponse -> ge...
Get an access token from the local storage if available otherwise request one from the API
17,369
public function makeAuthenticationCall ( ) { $ authResponse = $ this -> call ( 'POST' , [ 'grant_type' => 'client_credentials' , 'client_id' => $ this -> client -> getClientID ( ) , 'client_secret' => $ this -> client -> getClientSecret ( ) ] , false , [ 'Content-Type' => 'application/x-www-form-urlencoded' ] , false ,...
Get an access token from the API
17,370
public function call ( $ method , $ body = false , $ uriAppend = false , $ headers = [ ] , $ requiresAuthentication = true , $ buildQueryParams = true ) { $ headers = $ this -> addRequestHeaders ( $ headers ) ; $ url = $ requiresAuthentication ? $ this -> client -> getAPIEndpoint ( $ this -> uri ) : $ this -> client ->...
Make a call to the API
17,371
public function addRequestHeaders ( $ headers ) { $ currency = $ this -> client -> getCurrencyCode ( ) ; if ( ! empty ( $ currency ) ) { $ headers [ 'X-MOLTIN-CURRENCY' ] = $ this -> client -> getCurrencyCode ( ) ; } return $ headers ; }
Adds moltin specific request headers to an array to be passed to the request
17,372
public function buildQueryStringParams ( ) { $ params = [ ] ; if ( $ this -> limit > 0 ) { $ params [ 'page' ] [ 'limit' ] = $ this -> limit ; } if ( $ this -> offset > 0 ) { $ params [ 'page' ] [ 'offset' ] = $ this -> offset ; } if ( $ this -> sort ) { $ params [ 'sort' ] = $ this -> sort ; } if ( $ this -> filter ) ...
Build the query string parameters based on the resource settings
17,373
public function getValueOrDefault ( $ key , $ default = null ) { if ( ! empty ( $ this -> values [ $ key ] ) ) { return $ this -> values [ $ key ] ; } elseif ( ! empty ( $ this -> defaults [ $ key ] ) ) { return $ this -> defaults [ $ key ] ; } else { return $ default ; } }
Get value or default .
17,374
public function getSegments ( $ named = false ) { if ( ! empty ( $ this -> segments ) ) { return $ named === true ? $ this -> segmentsNamed : $ this -> segments ; } $ required = $ this -> defaults ; $ safeTemplate = $ this -> escapeTemplate ( $ this -> template ) ; $ this -> segments = $ this -> extractSegments ( $ thi...
Returns segments of the route .
17,375
private function escapeTemplate ( $ value ) { $ result = $ value ; $ result = str_replace ( '{{' , chr ( 1 ) , $ result ) ; $ result = str_replace ( '}}' , chr ( 2 ) , $ result ) ; $ result = preg_replace_callback ( '/([^\{\/\x5c]+|)(\{[^\}]+\})([^\{\/\x5c]+|)/' , function ( $ m ) { array_shift ( $ m ) ; $ m = array_fi...
Quote regular expression characters .
17,376
private function setBounds ( & $ segments ) { for ( $ i = 0 , $ count = count ( $ segments ) ; $ i < $ count ; ++ $ i ) { if ( $ segments [ $ i ] -> optional && $ i - 1 >= 0 ) { $ optional = true ; for ( $ j = $ i + 1 ; $ j < $ count ; ++ $ j ) { if ( ! $ segments [ $ j ] -> optional ) { $ optional = false ; break ; } ...
Marks the boundaries .
17,377
public function actionNameEquals ( $ name ) { $ actionName = strtolower ( $ this -> actionName ) ; if ( is_array ( $ name ) ) { foreach ( $ name as $ n ) { if ( $ actionName == strtolower ( $ n ) ) { return true ; } } return false ; } else { return $ actionName == strtolower ( $ name ) ; } }
Checks the equivalence of the specified string with the name of the action .
17,378
public function controllerNameEquals ( $ name ) { $ controllerName = strtolower ( $ this -> getControllerName ( ) ) ; if ( is_array ( $ name ) ) { foreach ( $ name as $ n ) { if ( $ controllerName == strtolower ( $ n ) ) { return true ; } } return false ; } else { return $ controllerName == strtolower ( $ name ) ; } }
Checks the equivalence of the specified string with the name of the controller .
17,379
public function clear ( $ regionName = null ) { $ path = $ this -> getPath ( $ regionName ) ; $ result = count ( glob ( $ path . DIRECTORY_SEPARATOR . '*.cache' ) ) ; array_map ( 'unlink' , glob ( $ path . DIRECTORY_SEPARATOR . '*.cache' ) ) ; array_map ( 'unlink' , glob ( $ path . DIRECTORY_SEPARATOR . '*.policy' ) ) ...
Removes all cache entries .
17,380
public function init ( ) { $ this -> cachePath = PathUtility :: mapPath ( $ this -> config -> cachePath ) ; $ this -> accessTime = ( isset ( $ this -> config -> accessTime ) ? ( int ) $ this -> config -> accessTime : 100 ) * 1000 ; $ this -> hash = ( isset ( $ this -> config -> hash ) ? $ this -> config -> hash : null ...
Initializes the provider .
17,381
public function get ( $ key , $ regionName = null ) { if ( $ this -> containsFiles ( $ key , $ regionName , $ policy , $ cache ) ) { $ this -> getCacheContent ( $ policy , $ cache , $ result ) ; return $ result ; } else { return null ; } }
Gets the specified cache entry from the cache as an object .
17,382
public function remove ( $ key , $ regionName = null ) { if ( $ this -> containsFiles ( $ key , $ regionName , $ policy , $ cache ) ) { if ( $ this -> getCacheContent ( $ policy , $ cache , $ result ) === true ) { $ this -> tryDeleteFile ( $ policy ) ; $ this -> tryDeleteFile ( $ cache ) ; } return $ result ; } else { ...
Removes the cache entry from the cache .
17,383
private function getKey ( $ value ) { return ! empty ( $ this -> hash ) ? call_user_func ( $ this -> hash , $ value ) : preg_replace ( '/[^0-9a-z\.\_\-]/i' , '' , $ value ) ; }
Gets normalized key .
17,384
private function getPath ( $ regionName = null ) { $ cachePath = $ this -> cachePath ; if ( ! empty ( $ regionName ) ) { $ cachePath .= DIRECTORY_SEPARATOR . $ regionName ; } if ( ! is_dir ( $ cachePath ) ) { if ( ! mkdir ( $ cachePath , 0775 , true ) ) { throw new \ Exception ( 'Unable to create cache directory "' . $...
Gets directory path of cache storage .
17,385
private function getCacheFilePaths ( $ key , $ regionName , & $ policy , & $ cache ) { $ key = $ this -> getKey ( $ key ) ; $ path = $ this -> getPath ( $ regionName ) ; $ policy = $ path . DIRECTORY_SEPARATOR . $ key . '.policy' ; $ cache = $ path . DIRECTORY_SEPARATOR . $ key . '.cache' ; }
Gets path to cache and policy files .
17,386
private function containsFiles ( $ key , $ regionName , & $ policy = null , & $ cache = null ) { $ this -> getCacheFilePaths ( $ key , $ regionName , $ policy , $ cache ) ; if ( ! is_file ( $ policy ) && ! is_file ( $ cache ) ) { return false ; } elseif ( ! is_file ( $ policy ) && is_file ( $ cache ) ) { $ this -> tryD...
Checks whether the cache entry already exists in the cache .
17,387
private function getCacheContent ( $ policy , $ cache , & $ data ) { $ policyContent = $ this -> tryReadFile ( $ policy ) ; $ cacheContent = $ this -> tryReadFile ( $ cache ) ; $ data = null ; if ( $ policyContent === false || $ cacheContent === false ) { $ this -> tryDeleteFile ( $ policy ) ; $ this -> tryDeleteFile (...
Gets content of cache entry .
17,388
private function addCache ( $ policy , $ cache , $ value , $ duration ) { $ content = is_callable ( $ value ) ? $ value ( ) : $ value ; $ policyContent = json_encode ( array ( 'absoluteExpiration' => $ duration > 0 ? time ( ) + $ duration : 0 ) ) ; if ( $ this -> tryWriteFile ( $ policy , $ policyContent ) === true ) {...
Saves cache .
17,389
private function tryDeleteFile ( $ path ) { $ interval = 100000 ; $ totalTime = 0 ; while ( file_exists ( $ path ) && ! unlink ( $ path ) ) { if ( $ totalTime >= $ this -> accessTime ) { return false ; } usleep ( $ interval ) ; $ totalTime += $ interval ; } return true ; }
Trying to delete the specified file .
17,390
private function tryReadFile ( $ path ) { if ( ! file_exists ( $ path ) ) { return false ; } $ interval = 100000 ; $ totalTime = 0 ; while ( ( $ result = file_get_contents ( $ path ) ) === false ) { if ( $ totalTime >= $ this -> accessTime ) { return false ; } usleep ( $ interval ) ; $ totalTime += $ interval ; } retur...
Trying to read the file .
17,391
private function tryWriteFile ( $ path , $ content ) { $ interval = 100000 ; $ totalTime = 0 ; while ( file_put_contents ( $ path , $ content ) === false ) { if ( $ totalTime >= $ this -> accessTime ) { return false ; } usleep ( $ interval ) ; $ totalTime += $ interval ; } return true ; }
Trying to save the file .
17,392
public function isValid ( $ key = null ) { if ( isset ( $ key ) ) { return empty ( $ this -> errors [ $ key ] ) ; } else { return empty ( $ this -> errors ) ; } }
Returns true if the state does not contain errors ; otherwise false .
17,393
public function getErrors ( $ key = null ) { if ( isset ( $ key ) ) { return ! empty ( $ this -> errors [ $ key ] ) ? $ this -> errors [ $ key ] : array ( ) ; } else { return $ this -> errors ; } }
Returns errors of the model state .
17,394
public function getKeyValuePair ( ) { $ result = array ( ) ; foreach ( $ this -> items as $ key => $ entry ) { $ result [ $ key ] = $ entry -> value ; } return $ result ; }
Gets the key - value pair .
17,395
public function getValues ( ) { $ result = array ( ) ; foreach ( $ this -> items as $ key => $ entry ) { $ result [ ] = $ entry -> value ; } return $ result ; }
Gets the value sequence .
17,396
public function addError ( $ key , $ error ) { if ( is_array ( $ key ) ) { $ key = implode ( '_' , $ key ) ; } if ( array_key_exists ( $ key , $ this -> errors ) ) { $ this -> errors [ $ key ] [ ] = $ error ; } else { $ this -> errors [ $ key ] = array ( $ error ) ; } }
Adds the specified errorMessage to the Errors instance that is associated with the specified key .
17,397
public function ignore ( $ template , $ constraints = null ) { $ route = new Route ( ) ; $ route -> template = $ template ; $ route -> constraints = $ constraints ; $ route -> ignore = true ; $ this -> ignored -> add ( $ route ) ; }
Adds an URL pattern that should not be checked for matches against routes if a request URL meets the specified constraints .
17,398
public static function add ( $ actionOrFilterName , $ filterName = null ) { if ( empty ( $ filterName ) ) { $ filterName = $ actionOrFilterName ; $ actionOrFilterName = '.' ; } if ( $ actionOrFilterName != '.' && ! self :: $ actionContext -> actionNameEquals ( $ actionOrFilterName ) ) { return ; } if ( ! isset ( self :...
Adds a filter .
17,399
public function writeAttempt ( ) { $ result = self :: OK ; if ( empty ( $ this -> filepath ) ) { return self :: ERROR ; } $ fp = fopen ( $ this -> filepath , 'c' ) ; if ( $ fp === false ) { return self :: ERROR_OPEN ; } if ( empty ( $ this -> file_lock ) ) { ftruncate ( $ fp , 0 ) ; if ( fwrite ( $ fp , $ this -> conte...
Attempt to write into the file . If lock is not acquired file is not written .