idx
int64
0
60.3k
question
stringlengths
64
4.24k
target
stringlengths
5
618
54,200
public function validateapiAction ( ) { $ request = $ this -> getRequest ( ) ; $ configMap = Mage :: getModel ( 'radial_core/config' ) ; $ hostname = $ this -> _validatorHelper -> getParamOrFallbackValue ( $ request , self :: HOSTNAME_PARAM , self :: HOSTNAME_USE_DEFAULT_PARAM , $ configMap -> getPathForKey ( 'api_hostname' ) ) ; $ storeId = $ this -> _validatorHelper -> getParamOrFallbackValue ( $ request , self :: STORE_ID_PARAM , self :: STORE_ID_USE_DEFAULT_PARAM , $ configMap -> getPathForKey ( 'store_id' ) ) ; $ apiKey = $ this -> _validatorHelper -> getEncryptedParamOrFallbackValue ( $ request , self :: API_KEY_PARAM , self :: API_KEY_USE_DEFAULT_PARAM , Mage :: getSingleton ( 'radial_core/config' ) -> getPathForKey ( 'api_key' ) ) ; $ this -> getResponse ( ) -> setHeader ( 'Content-Type' , 'text/json' ) -> setBody ( json_encode ( Mage :: helper ( 'radial_core/validator' ) -> testApiConnection ( $ storeId , $ apiKey , $ hostname ) ) ) ; return $ this ; }
Validate the API configuration by making a test address validation request and ensuring the response that is returned is valid .
54,201
public function validatesftpAction ( ) { $ request = $ this -> getRequest ( ) ; $ configMap = Mage :: getModel ( 'radial_core/config' ) ; $ host = $ this -> _validatorHelper -> getParamOrFallbackValue ( $ request , self :: SFTP_HOSTNAME_PARAM , self :: SFTP_HOSTNAME_USE_DEFAULT_PARAM , $ configMap -> getPathForKey ( 'sftp_location' ) ) ; $ username = $ this -> _validatorHelper -> getParamOrFallbackValue ( $ request , self :: SFTP_USERNAME_PARAM , self :: SFTP_USERNAME_USE_DEFAULT_PARAM , $ configMap -> getPathForKey ( 'sftp_username' ) ) ; $ port = $ this -> _validatorHelper -> getParamOrFallbackValue ( $ request , self :: SFTP_PORT_PARAM , self :: SFTP_PORT_USE_DEFAULT_PARAM , $ configMap -> getPathForKey ( 'sftp_port' ) ) ; $ key = $ this -> _validatorHelper -> getSftpPrivateKey ( $ request , self :: SFTP_PRIV_KEY_PARAM , self :: SFTP_PRIV_KEY_USE_DEFAULT_PARAM , Mage :: getSingleton ( 'radial_core/config' ) -> getPathForKey ( 'sftp_private_key' ) ) ; $ this -> getResponse ( ) -> setHeader ( 'Content-Type' , 'text/json' ) -> setBody ( json_encode ( Mage :: helper ( 'radial_core/validator' ) -> testSftpConnection ( $ host , $ username , $ key , $ port ) ) ) ; return $ this ; }
Validate the SFTP configurations and set the response body to a JSON response including the success of the test connection and any messages to be displayed to the user .
54,202
private function registerOAuthServer ( ) { $ this -> app -> bind ( 'League\OAuth2\Server\Storage\ClientInterface' , 'Sule\Api\OAuth2\Repositories\FluentClient' ) ; $ this -> app -> bind ( 'League\OAuth2\Server\Storage\ScopeInterface' , 'Sule\Api\OAuth2\Repositories\FluentScope' ) ; $ this -> app -> bind ( 'League\OAuth2\Server\Storage\SessionInterface' , 'Sule\Api\OAuth2\Repositories\FluentSession' ) ; $ this -> app -> bind ( 'Sule\Api\OAuth2\Repositories\SessionManagementInterface' , 'Sule\Api\OAuth2\Repositories\FluentSession' ) ; $ this -> app [ 'api.authorization' ] = $ this -> app -> share ( function ( $ app ) { $ server = $ app -> make ( 'League\OAuth2\Server\Authorization' ) ; $ config = $ app [ 'config' ] -> get ( 'sule/api::oauth2' ) ; foreach ( $ config [ 'grant_types' ] as $ grantKey => $ grantValue ) { $ server -> addGrantType ( new $ grantValue [ 'class' ] ( $ server ) ) ; $ server -> getGrantType ( $ grantKey ) -> setAccessTokenTTL ( $ grantValue [ 'access_token_ttl' ] ) ; if ( array_key_exists ( 'callback' , $ grantValue ) ) { $ server -> getGrantType ( $ grantKey ) -> setVerifyCredentialsCallback ( $ grantValue [ 'callback' ] ) ; } if ( array_key_exists ( 'auth_token_ttl' , $ grantValue ) ) { $ server -> getGrantType ( $ grantKey ) -> setAuthTokenTTL ( $ grantValue [ 'auth_token_ttl' ] ) ; } if ( array_key_exists ( 'refresh_token_ttl' , $ grantValue ) ) { $ server -> getGrantType ( $ grantKey ) -> setRefreshTokenTTL ( $ grantValue [ 'refresh_token_ttl' ] ) ; } if ( array_key_exists ( 'rotate_refresh_tokens' , $ grantValue ) ) { $ server -> getGrantType ( $ grantKey ) -> rotateRefreshTokens ( $ grantValue [ 'rotate_refresh_tokens' ] ) ; } } $ server -> requireStateParam ( $ config [ 'state_param' ] ) ; $ server -> requireScopeParam ( $ config [ 'scope_param' ] ) ; $ server -> setScopeDelimeter ( $ config [ 'scope_delimiter' ] ) ; $ server -> setDefaultScope ( $ config [ 'default_scope' ] ) ; $ server -> setAccessTokenTTL ( $ config [ 'access_token_ttl' ] ) ; return new OAuthServer ( $ server ) ; } ) ; $ this -> app [ 'api.resource' ] = $ this -> app -> share ( function ( $ app ) { return $ app -> make ( 'Sule\Api\OAuth2\Resource' ) ; } ) ; }
Register the OAuth server .
54,203
public function registerApi ( ) { $ this -> app [ 'api' ] = $ this -> app -> share ( function ( $ app ) { $ config = $ app [ 'config' ] -> get ( 'sule/api::config' ) ; $ config [ 'oauth2' ] = $ app [ 'config' ] -> get ( 'sule/api::oauth2' ) ; return new Api ( $ config , $ app [ 'request' ] , new Response ( ) , $ app [ 'api.authorization' ] , $ app [ 'api.resource' ] ) ; } ) ; }
Register the Api .
54,204
private function createPhpProcessBuilder ( OutputInterface $ output , $ address ) { $ router = realpath ( __DIR__ . '/../../Resources/bin/router.php' ) ; $ finder = new PhpExecutableFinder ( ) ; if ( false === $ binary = $ finder -> find ( ) ) { $ output -> writeln ( '<error>Unable to find PHP binary to run server</error>' ) ; return ; } return new ProcessBuilder ( [ $ binary , '-S' , $ address , $ router ] ) ; }
Get a ProcessBuilder instance
54,205
protected function isOtherServerProcessRunning ( $ address ) { if ( file_exists ( sys_get_temp_dir ( ) . '/' . strtr ( $ address , '.:' , '--' ) . '.pid' ) ) { return true ; } list ( $ hostname , $ port ) = explode ( ':' , $ address ) ; if ( false !== $ fp = @ fsockopen ( $ hostname , $ port , $ errno , $ errstr , 5 ) ) { fclose ( $ fp ) ; return true ; } return false ; }
Is another service already using the given address?
54,206
protected function getCredentials ( ) { $ credentialArgs = [ '--host=%s --port=%s --user=%s --password=%s %s' , escapeshellarg ( $ this -> config [ 'host' ] ) , escapeshellarg ( $ this -> config [ 'port' ] ) , escapeshellarg ( $ this -> config [ 'user' ] ) , escapeshellarg ( $ this -> config [ 'pass' ] ) , escapeshellarg ( $ this -> config [ 'database' ] ) , ] ; return call_user_func_array ( 'sprintf' , $ credentialArgs ) ; }
Get the credential options for the command .
54,207
protected function getTables ( ) { if ( empty ( $ this -> config [ 'tables' ] ) ) { return '' ; } $ tables = [ ] ; $ allTables = array_diff ( $ this -> config [ 'tables' ] , $ this -> config [ 'structureTables' ] ) ; foreach ( $ allTables as $ table ) { $ tables [ ] = escapeshellarg ( $ table ) ; } return implode ( $ tables ) ; }
Get the table arguments for the command .
54,208
protected function getOptions ( ) { $ options = [ '--routines' , ] ; if ( $ this -> config [ 'dataOnly' ] ) { $ options [ ] = '--no-create-info' ; } if ( $ this -> config [ 'orderedDump' ] ) { $ options [ ] = '--skip-extended-insert' ; $ options [ ] = '--order-by-primary' ; } if ( $ this -> config [ 'singleTransaction' ] ) { $ options [ ] = '--single-transaction' ; } if ( $ this -> config [ 'extra' ] ) { $ options [ ] = $ this -> config [ 'extra' ] ; } return implode ( ' ' , $ options ) ; }
Get the command options for the command .
54,209
protected function getIgnore ( ) { if ( ! empty ( $ this -> config [ 'tables' ] ) ) { return '' ; } $ ignoreTables = array_merge ( $ this -> config [ 'structureTables' ] , $ this -> config [ 'ignoreTables' ] ) ; $ ignoreArgs = [ ] ; foreach ( $ ignoreTables as $ table ) { $ ignoreArgs [ ] = escapeshellarg ( $ this -> config [ 'database' ] . '.' . $ table ) ; } array_unshift ( $ ignoreArgs , str_repeat ( ' --ignore-table=%s' , count ( $ ignoreArgs ) ) ) ; return trim ( call_user_func_array ( 'sprintf' , $ ignoreArgs ) ) ; }
Get the ignore table options for the command .
54,210
protected function getStructureTables ( ) { if ( empty ( $ this -> config [ 'structureTables' ] ) ) { return '' ; } $ structureTables = [ ] ; foreach ( $ this -> config [ 'structureTables' ] as $ table ) { $ structureTables [ ] = escapeshellarg ( $ table ) ; } return implode ( ' ' , $ structureTables ) ; }
Get the structure tables for the command .
54,211
public function load ( ICategory $ category ) { $ this -> template -> set ( 'title' , $ category -> getTitle ( ) ) ; $ this -> template -> set ( 'meta_title' , $ category -> metaTitle ( ) ) ; $ this -> template -> set ( 'meta_keywords' , $ category -> metaKeywords ( ) ) ; $ this -> template -> set ( 'meta_description' , $ category -> metaDescription ( ) ) ; }
Load category data to the template .
54,212
public function addEmbed ( EmbeddedPropMetadata $ embed ) { $ this -> validateEmbed ( $ embed ) ; $ this -> embeds [ $ embed -> getKey ( ) ] = $ embed ; ksort ( $ this -> embeds ) ; return $ this ; }
Adds an embed field .
54,213
public function getEmbed ( $ key ) { if ( ! isset ( $ this -> embeds [ $ key ] ) ) { return null ; } return $ this -> embeds [ $ key ] ; }
Gets an embed field . Returns null if the embed does not exist .
54,214
private function getResourcesSection ( ) { $ builder = new TreeBuilder ( ) ; $ node = $ builder -> root ( 'resources' ) ; $ node -> useAttributeAsKey ( 'prefix' ) -> prototype ( 'array' ) -> useAttributeAsKey ( 'name' ) -> prototype ( 'array' ) -> children ( ) -> variableNode ( 'templates' ) -> end ( ) -> scalarNode ( 'entity' ) -> isRequired ( ) -> cannotBeEmpty ( ) -> end ( ) -> scalarNode ( 'controller' ) -> end ( ) -> scalarNode ( 'repository' ) -> end ( ) -> scalarNode ( 'operator' ) -> end ( ) -> scalarNode ( 'event' ) -> end ( ) -> scalarNode ( 'form' ) -> isRequired ( ) -> cannotBeEmpty ( ) -> end ( ) -> scalarNode ( 'table' ) -> isRequired ( ) -> cannotBeEmpty ( ) -> end ( ) -> scalarNode ( 'parent' ) -> end ( ) -> arrayNode ( 'translation' ) -> children ( ) -> scalarNode ( 'entity' ) -> end ( ) -> scalarNode ( 'repository' ) -> end ( ) -> arrayNode ( 'fields' ) -> prototype ( 'scalar' ) -> end ( ) -> defaultValue ( [ ] ) -> end ( ) -> end ( ) -> end ( ) -> end ( ) -> end ( ) -> end ( ) ; return $ node ; }
Returns the resources configuration definition .
54,215
private function getMenusSection ( ) { $ builder = new TreeBuilder ( ) ; $ node = $ builder -> root ( 'menus' ) ; $ node -> useAttributeAsKey ( 'name' ) -> prototype ( 'array' ) -> children ( ) -> scalarNode ( 'label' ) -> isRequired ( ) -> cannotBeEmpty ( ) -> end ( ) -> scalarNode ( 'icon' ) -> isRequired ( ) -> cannotBeEmpty ( ) -> end ( ) -> integerNode ( 'position' ) -> defaultValue ( 0 ) -> end ( ) -> scalarNode ( 'domain' ) -> defaultValue ( 'messages' ) -> end ( ) -> scalarNode ( 'route' ) -> defaultNull ( ) -> end ( ) -> arrayNode ( 'entries' ) -> useAttributeAsKey ( 'name' ) -> prototype ( 'array' ) -> children ( ) -> scalarNode ( 'route' ) -> isRequired ( ) -> cannotBeEmpty ( ) -> end ( ) -> scalarNode ( 'label' ) -> isRequired ( ) -> cannotBeEmpty ( ) -> end ( ) -> scalarNode ( 'resource' ) -> isRequired ( ) -> cannotBeEmpty ( ) -> end ( ) -> integerNode ( 'position' ) -> defaultValue ( 0 ) -> end ( ) -> scalarNode ( 'domain' ) -> defaultValue ( 'messages' ) -> end ( ) -> end ( ) -> end ( ) -> end ( ) -> end ( ) -> end ( ) ; return $ node ; }
Returns the menu configuration definition .
54,216
private function getDashboardSection ( ) { $ builder = new TreeBuilder ( ) ; $ node = $ builder -> root ( 'dashboard' ) ; $ node -> useAttributeAsKey ( 'name' ) -> prototype ( 'array' ) -> children ( ) -> scalarNode ( 'type' ) -> isRequired ( ) -> cannotBeEmpty ( ) -> end ( ) -> arrayNode ( 'options' ) -> useAttributeAsKey ( 'name' ) -> prototype ( 'scalar' ) -> end ( ) -> defaultValue ( array ( ) ) -> end ( ) -> end ( ) -> end ( ) ; return $ node ; }
Returns the dashboard configuration definition .
54,217
public function rest_api_init ( ) { $ args = [ ] ; foreach ( [ 'GET' , 'POST' , 'PUT' , 'DELETE' , 'PATCH' , 'OPTIONS' , 'HEAD' ] as $ http_method ) { $ method_name = 'handle_' . strtolower ( $ http_method ) ; if ( method_exists ( $ this , $ method_name ) ) { $ arg = [ 'methods' => $ http_method , 'callback' => [ $ this , 'callback' ] , 'args' => $ this -> get_args ( $ http_method ) , ] ; $ permission_callback = method_exists ( $ this , 'permission_callback' ) ? [ $ this , 'permission_callback' ] : null ; if ( $ permission_callback ) { $ arg [ 'permission_callback' ] = $ permission_callback ; } $ args [ ] = $ arg ; } } if ( $ args ) { register_rest_route ( "{$this->namespace}/v{$this->version}" , $ this -> route , $ args ) ; } }
Register rest route .
54,218
public function createNewEmbed ( ) { $ embed = $ this -> store -> loadEmbed ( $ this -> getMetadata ( ) , [ ] ) ; $ embed -> getState ( ) -> setNew ( ) ; return $ embed ; }
Creates a new Embed model instance based on the collection
54,219
public function getHash ( ) { $ hash = [ ] ; foreach ( $ this as $ embed ) { $ hash [ ] = $ embed -> getHash ( ) ; } sort ( $ hash ) ; return md5 ( serialize ( $ hash ) ) ; }
Gets the unique hash for this collection .
54,220
public static function make ( array $ options = [ ] , $ driver = null ) { $ class = null ; if ( ! $ driver && isset ( $ options [ 'driver' ] ) ) { $ driver = $ options [ 'driver' ] ; unset ( $ options [ 'driver' ] ) ; } if ( isset ( self :: $ driverMap [ $ driver ] ) ) { $ class = self :: $ driverMap [ $ driver ] ; } else { foreach ( [ self :: DRIVER_SEM , self :: DRIVER_FILE ] as $ name ) { $ class = self :: $ driverMap [ $ name ] ; if ( $ class :: isSupported ( ) ) { break ; } } } if ( ! $ class ) { throw new \ RuntimeException ( 'No available driver! MAP: ' . implode ( ',' , self :: $ driverMap ) ) ; } return new $ class ( $ options ) ; }
Lock constructor .
54,221
public function post ( $ params = null , $ url = null , $ contenttype = 'application/x-www-form-urlencoded' , $ user = null , $ password = null , $ raw = false ) { return $ this -> request ( $ params , $ url , 'POST' , $ contenttype , $ user , $ password , $ raw ) ; }
Convenience method wrapping a commom POST call
54,222
public static function initResult ( $ res ) { if ( ! is_array ( $ res ) ) throw new Exception ( 'Invalid datatype. Array expected!' ) ; elseif ( isset ( $ res [ 'error' ] ) ) throw new Exception ( 'Server error: ' . $ res [ 'error' ] ) ; elseif ( ! isset ( $ res [ 'result' ] ) ) throw new Exception ( 'Server returned no result: ' . $ res ) ; return $ res [ 'result' ] ; }
Initializes and checks a server result
54,223
public static function getArrayItemByPointSeparatedKey ( array & $ aData , $ sKey ) { if ( strpos ( $ sKey , '.' ) !== false ) { preg_match ( '/([a-zA-Z0-9_\-]+)\.([a-zA-Z0-9_\-\.]+)/' , $ sKey , $ aKey ) ; if ( ! isset ( $ aData [ $ aKey [ 1 ] ] ) ) { throw new Exception ( 'Undefined index: ' . $ aKey [ 1 ] ) ; } if ( ! is_array ( $ aData [ $ aKey [ 1 ] ] ) ) { throw new Exception ( "The element indexed {$aKey[1]} isn't an array." ) ; } return self :: getArrayItemByPointSeparatedKey ( $ aData [ $ aKey [ 1 ] ] , $ aKey [ 2 ] ) ; } elseif ( isset ( $ aData [ $ sKey ] ) ) { return $ aData [ $ sKey ] ; } else { throw new Exception ( 'Undefined index: ' . $ sKey ) ; } }
The method returns a tree element by a key which is formed as a string separated by points and reflecting the nesting hierarchy .
54,224
public function addRule ( $ sName , $ funcCall , $ mErrorMsg = null ) { if ( is_callable ( $ funcCall ) ) { $ this -> rules [ $ sName ] = array ( $ funcCall , $ mErrorMsg ) ; } else { throw new Exception ( "Rule isn't callable." ) ; } return $ this ; }
The method adds a validation rule to the stack of validator rulesets .
54,225
private function applyRuleToField ( $ sFieldName , $ sRuleName , array $ aOpt = array ( ) ) { if ( ! isset ( $ this -> rules [ $ sRuleName ] ) ) { throw new Exception ( 'Undefined rule name.' ) ; } $ funcCall = $ this -> rules [ $ sRuleName ] [ 0 ] ; if ( ! $ funcCall ( $ sFieldName , $ aOpt ) ) { if ( isset ( $ this -> rules [ $ sRuleName ] [ 1 ] ) ) { if ( is_callable ( $ this -> rules [ $ sRuleName ] [ 1 ] ) ) { $ funcMsg = $ this -> rules [ $ sRuleName ] [ 1 ] ; $ this -> addError ( $ funcMsg ( $ sFieldName , $ aOpt ) ) ; } else { $ this -> addError ( ( string ) $ this -> rules [ $ sRuleName ] [ 1 ] ) ; } } else { $ this -> addDefaultError ( $ sFieldName ) ; } } }
The method applies the validation rule to the validable field .
54,226
public function run ( ) { if ( ! $ this -> isRan ) { $ this -> isRan = true ; foreach ( $ this -> items as $ aItem ) { $ mOpt = isset ( $ aItem [ 2 ] ) ? $ aItem [ 2 ] : array ( ) ; $ sRuleName = $ aItem [ 1 ] ; foreach ( is_array ( $ aItem [ 0 ] ) ? $ aItem [ 0 ] : array ( $ aItem [ 0 ] ) as $ sFieldName ) { self :: applyRuleToField ( $ sFieldName , $ sRuleName , $ mOpt ) ; } } } return $ this ; }
The main executable method .
54,227
protected function showErrorAndDie ( \ Exception $ e ) { $ this -> error ( 'And error occurs connecting to the api url: ' . $ this -> url ) ; if ( $ e -> getResponse ( ) ) { $ this -> error ( 'Status code: ' . $ e -> getResponse ( ) -> getStatusCode ( ) . ' | Reason : ' . $ e -> getResponse ( ) -> getReasonPhrase ( ) ) ; } else { $ this -> error ( 'Exception occurs. Message: ' . $ e -> getMessage ( ) ) ; } die ( ) ; }
Show error and die .
54,228
protected function processOptions ( array $ options ) { foreach ( $ options as $ name => $ value ) { if ( is_callable ( $ value ) ) { $ options [ $ name ] = call_user_func ( $ value , $ this -> data , $ options ) ; } elseif ( is_object ( $ value ) && ! method_exists ( $ value , '__toString' ) ) { throw new \ InvalidArgumentException ( 'the value of an option must be either castable to a string or callable' ) ; } } return $ options ; }
processes the passed options based on the data set for the column
54,229
public function getResourceRepository ( ) { if ( $ this -> resourceRepository === null ) { $ this -> resourceRepository = $ this -> getPuliFactory ( ) -> createRepository ( ) ; } return $ this -> resourceRepository ; }
Returns an instance to the puli repository
54,230
public function getResourceDiscovery ( ) { if ( $ this -> resourceDiscovery === null ) { $ repo = $ this -> getResourceRepository ( ) ; $ this -> resourceDiscovery = $ this -> getPuliFactory ( ) -> createDiscovery ( $ repo ) ; } return $ this -> resourceDiscovery ; }
Returns an instance to the puli discovery
54,231
public function getUrlGenerator ( ) { if ( $ this -> urlGenerator === null ) { $ discovery = $ this -> getResourceDiscovery ( ) ; $ this -> urlGenerator = $ this -> getPuliFactory ( ) -> createUrlGenerator ( $ discovery ) ; } return $ this -> urlGenerator ; }
Returns the url generator for puli resources
54,232
public function generateProxyClass ( $ entity , $ config ) { if ( ! is_array ( $ config ) && ! $ config instanceof \ ArrayAccess ) { throw new Exception \ InvalidArgumentException ( 'Invalid proxy class configuration; array or instance of ArrayAccess expected' ) ; } if ( ! is_object ( $ entity ) ) { if ( ( is_string ( $ entity ) && ( ! class_exists ( $ entity ) ) ) || ( ! is_string ( $ entity ) ) ) { throw new Exception \ InvalidArgumentException ( sprintf ( '%s expects an object or valid class name; received "%s"' , __METHOD__ , var_export ( $ entity , 1 ) ) ) ; } } $ this -> serviceConfig = $ config ; $ reflection = new ReflectionClass ( $ entity ) ; $ className = $ reflection -> getName ( ) ; $ class = ClassGenerator :: fromArray ( [ 'name' => $ this -> getProxyClassName ( $ className ) , 'namespace_name' => $ this -> getProxyNamespace ( $ className ) , 'extended_class' => '\\' . $ className , 'implemented_interfaces' => array ( '\Zend\EventManager\EventManagerAwareInterface' ) , 'methods' => $ this -> generateMethods ( $ reflection ) , 'properties' => [ new PropertyGenerator ( '__wrappedObject' , null , PropertyGenerator :: FLAG_PUBLIC ) , new PropertyGenerator ( '__eventManager' , null , PropertyGenerator :: FLAG_PRIVATE ) , new PropertyGenerator ( '__commandStack' , null , PropertyGenerator :: FLAG_PRIVATE ) ] ] ) ; $ source = "<?php\n" . $ class -> generate ( ) ; $ fileName = $ this -> getProxyFileName ( $ className ) ; $ parentDirectory = $ this -> proxyDirectory ; if ( ! is_dir ( $ parentDirectory ) && ( false === @ mkdir ( $ parentDirectory , 0775 , true ) ) ) { throw new Exception \ RuntimeException ( 'Proxy directory ' . $ parentDirectory . ' not found' ) ; } if ( ! is_writable ( $ parentDirectory ) ) { throw new Exception \ RuntimeException ( 'Proxy directory ' . $ parentDirectory . ' is not writable' ) ; } $ tmpFileName = $ fileName . '.' . uniqid ( '' , true ) ; file_put_contents ( $ tmpFileName , $ source ) ; rename ( $ tmpFileName , $ fileName ) ; }
Generate proxy class for entity
54,233
public function getProxyClassName ( $ className ) { $ suffix = ltrim ( $ className , '\\' ) ; if ( $ this -> proxyClassSuffix !== null ) { $ suffix .= $ this -> proxyClassSuffix ; } return rtrim ( $ this -> proxyNamespace , '\\' ) . '\\' . self :: MARKER . '\\' . $ suffix ; }
Get proxy class name for service class name
54,234
public function getProxyFilename ( $ className ) { $ baseDirectory = $ this -> proxyDirectory ; $ suffix = str_replace ( '\\' , '' , $ className ) ; if ( $ this -> proxyClassSuffix !== null ) { $ suffix .= $ this -> proxyClassSuffix ; } return rtrim ( $ baseDirectory , DIRECTORY_SEPARATOR ) . DIRECTORY_SEPARATOR . self :: MARKER . $ suffix . '.php' ; }
Get proxy class filename for service class name
54,235
public function createProxyClassInstance ( $ service ) { $ file = $ this -> getProxyFilename ( get_class ( $ service ) ) ; if ( file_exists ( $ file ) ) { require_once $ file ; } else { throw new Exception \ RuntimeException ( sprintf ( 'Proxy class for service "%s" has not been initialized' , get_class ( $ service ) ) ) ; } $ proxyService = $ this -> getProxyClassName ( get_class ( $ service ) ) ; return new $ proxyService ( $ service ) ; }
Create a new instance of the proxy class
54,236
public function getProxyNamespace ( $ className ) { $ proxyClassName = $ this -> getProxyClassName ( $ className ) ; $ parts = explode ( '\\' , strrev ( $ proxyClassName ) , 2 ) ; return strrev ( $ parts [ 1 ] ) ; }
Get proxy namespace for service class name
54,237
protected function generateMethods ( ReflectionClass $ reflectionClass ) { $ methods = array ( ) ; $ methods [ ] = $ this -> generateConstructor ( $ reflectionClass ) ; $ methods [ ] = $ this -> generateInvoker ( $ reflectionClass ) ; $ methods [ ] = $ this -> generateOperationNotFound ( $ reflectionClass ) ; $ methods [ ] = $ this -> generateMatchContext ( $ reflectionClass ) ; if ( ! $ reflectionClass -> hasMethod ( 'setEventManager' ) ) { $ methods [ ] = $ this -> generateEventManagerSetter ( $ reflectionClass ) ; } if ( ! $ reflectionClass -> hasMethod ( 'getEventManager' ) ) { $ methods [ ] = $ this -> generateEventManagerGetter ( $ reflectionClass ) ; } $ methods = array_merge ( $ methods , $ this -> generateServiceMethods ( $ reflectionClass ) ) ; return $ methods ; }
Generate methods for ClassGenerator
54,238
protected function getOperationConfig ( $ name , $ param = null , $ default = null ) { $ config = isset ( $ this -> serviceConfig [ 'operations' ] [ $ name ] ) ? $ this -> serviceConfig [ 'operations' ] [ $ name ] : null ; if ( $ param === null || $ config === null ) { return $ config ; } else { return isset ( $ config [ $ param ] ) ? $ config [ $ param ] : $ default ; } }
Get configurations for named operation
54,239
protected function generateTriggerEventCode ( $ operationName , $ params , $ type , $ paramsExist = false ) { $ config = $ this -> getOperationConfig ( $ operationName , 'events' , array ( ) ) ; $ code = '' ; $ serviceId = strtolower ( $ this -> serviceConfig [ 'service_id' ] ) ; $ responseInjected = false ; if ( ! empty ( $ config ) ) { foreach ( $ config as $ specs ) { if ( $ specs [ 'type' ] === $ type ) { if ( is_string ( $ specs [ 'args' ] ) ) { $ specs [ 'args' ] = array ( $ specs [ 'args' ] ) ; } if ( ! $ specs [ 'name' ] ) { $ specs [ 'name' ] = $ type . '.' . $ serviceId . '.' . $ operationName ; } $ specs [ 'name' ] = str_replace ( '<service>' , $ serviceId , strtolower ( $ specs [ 'name' ] ) ) ; if ( ! $ paramsExist ) { $ code .= '$__event_params = new \ArrayObject();' . "\n" ; foreach ( $ params as $ name ) { if ( $ specs [ 'args' ] === null || in_array ( $ name , $ specs [ 'args' ] ) ) { $ code .= '$__event_params["' . $ name . '"] = $' . $ name . ';' . "\n" ; } } if ( isset ( $ specs [ 'params' ] ) && is_array ( $ specs [ 'params' ] ) && ! empty ( $ specs [ 'params' ] ) ) { foreach ( $ specs [ 'params' ] as $ name => $ value ) { $ code .= '$__event_params["' . $ name . '"] = ' . var_export ( $ value , true ) . ';' . "\n" ; } } $ paramsExist = true ; } if ( $ type == self :: EVENT_POST && ! $ responseInjected ) { $ code .= '$__event_params["__response"] = $response;' . "\n" ; $ responseInjected = true ; } $ code .= '// Trigger "' . $ type . '" event' . "\n" ; $ code .= 'if ($this->__commandStack->count()) {' . "\n" ; $ code .= ' $__event = new \ValuSo\Broker\ServiceEvent(' . var_export ( $ specs [ 'name' ] , true ) . ', $this->__wrappedObject, $__event_params);' . "\n" ; $ code .= ' $__event->setCommand($this->__commandStack->top());' . "\n" ; $ code .= ' $this->getEventManager()->trigger($__event);' . "\n" ; $ code .= '}' . "\n" ; } } return $ code ; } else { return '' ; } }
Generate event trigger code
54,240
public function onClientHandlerMessage ( ClientHandlerJobRequest $ msg ) { $ request = new Request ( $ msg -> getRequestId ( ) , $ msg -> getActionName ( ) , $ msg -> getParameters ( ) ) ; $ this -> addRequest ( $ request ) ; $ this -> getStream ( 'clientHandler' ) -> send ( new ClientHandlerJobResponse ( $ msg -> getRequestId ( ) , $ this -> getId ( ) ) ) ; }
Handles a request from the ClientHandler .
54,241
protected function handleWorkerInit ( Worker $ worker , Register $ msg ) { $ actionCount = intval ( count ( $ msg -> getActions ( ) ) ) ; if ( $ actionCount <= 0 ) { $ this -> getLogger ( ) -> error ( 'Invalid init, invalid action count.' ) ; return ; } foreach ( $ msg -> getActions ( ) as $ actionName ) { $ worker -> addAction ( $ actionName ) ; $ action = $ this -> getActionName ( $ actionName ) ; $ action -> addWorker ( $ worker ) ; } $ this -> getLogger ( ) -> info ( 'New worker (' . $ worker -> getHexId ( ) . ') with ' . $ actionCount . ' actions.' ) ; $ this -> getLogger ( ) -> debug ( 'Actions for worker ' . $ worker -> getHexId ( ) . ': ' . implode ( ', ' , $ worker -> getActionList ( ) ) ) ; $ worker -> setValid ( true ) ; $ this -> reply ( $ worker , new HeartbeatResponseWorkerhandler ( ) ) ; $ this -> getLogger ( ) -> debug ( 'Worker ' . bin2hex ( $ worker -> getId ( ) ) . ' initialised.' ) ; }
Handles an init message from the worker .
54,242
protected function handleGetJobRequest ( Worker $ worker ) { $ this -> getLogger ( ) -> debug ( 'Worker ' . $ worker -> getHexId ( ) . ' is requesting a Job.' ) ; if ( ! $ worker -> isValid ( ) ) { return ; } $ actions = $ worker -> getActionList ( ) ; foreach ( $ actions as $ action ) { if ( isset ( $ this -> notAvailable [ $ action ] ) ) { unset ( $ this -> notAvailable [ $ action ] ) ; $ this -> getLogger ( ) -> debug ( 'Action: ' . $ action . ' is available.' ) ; } } }
Sets the Worker object and its actions to be available again .
54,243
public function reply ( Worker $ worker , MessageInterface $ msg ) { if ( ! $ worker -> isReady ( ) ) { $ this -> getLogger ( ) -> debug ( 'Worker ' . $ worker -> getHexId ( ) . ' is not ready to receive data.' ) ; return ; } $ worker -> setReady ( false ) ; if ( ! $ worker -> isValid ( ) ) { $ this -> getLogger ( ) -> debug ( 'Worker ' . $ worker -> getHexId ( ) . ' is not valid, destroying.' ) ; $ msg = new Destroy ( ) ; } $ this -> getStream ( 'worker' ) -> send ( $ msg , $ worker -> getId ( ) ) ; }
Send a reply to the Worker .
54,244
public function sendRequest ( Worker $ worker , Request $ request ) { $ worker -> setRequest ( $ request ) ; $ this -> reply ( $ worker , new ExecuteJobRequest ( $ request -> getId ( ) , $ request -> getActionName ( ) , $ request -> getParams ( ) ) ) ; }
Sends the request to the worker .
54,245
public function getWorker ( $ id ) { if ( ! isset ( $ this -> workers [ $ id ] ) ) { $ this -> workers [ $ id ] = new Worker ( $ id ) ; } return $ this -> workers [ $ id ] ; }
Retrieves the worker by id if it is not available a new one will be created .
54,246
public function getActionName ( $ name ) { if ( ! isset ( $ this -> actionList [ $ name ] ) ) { $ this -> actionList [ $ name ] = new Action ( $ name ) ; } return $ this -> actionList [ $ name ] ; }
Gets a action by name . If it does not exist it is created .
54,247
public function notifyActions ( Worker $ worker ) { $ actionList = $ worker -> getActionList ( ) ; foreach ( $ actionList as $ actionName ) { $ action = $ this -> getActionName ( $ actionName ) ; if ( $ worker -> isReady ( ) ) { $ action -> addWaitingWorker ( $ worker ) ; } elseif ( ! $ worker -> isValid ( ) ) { $ action -> removeWorker ( $ worker ) ; } } }
Notify actions that the worker state is changed . If the worker is valid it will be added to the actions . If it is invalid it will be removed .
54,248
protected function handleRequests ( ) { $ actions = array_keys ( $ this -> clientRequests ) ; foreach ( $ actions as $ actionName ) { $ this -> dispatchRequestsForAction ( $ actionName ) ; } }
Searches the requestQueue for new jobs .
54,249
public function storeResult ( $ worker , $ requestId , $ result ) { $ request = $ worker -> getRequest ( ) ; if ( $ request === null ) { return ; } if ( $ request -> getId ( ) != $ requestId ) { $ this -> getLogger ( ) -> error ( 'RequestId mismatch (' . $ requestId . ' => ' . $ request -> getId ( ) . ').' ) ; return ; } $ this -> storage [ $ requestId ] = $ result ; $ worker -> setRequest ( null ) ; $ this -> notify ( $ requestId ) ; }
Store a result in the Storage
54,250
public function handle ( ) { $ this -> getStream ( 'clientHandler' ) -> handle ( new TimeoutTimer ( AlphaRPC :: WORKER_HANDLER_TIMEOUT / 3 ) ) ; $ this -> getStream ( 'worker' ) -> handle ( new TimeoutTimer ( AlphaRPC :: WORKER_HANDLER_TIMEOUT / 3 ) ) ; $ this -> purgeWorkers ( ) ; $ this -> handleRequests ( ) ; $ this -> notify ( ) ; }
Perform one round of the loop .
54,251
public function notify ( $ requestId = null ) { $ this -> getStream ( 'status' ) -> send ( new WorkerHandlerStatus ( $ this -> getId ( ) , $ requestId ) ) ; }
Send a message to notify the client handlers that the workerhandler is still alive .
54,252
public static function concat_pdf ( $ path_array , $ target_file_name , $ multiple = false ) { $ cmd = 'pdftk ' ; $ cmd_files = '' ; $ unique = array ( ) ; try { if ( empty ( $ path_array ) ) { throw new FileException ( ( string ) "\$path_array was empty" , ( int ) Config :: get ( 'file_error' ) , ( int ) Config :: get ( 'error_lvl_low' ) , ( string ) __FILE__ , ( string ) __LINE__ ) ; } foreach ( $ path_array as $ pdf_file ) { if ( ! file_exists ( $ pdf_file ) || in_array ( $ pdf_file , $ unique ) ) continue ; if ( $ multiple === false ) { $ unique [ ] = $ pdf_file ; } $ cmd_files .= ( string ) " " . escapeshellarg ( addslashes ( stripslashes ( $ pdf_file ) ) ) . " " ; } unset ( $ pdf_file ) ; if ( empty ( $ cmd_files ) ) { throw new FileException ( ( string ) "No valid File within the whole array" , ( int ) Config :: get ( 'file_error' ) , ( int ) Config :: get ( 'error_lvl_low' ) , ( string ) __FILE__ , ( string ) __LINE__ ) ; } $ cmd .= ( string ) $ cmd_files ; if ( empty ( $ target_file_name ) ) { $ target_file_name = Config :: get ( 'storage_root' ) . "/" . Config :: get ( 'pdf_default_path' ) . "/concat_" . Tool :: random_string ( 10 ) . ".pdf" ; } system ( $ cmd . " cat output $target_file_name" , $ output ) ; if ( strpos ( strtolower ( $ output ) , 'err' ) !== false ) { throw new FileException ( ( string ) "Error generating the pdf file $cmd\n$output" , ( int ) Config :: get ( 'file_error' ) , ( int ) Config :: get ( 'error_lvl_low' ) , ( string ) __FILE__ , ( string ) __LINE__ ) ; } unset ( $ cmd , $ output ) ; } catch ( FileException $ e ) { throw $ e ; } return true ; }
Concats multiple pdfs together using the shell program pdftk
54,253
protected function stopMaster ( $ pid , $ quit = true ) { $ this -> stdout ( "Stop the manager(PID:$pid)" ) ; ProcessUtil :: killAndWait ( $ pid , SIGTERM , 'manager' ) ; $ this -> stdout ( sprintf ( "\n%s\n" ) , Cli :: color ( 'The manager process stopped' , Cli :: FG_GREEN ) ) ; if ( $ quit ) { $ this -> quit ( ) ; } clearstatcache ( ) ; $ this -> stdout ( 'Begin restart manager ...' ) ; }
Do shutdown Manager
54,254
protected function stopWorkers ( $ signal = SIGTERM ) { if ( ! $ this -> workers ) { $ this -> log ( 'No child process(worker) need to stop' , ProcessLogger :: PROC_INFO ) ; return false ; } return ProcessUtil :: stopChildren ( $ this -> workers , $ signal , [ 'beforeStops' => function ( $ sigText ) { $ this -> log ( "Stopping workers({$sigText}) ..." , ProcessLogger :: PROC_INFO ) ; } , 'beforeStop' => function ( $ pid , $ info ) { $ this -> log ( "Stopping worker #{$info['id']}(PID:$pid)" , ProcessLogger :: PROC_INFO ) ; } , ] ) ; }
Stops all running workers
54,255
public function addGoogleAnalytics ( $ boot = false , $ user = '' ) { $ this -> google [ 'boot' ] = $ boot ; $ this -> google [ 'user' ] = $ user ; }
Add google analytics
54,256
public function init ( ) { foreach ( $ this -> soilFunc as $ key => $ value ) { if ( is_bool ( $ value ) && $ value === true ) { add_theme_support ( $ key ) ; } } $ google = $ this -> google ; if ( is_bool ( $ google [ 'boot' ] ) && $ google [ 'boot' ] === true ) { add_theme_support ( 'soil-google-analytics' , $ google [ 'user' ] ) ; } }
Active soil thme supports .
54,257
public static function send ( $ address , $ subject , $ body , $ account = 'default' ) { $ HTML = true ; $ accounts = \ Phramework \ Phramework :: getSetting ( 'email' ) ; if ( ! $ accounts || ! isset ( $ accounts [ 'default' ] ) ) { throw new \ Exception ( 'email setting is required' ) ; } if ( ! isset ( $ accounts [ $ account ] ) ) { $ account = 'default' ; } $ headers = [ ] ; $ headers [ ] = "MIME-Version: 1.0" . "\r\n" ; if ( ! $ HTML ) { $ headers [ ] = 'Content-Type: text/plain;charset=utf-8' . "\r\n" ; } else { $ headers [ ] = 'Content-Type: text/html;charset=utf-8' . "\r\n" ; } $ headers [ ] = 'From: ' . $ accounts [ $ account ] [ 'name' ] . ' <' . $ accounts [ $ account ] [ 'mail' ] . '>' . "\r\n" ; $ headers [ ] = 'Reply-To: ' . $ accounts [ $ account ] [ 'name' ] . ' <' . $ accounts [ $ account ] [ 'mail' ] . "\r\n" ; mail ( $ address , $ subject , $ body , implode ( '' , $ headers ) , ( '-f' . $ accounts [ $ account ] [ 'mail' ] ) ) ; }
Send an e - mail
54,258
public function apply ( $ testable , array $ config = array ( ) ) { $ lines = $ testable -> lines ( ) ; $ tokens = $ testable -> tokens ( ) ; $ lastBlankLineId = - 2 ; foreach ( $ lines as $ lineId => $ line ) { $ lineNumber = $ lineId + 1 ; $ ignore = false ; $ key = $ testable -> findTokenByLine ( $ lineNumber ) ; if ( isset ( $ tokens [ $ key ] ) ) { $ token = $ tokens [ $ key ] ; $ ignore = in_array ( $ token [ 'id' ] , $ this -> ignoreableTokens , true ) ; } if ( ! $ ignore && preg_match ( '/^$/' , $ line ) === 1 ) { if ( $ lastBlankLineId + 1 === $ lineId ) { $ this -> addViolation ( array ( 'message' => 'Multiple blank lines.' , 'line' => $ lineNumber , ) ) ; } $ lastBlankLineId = $ lineId ; } } }
Will iterate over each line checking for blank lines
54,259
public function getData ( $ field = null ) { if ( empty ( $ field ) ) { return $ this -> data ; } if ( ! empty ( $ this -> data ) && array_key_exists ( $ field , $ this -> data ) ) { return $ this -> data [ $ field ] ; } return null ; }
Retrieve a data element that was validated .
54,260
public static function call ( $ state , $ params = array ( ) ) { $ results = array ( ) ; if ( isset ( self :: $ hook [ $ state ] ) ) { $ return = true ; foreach ( self :: $ hook [ $ state ] as $ f ) { if ( is_callable ( $ f ) ) { $ results [ ] = call_user_func ( $ f , array_merge ( array ( 'state' => $ state , 'timestamp' => time ( ) , ) , $ params ) ) ; } } } return $ results ; }
call no yield
54,261
public function getOptionsAction ( Request $ request , TranslatorInterface $ translator ) { $ entityAlias = $ request -> request -> get ( 'entity_alias' ) ; $ parentId = $ request -> request -> get ( 'parent_id' ) ; $ emptyValue = $ request -> request -> get ( 'empty_value' ) ; $ entities = $ this -> getParameter ( 'anacona16.dependent_forms_config' ) ; $ entityInformation = $ entities [ $ entityAlias ] ; if ( $ entityInformation [ 'role' ] !== 'IS_AUTHENTICATED_ANONYMOUSLY' ) { $ this -> denyAccessUnlessGranted ( $ entityInformation [ 'role' ] ) ; } $ qb = $ this -> getDoctrine ( ) -> getRepository ( $ entityInformation [ 'class' ] ) -> createQueryBuilder ( 'e' ) -> where ( 'e.' . $ entityInformation [ 'parent_property' ] . ' = :parent_id' ) -> orderBy ( 'e.' . $ entityInformation [ 'order_property' ] , $ entityInformation [ 'order_direction' ] ) -> setParameter ( 'parent_id' , $ parentId ) ; if ( null !== $ entityInformation [ 'callback' ] ) { $ repository = $ qb -> getEntityManager ( ) -> getRepository ( $ entityInformation [ 'class' ] ) ; if ( ! method_exists ( $ repository , $ entityInformation [ 'callback' ] ) ) { throw new \ InvalidArgumentException ( sprintf ( 'Callback function "%s" in Repository "%s" does not exist.' , $ entityInformation [ 'callback' ] , get_class ( $ repository ) ) ) ; } $ repository -> $ entityInformation [ 'callback' ] ( $ qb ) ; } $ results = $ qb -> getQuery ( ) -> getResult ( ) ; if ( empty ( $ results ) ) { return new Response ( '<option value="">' . $ translator -> trans ( $ entityInformation [ 'no_result_msg' ] ) . '</option>' ) ; } $ html = '' ; if ( $ emptyValue !== false ) { $ html .= '<option value="">' . $ translator -> trans ( $ emptyValue ) . '</option>' ; } $ propertyAccessor = PropertyAccess :: createPropertyAccessor ( ) ; foreach ( $ results as $ result ) { if ( $ entityInformation [ 'property' ] ) { $ resultString = $ propertyAccessor -> getValue ( $ result , $ entityInformation [ 'property' ] ) ; } else { $ resultString = ( string ) $ result ; } $ html .= sprintf ( '<option value="%s">%s</option>' , $ result -> getId ( ) , $ resultString ) ; } return new Response ( $ html ) ; }
This action handler the ajax call for a dependent field type .
54,262
public function send ( $ endpoint , $ options = [ ] , $ body = '' ) { return $ this -> client -> post ( $ endpoint . '?' . http_build_query ( $ options ) , [ 'body' => $ body , ] ) ; }
Send request to Endomondo old api .
54,263
public function requestAuthToken ( $ email , $ password ) { return $ this -> send ( self :: URL_AUTH , [ 'email' => $ email , 'password' => $ password , 'country' => 'EN' , 'deviceId' => Uuid :: uuid5 ( Uuid :: NAMESPACE_DNS , gethostname ( ) ) -> toString ( ) , 'action' => 'PAIR' , ] ) ; }
Request auth token from Endomondo .
54,264
public function getShortUrl ( $ url ) { $ postData = [ 'longUrl' => $ url ] ; $ jsonData = json_encode ( $ postData ) ; $ token = $ this -> getToken ( ) ; $ url = $ this -> getUrl ( ) ; if ( true === empty ( $ token ) ) { throw new \ LogicException ( "Missing pm_tool.google_link_shortener.token" ) ; } if ( true === empty ( $ url ) ) { throw new \ LogicException ( "Missing pm_tool.google_link_shortener.url" ) ; } $ curlObj = curl_init ( ) ; curl_setopt ( $ curlObj , CURLOPT_URL , sprintf ( "%s?key=%s" , $ url , $ token ) ) ; curl_setopt ( $ curlObj , CURLOPT_RETURNTRANSFER , 1 ) ; curl_setopt ( $ curlObj , CURLOPT_SSL_VERIFYPEER , 0 ) ; curl_setopt ( $ curlObj , CURLOPT_HEADER , 0 ) ; curl_setopt ( $ curlObj , CURLOPT_HTTPHEADER , array ( 'Content-type:application/json' ) ) ; curl_setopt ( $ curlObj , CURLOPT_POST , 1 ) ; curl_setopt ( $ curlObj , CURLOPT_POSTFIELDS , $ jsonData ) ; $ response = curl_exec ( $ curlObj ) ; $ json = json_decode ( $ response , true ) ; curl_close ( $ curlObj ) ; if ( isset ( $ json [ 'id' ] ) ) { return $ json [ 'id' ] ; } return 'Api Error: ' . print_r ( $ json , true ) ; }
Get Short URL
54,265
public function write ( string $ key , $ data , int $ ttl = 0 ) : bool { $ ttl = ( ( int ) $ ttl <= 0 ) ? 0 : ( ( int ) $ ttl + time ( ) ) ; $ file = $ this -> cacheFile ( $ key ) ; $ data = var_export ( [ 'ttl' => $ ttl , 'data' => serialize ( $ data ) ] , true ) ; $ data = "<?php\n\rreturn " . preg_replace ( '/\s=>\s(\n\s+)array\s\(\n/' , " => array (\n" , $ data ) . ';' ; return $ this -> fileWrite ( $ file , $ data ) ; }
Write to cache
54,266
public function setInitValues ( array $ values ) { if ( isset ( $ this -> data [ 'isSend' ] ) == false || $ this -> data [ 'isSend' ] != true ) { foreach ( $ this -> elements as $ name => $ element ) { if ( $ element instanceof ElementInterface ) { if ( array_key_exists ( $ name , $ values ) ) { $ element -> setValue ( $ values [ $ name ] ) ; } } } } }
Set default values to the form only when the form ist not posted
54,267
public function getMethods ( $ order = FALSE ) { if ( ! $ this -> methods || $ order !== FALSE ) { $ class = $ this -> getNamespace ( ) . '\Method' ; $ params [ 'where' ] [ ] = array ( 'module_id' , $ this -> get ( 'id' ) ) ; $ params [ 'orderby' ] = $ order ? : 'ABS(name)' ; $ this -> methods = $ class :: _getObjects ( $ params ) ; } return $ this -> methods ; }
Return an array of module method objects
54,268
public function getMethod ( $ method ) { $ this -> getMethods ( ) ; foreach ( $ this -> methods as $ obj ) { if ( strtolower ( $ obj -> get ( 'name' ) ) == strtolower ( $ method ) ) { return $ obj ; } } return FALSE ; }
Return a module method if it exists
54,269
public function checkMethod ( $ method ) { $ method = strtolower ( $ method ) ; $ class = $ this -> getModuleClass ( ) ; $ this -> getMethods ( ) ; foreach ( $ this -> methods as $ obj ) { if ( strtolower ( $ obj -> get ( 'name' ) ) == $ method && method_exists ( $ class , $ method ) ) { return TRUE ; } } return FALSE ; }
Check a module method if it exists
54,270
public function callMethod ( & $ api , $ module , $ method , $ args = array ( ) ) { $ class = $ this -> getModuleClass ( $ module ) ; $ obj = new $ class ; $ obj -> api = $ api ; if ( $ obj -> callInit ( $ this , $ method , $ args ) ) { $ return = call_user_func_array ( array ( $ obj , $ method ) , array ( $ args ) ) ; } return $ obj -> getResult ( ) ; }
Call a module method
54,271
public function getModuleClass ( $ name = FALSE ) { if ( $ name === FALSE ) { $ name = $ this -> get ( 'name' ) ; } $ arr = explode ( '.' , $ name ) ; foreach ( $ arr as & $ val ) { $ val = ucfirst ( $ val ) ; } $ name = implode ( '\\' , $ arr ) ; return get_called_class ( ) . '\\' . $ name ; }
Return the class name of the module
54,272
public function isClosed ( ) : bool { if ( $ this -> isEmpty ( ) ) { return true ; } $ start = $ this -> getStartPoint ( ) ; $ end = $ this -> getEndPoint ( ) ; return $ start === $ end ; }
Indicates whether the Curve is closed .
54,273
public function getLength ( bool $ _3D = false ) : float { $ event = new MeasurementOpEvent ( $ this , [ '3D' => $ _3D ] ) ; $ this -> fireOperationEvent ( MeasurementOpEvent :: LENGTH_EVENT , $ event ) ; return $ event -> getResults ( ) ; }
Gets the length of this Curve in its associated spatial reference .
54,274
public function onBootstrap ( EventInterface $ e ) { if ( Console :: isConsole ( ) ) return false ; $ events = $ e -> getApplication ( ) -> getEventManager ( ) ; $ events -> attach ( new AdminRouteListener ( ) ) ; }
Listen to the bootstrap MvcEvent
54,275
public function getConfig ( ) { $ conf = [ ] ; foreach ( glob ( __DIR__ . '/../../config/*.config.php' ) as $ conFile ) { $ conFile = include_once $ conFile ; if ( is_array ( $ conFile ) ) $ conf = \ Poirot \ Core \ array_merge ( $ conf , $ conFile ) ; } return $ conf ; }
Returns configuration to merge with application configuration
54,276
public function createFromUpload ( $ filename = FALSE , $ newX = FALSE , $ newY = FALSE , $ method = self :: RESIZE_MAX , $ proportional = FALSE , $ replace = FALSE ) { if ( ! $ this -> path ) { new \ Sonic \ Message ( 'error' , 'No absolute path set!' ) ; return FALSE ; } if ( ! ( $ objImage = self :: _Load ( $ this -> tmpPath ( ) ) ) ) { return FALSE ; } if ( $ newX !== FALSE && $ newY !== FALSE ) { $ objImage = self :: _Resize ( $ objImage , $ newX , $ newY , $ method , $ proportional ) ; } if ( ! $ filename ) { $ filename = $ this -> getFilename ( ) ; } if ( ! self :: _Save ( $ objImage , $ this -> getPath ( ) . $ filename , $ replace ) ) { new \ Sonic \ Message ( 'error' , 'Could not save image: ' . $ filename ) ; return FALSE ; } imagedestroy ( $ objImage ) ; return TRUE ; }
Load resize and save an image from an uploaded file
54,277
public static function _Load ( $ path ) { if ( ! parent :: _Exists ( $ path ) ) { return FALSE ; } $ image = FALSE ; switch ( self :: _getMIME ( $ path ) ) { case IMAGETYPE_GIF : $ image = imagecreatefromgif ( $ path ) ; break ; case IMAGETYPE_PNG : $ resImg = imagecreatefrompng ( $ path ) ; break ; default : $ image = imagecreatefromjpeg ( $ path ) ; break ; } return $ image ; }
Load image as a resource
54,278
public static function _Save ( $ image , $ path , $ replace = FALSE ) { if ( $ replace === FALSE && parent :: _Exists ( $ path ) ) { return FALSE ; } switch ( parent :: _getExtension ( $ path ) ) { case 'gif' : if ( ! imagegif ( $ image , $ path ) ) { return FALSE ; } break ; case 'png' : if ( ! imagepng ( $ image , $ path ) ) { return FALSE ; } break ; default : if ( ! imagejpeg ( $ image , $ path , 80 ) ) { return FALSE ; } break ; } return TRUE ; }
Save an image resource
54,279
public static function _Resize ( $ image , $ newX , $ newY , $ method = self :: RESIZE_MAX , $ proportional = TRUE ) { $ origX = imagesx ( $ image ) ; $ origY = imagesy ( $ image ) ; $ canvasX = $ newX ; $ canvasY = $ newY ; switch ( $ method ) { case self :: RESIZE_MAX : if ( $ origX / $ newX > $ origY / $ newY ) { $ newY = ( $ newX / $ origX ) * $ origY ; $ canvasY = $ newY ; } else { $ newX = ( $ newY / $ origY ) * $ origX ; $ canvasX = $ newX ; } break ; case self :: RESIZE_MIN : if ( $ origX / $ newX > $ origY / $ newY ) { $ newX = ( $ newY / $ origY ) * $ origX ; $ canvasX = $ newX ; } else { $ newY = ( $ newX / $ origX ) * $ origY ; $ canvasY = $ newY ; } break ; case self :: RESIZE_EXACT : if ( $ proportional ) { if ( $ origX / $ newX > $ origY / $ newY ) { $ newY = ( $ newX / $ origX ) * $ origY ; } else { $ newX = ( $ newY / $ origY ) * $ origX ; } } break ; case self :: RESIZE_CROP : if ( $ proportional ) { if ( $ origX / $ newX > $ origY / $ newY ) { $ newX = ( $ newY / $ origY ) * $ origX ; } else { $ newY = ( $ newX / $ origX ) * $ origY ; } } break ; } $ posX = ( $ canvasX - $ newX ) / 2 ; $ posY = ( $ canvasY - $ newY ) / 2 ; $ newImage = imagecreatetruecolor ( $ canvasX , $ canvasY ) ; $ colourWhite = imagecolorallocate ( $ newImage , 0xFF , 0xFF , 0xFF ) ; imagefill ( $ newImage , 0 , 0 , $ colourWhite ) ; imagecopyresampled ( $ newImage , $ image , $ posX , $ posY , 0 , 0 , $ newX , $ newY , $ origX , $ origY ) ; return $ newImage ; }
Resize an image resource
54,280
public static function _copyResize ( $ originalPath , $ newPath , $ newX , $ newY , $ method = self :: RESIZE_MAX , $ proportional = TRUE ) { if ( ! parent :: _Exists ( $ originalPath ) ) { return FALSE ; } $ image = self :: _Load ( $ originalPath ) ; $ newImage = self :: _Resize ( $ image , $ newX , $ newY , $ method , $ proportional ) ; if ( ! self :: _Save ( $ newImage , $ newPath , TRUE ) ) { new \ Sonic \ Message ( 'error' , 'Could not save image: ' . $ newPath ) ; imagedestroy ( $ image ) ; imagedestroy ( $ newImage ) ; return FALSE ; } imagedestroy ( $ image ) ; imagedestroy ( $ newImage ) ; return TRUE ; }
Resize and copy an image
54,281
public function createDriver ( ) : Driver { $ classname = '\ntentan\atiaa\drivers\\' . Text :: ucamelize ( $ this -> config [ 'driver' ] ) . 'Driver' ; return new $ classname ( $ this -> config ) ; }
Create a new driver based on the configuration in the factory .
54,282
public function remember ( $ key , $ default , $ minutes = 60 , $ function = 'put' ) { $ this -> _cleanCache ( ) ; if ( ! is_null ( $ item = $ this -> get ( $ key , null ) ) ) { return $ item ; } $ this -> $ function ( $ key , $ default = Utils :: value ( $ default ) , $ minutes ) ; return $ default ; }
Get an item from the cache or cache and return the default value .
54,283
public function execute ( ServerRequestInterface $ request , string $ eventBaseName ) { $ processEventName = sprintf ( '%s%s' , $ this -> processSuffix , $ eventBaseName ) ; $ this -> logger -> debug ( 'Processing started' , [ 'Request method' => $ request -> getMethod ( ) , 'Event name' => $ processEventName , 'Controller' => static :: class ] ) ; $ processEvent = new ProcessEvent ( $ request ) ; try { $ processEvent = $ this -> eventDispatcher -> dispatch ( $ processEventName , $ processEvent ) ; } catch ( \ Exception $ processException ) { $ this -> logger -> error ( 'Process error' , [ 'Request method' => $ request -> getMethod ( ) , 'Event name' => $ processEventName , 'Controller' => static :: class , 'Exception' => $ processException ] ) ; $ processEvent -> setResponse ( $ processException ) ; } $ responseEvent = new ResponseEvent ( ) ; $ responseEvent -> setResponse ( $ processEvent -> getResponse ( ) ) ; $ responseEventName = sprintf ( '%s%s' , $ this -> responseSuffix , $ eventBaseName ) ; $ this -> logger -> debug ( 'Rendering started' , [ 'Event name' => $ responseEventName , ] ) ; $ responseEvent = $ this -> eventDispatcher -> dispatch ( $ responseEventName , $ responseEvent ) ; return $ responseEvent -> getResponse ( ) ; }
Execute a request process .
54,284
protected function fixOptionalSlashes ( $ string ) { $ parts = explode ( '/(' , $ string ) ; $ regex = '' ; $ num = count ( $ parts ) ; $ counter = 1 ; foreach ( $ parts as $ part ) { $ regex .= $ part ; if ( $ num > $ counter ) { if ( preg_match ( '/\)\?$/' , $ parts [ $ counter ] ) ) { $ regex .= '(/)?(' ; } else { $ regex .= '/(' ; } } $ counter ++ ; } return $ regex ; }
Takes the input string and splits the params up and fixes the slashes depending on if the param name following the slash is optional or not . If the following param name is optional the slash must also be optional .
54,285
private function getMappings ( ) : Iterator { if ( $ this -> mappings === null ) { $ filePaths = [ ] ; foreach ( $ this -> mappingFilePaths as $ mappingFilePath ) { $ newFilePaths = iterator_to_array ( new SplFileObject ( $ mappingFilePath , 'r' ) ) ; $ filePaths = array_merge ( $ filePaths , $ newFilePaths ) ; } $ this -> mappings = new ArrayIterator ( array_map ( function ( string $ mapping ) : FileMappingInterface { return new UnixFileMapping ( $ this -> sourceDirectory , $ this -> targetDirectory , trim ( $ mapping ) ) ; } , array_filter ( $ filePaths ) ) ) ; } return $ this -> mappings ; }
Get the mappings .
54,286
public function getCreationInstanceName ( ) { return sizeof ( $ this -> instanceNames ) ? $ this -> instanceNames [ sizeof ( $ this -> instanceNames ) - 1 ] : null ; }
Retrieve name of the instance that is currently being created or initialized
54,287
public function getCreationInstanceOptions ( ) { return sizeof ( $ this -> instanceOptions ) ? $ this -> instanceOptions [ sizeof ( $ this -> instanceOptions ) - 1 ] : null ; }
Retrieve options for the instance that is currently being created or initialized
54,288
public function getCreationInstanceFetchAsService ( ) { return sizeof ( $ this -> instanceAsService ) ? $ this -> instanceAsService [ sizeof ( $ this -> instanceAsService ) - 1 ] : null ; }
Retrieve fetch as service flag for instance that is currently being initialized
54,289
public function getProxyGenerator ( ) { if ( ! $ this -> proxyGenerator ) { $ this -> proxyGenerator = new ServiceProxyGenerator ( $ this -> getProxyDir ( ) , $ this -> getProxyNs ( ) ) ; } return $ this -> proxyGenerator ; }
Retrieve proxy generator
54,290
public function wrapService ( $ serviceId , $ instance ) { $ serviceId = $ this -> canonicalizeName ( $ serviceId ) ; $ proxy = null ; if ( ( $ fqcn = $ this -> getCache ( ) -> getItem ( self :: CACHE_ID_PREFIX . $ serviceId ) ) && class_exists ( $ fqcn ) && $ this -> getProxyAutoCreateStrategy ( ) !== self :: PROXY_AUTO_CREATE_ALWAYS ) { $ proxy = new $ fqcn ( $ instance ) ; } else { $ className = get_class ( $ instance ) ; $ proxyGenerator = $ this -> getProxyGenerator ( ) ; $ fqcn = $ proxyGenerator -> getProxyClassName ( $ className ) ; $ file = $ proxyGenerator -> getProxyFilename ( $ className ) ; if ( $ this -> getProxyAutoCreateStrategy ( ) === self :: PROXY_AUTO_CREATE_MTIME && file_exists ( $ file ) ) { $ reflection = new ReflectionClass ( $ className ) ; $ instanceFile = $ reflection -> getFileName ( ) ; if ( filemtime ( $ instanceFile ) > filemtime ( $ file ) ) { unlink ( $ file ) ; } } if ( ! file_exists ( $ file ) || $ this -> getProxyAutoCreateStrategy ( ) === self :: PROXY_AUTO_CREATE_ALWAYS ) { try { $ config = $ this -> getAnnotationBuilder ( ) -> getServiceSpecification ( $ instance ) ; } catch ( \ Exception $ e ) { throw new AnnotationException ( sprintf ( 'Unable to parse annotations for service %s (%s). Reason: %s' , $ serviceId , $ file , $ e -> getMessage ( ) ) ) ; } $ config [ 'service_id' ] = $ serviceId ; $ proxyGenerator -> generateProxyClass ( $ instance , $ config ) ; } require_once $ file ; $ proxy = new $ fqcn ( $ instance ) ; $ this -> getCache ( ) -> setItem ( self :: CACHE_ID_PREFIX . $ serviceId , $ fqcn ) ; } foreach ( $ this -> initializers as $ initializer ) { if ( $ initializer instanceof InitializerInterface ) { $ initializer -> initialize ( $ proxy , $ this ) ; } elseif ( is_object ( $ initializer ) && is_callable ( $ initializer ) ) { $ initializer ( $ proxy , $ this ) ; } else { call_user_func ( $ initializer , $ proxy , $ this ) ; } } return $ proxy ; }
Wrap service with proxy instance
54,291
public function getOptionalProperty ( $ property , $ default = null ) { \ Assert \ that ( $ property ) -> string ( ) -> notEmpty ( ) ; if ( property_exists ( $ this -> description , $ property ) === false ) { return $ default ; } return $ this -> getMandatoryProperty ( $ property ) ; }
Get an optional property .
54,292
public function getMandatoryProperty ( $ property ) { \ Assert \ that ( $ property ) -> string ( ) -> notEmpty ( ) ; if ( isset ( $ this -> description -> { $ property } ) === false ) { throw InvalidDescriptionException :: missingMandatoryProperty ( $ property ) ; } if ( $ this -> description -> { $ property } instanceof \ stdClass ) { return new static ( $ this -> description -> { $ property } ) ; } return $ this -> description -> { $ property } ; }
Get a mandatory property .
54,293
public static function getProvider ( $ classname ) { if ( array_key_exists ( $ classname , self :: $ providers ) ) { return self :: $ providers [ $ classname ] ; } $ provider = new $ classname ; if ( ! ( $ provider instanceof ServiceProviderInterface ) ) { throw new \ InvalidArgumentException ( "$classname is not a valid ServiceProviderInterface instance" ) ; } self :: $ providers [ $ classname ] = $ provider ; return self :: $ providers [ $ classname ] ; }
Obtains a provider class instance
54,294
protected function getSourceRow ( ) : array { $ row = $ this -> dictionary -> getRow ( $ this -> sourceId ) ; if ( ! $ row ) { throw new TranslationNotFoundException ( $ this -> getKey ( ) , $ this -> dictionary ) ; } return $ row ; }
Fetch the source row .
54,295
protected function getTargetRow ( ) : array { $ row = $ this -> dictionary -> getRow ( $ this -> targetId ) ; if ( ! $ row ) { throw new TranslationNotFoundException ( $ this -> getKey ( ) , $ this -> dictionary ) ; } return $ row ; }
Fetch the target row .
54,296
protected function parsePostBody ( $ data ) { if ( ! empty ( $ data [ "body" ] ) && ! empty ( $ data [ "headers" ] [ "Content-Type" ] ) ) { $ matched = preg_match ( "/boundary=(.*)$/" , $ data [ "headers" ] [ "Content-Type" ] , $ matches ) ; if ( ! $ matched ) { parse_str ( urldecode ( $ data [ "body" ] ) , $ params ) ; } else { $ boundary = $ matches [ 1 ] ; $ blocks = preg_split ( "/-+$boundary/" , $ data [ "body" ] ) ; array_pop ( $ blocks ) ; foreach ( $ blocks as $ block ) { if ( ! empty ( $ block ) ) { if ( strpos ( $ block , "application/octet-stream" ) !== false ) { preg_match ( "/name=\"([^\"]*)\".*stream[\n|\r]+([^\n\r].*)?$/s" , $ block , $ matches ) ; $ data [ "files" ] [ $ matches [ 1 ] ] = $ matches [ 2 ] ; } else { preg_match ( "/name=\"([^\"]*)\"[\n|\r]+([^\n\r].*)?\r$/s" , $ block , $ matches ) ; $ data [ "params" ] [ $ matches [ 1 ] ] = $ matches [ 2 ] ; } } } } } return $ data ; }
Parse raw http request body
54,297
public function setPath ( string $ path ) : void { if ( ! is_writable ( $ path ) ) { throw new Exception ( "The path to the cache is not writable." ) ; } $ this -> cachePath = $ path ; }
Set the base for the cache path where all items are stored .
54,298
public function fileCacheSet ( $ key , $ value , $ cache_time = 86400 ) { if ( $ this -> isSingle ( ) ) { FilecacheKit :: add ( $ key , $ value , $ cache_time ) ; } }
File Cache Set
54,299
public function addEntityReflection ( EntityReflectionInterface $ entityReflection ) { $ slug = $ entityReflection -> getSlug ( ) ; if ( isset ( $ this -> entitiesBySlug [ $ slug ] ) ) { throw new DomainErrorException ( 'Two entities are registered with the same "' . $ slug . '" slug!' ) ; } $ this -> entitiesBySlug [ $ slug ] = $ entityReflection ; }
Add an entity to the pool