idx
int64
0
60.3k
question
stringlengths
64
4.24k
target
stringlengths
5
618
12,200
protected function logToFile ( $ message ) { if ( isset ( $ this -> logger ) && $ this -> logger instanceof \ sb \ Logger \ Base ) { return $ this -> logger -> { $ this -> log_name } ( $ message ) ; } }
Logs to file
12,201
public function getCommandlineInvocation ( $ method_name , $ http_host = null , $ http_args = [ ] ) { $ command_prefix = "php " . ROOT . "/public/index.php" ; preg_match ( '/Controllers.([^:]+)::([A-Za-z_]+)/' , $ method_name , $ matches ) ; if ( count ( $ matches ) !== 3 ) { return '' ; } $ class_name = strtolower ( $ matches [ 1 ] ) ; $ class_name = preg_replace ( '/\\\/' , '_' , $ class_name ) ; $ method_name = strtolower ( $ matches [ 2 ] ) ; $ request_arg = "/$class_name/$method_name" ; if ( ! empty ( $ http_args ) ) { $ request_arg .= "?" . http_build_query ( $ http_args ) ; } if ( is_null ( $ http_host ) ) { $ http_host = \ sb \ Gateway :: $ http_host ; } return "$command_prefix --request=$request_arg --http_host=$http_host" ; }
Returns the name of a controller method in a format that can be used in a commandline invocation .
12,202
private function load_cache_settings ( ) { if ( $ this -> app -> isset_shared_object ( 'is_valid_hook_cache' ) ) { return ; } $ this -> app -> set_shared_object ( 'is_valid_hook_cache' , ! empty ( $ this -> app -> get_config ( 'config' , 'cache_filter_result' ) ) ) ; $ prevent_cache = $ this -> app -> get_config ( 'config' , 'cache_filter_exclude_list' , [ ] ) ; $ prevent_cache = empty ( $ prevent_cache ) ? [ ] : array_combine ( $ prevent_cache , array_fill ( 0 , count ( $ prevent_cache ) , true ) ) ; $ this -> app -> set_shared_object ( 'prevent_hook_cache' , $ prevent_cache ) ; $ this -> app -> set_shared_object ( 'hook_cache' , [ ] ) ; }
load cache settings
12,203
public function getSourceInstance ( $ type , $ name , array $ parameters , array $ globalParameters = array ( ) ) { $ sourceObj = null ; $ sourceConfig = $ this -> getSourceConfig ( $ name , $ type , $ parameters , $ globalParameters ) ; if ( $ sourceConfig instanceof SourceConfig ) { switch ( $ type ) { case SourceConfig :: SOURCE_TYPE_IMAP : $ sourceObj = new Imap ( ) ; break ; case SourceConfig :: SOURCE_TYPE_POP : $ sourceObj = new Pop ( ) ; break ; default : throw new Exception \ BadSourceConfigConfigurationException ( sprintf ( "Unrecognized Parser Source type '%s'. Accepted values are: '%s'" , $ type , SourceConfig :: SOURCE_TYPE_IMAP ) ) ; } if ( $ sourceObj instanceof SourceInterface ) { $ sourceObj -> setConfig ( $ sourceConfig ) ; } else { throw new Exception \ BadSourceConfigConfigurationException ( sprintf ( "Unexpected object type: expected 'Msl\ResourceProxy\Source\SourceInterface' for type '%s' but got '%s'." , $ type , get_class ( $ sourceObj ) ) ) ; } } else { throw new Exception \ BadSourceConfigConfigurationException ( sprintf ( "Unexpected object type: expected 'Msl\ResourceProxy\Source\SourceConfig' for type '%s' but got '%s'." , $ type , get_class ( $ sourceConfig ) ) ) ; } return $ sourceObj ; }
Gets a Source instance according to the type .
12,204
public function buildOrder ( $ meta , $ tableAlias = null ) { $ metaFields = $ meta ? $ meta -> fields : null ; $ order = $ this -> order ; if ( $ meta && $ meta -> defaultOrder && $ order !== null ) { $ order = $ meta -> defaultOrder ; } if ( $ order ) { if ( is_array ( $ order ) ) { $ oClauses = '' ; foreach ( $ order as $ field => $ dir ) { if ( $ oClauses ) { $ oClauses .= ', ' ; } if ( ! is_string ( $ field ) ) { $ field = $ dir ; $ dir = '' ; } $ name = ( isset ( $ metaFields [ $ field ] ) ? $ metaFields [ $ field ] [ 'name' ] : $ field ) ; $ qname = $ name [ 0 ] == '`' ? $ name : '`' . $ name . '`' ; $ qname = ( $ tableAlias ? $ tableAlias . '.' : '' ) . $ qname ; $ oClauses .= $ qname ; if ( $ dir ) { if ( $ dir === true ) { $ dir = 'asc' ; } if ( isset ( $ dir [ 3 ] ) && ( $ dir [ 0 ] == 'd' || $ dir [ 0 ] == 'D' ) && ( $ dir [ 1 ] == 'e' || $ dir [ 1 ] == 'E' ) && ( $ dir [ 2 ] == 's' || $ dir [ 2 ] == 'S' ) && ( $ dir [ 3 ] == 'c' || $ dir [ 3 ] == 'C' ) ) { $ oClauses .= ' desc' ; } elseif ( ! isset ( $ dir [ 2 ] ) || ! ( ( $ dir [ 0 ] == 'a' || $ dir [ 0 ] == 'A' ) && ( $ dir [ 1 ] == 's' || $ dir [ 1 ] == 'S' ) && ( $ dir [ 2 ] == 'c' || $ dir [ 2 ] == 'C' ) ) ) { throw new \ UnexpectedValueException ( "Order direction must be 'asc' or 'desc', found " . $ dir ) ; } } } $ order = $ oClauses ; } else { if ( $ metaFields && strpos ( $ order , '{' ) !== false ) { $ order = static :: replaceFields ( $ meta , $ order , $ tableAlias ) ; } } } return $ order ; }
damn this is pretty much identical to the above . FIXME etc .
12,205
protected function queueHandler ( $ class , $ method , $ arguments ) { list ( $ listener , $ job ) = $ this -> createListenerAndJob ( $ class , $ method , $ arguments ) ; $ connection = $ this -> resolveQueue ( ) -> connection ( isset ( $ listener -> connection ) ? $ listener -> connection : null ) ; $ queue = isset ( $ listener -> queue ) ? $ listener -> queue : null ; isset ( $ listener -> delay ) ? $ connection -> laterOn ( $ queue , $ listener -> delay , $ job ) : $ connection -> pushOn ( $ queue , $ job ) ; }
Queue the handler class .
12,206
protected function createListenerAndJob ( $ class , $ method , $ arguments ) { $ listener = ( new ReflectionClass ( $ class ) ) -> newInstanceWithoutConstructor ( ) ; return [ $ listener , $ this -> propogateListenerOptions ( $ listener , new CallQueuedListener ( $ class , $ method , $ arguments ) ) ] ; }
Create the listener and job for a queued listener .
12,207
protected function propogateListenerOptions ( $ listener , $ job ) { return tap ( $ job , function ( $ job ) use ( $ listener ) { $ job -> tries = isset ( $ listener -> tries ) ? $ listener -> tries : null ; $ job -> timeout = isset ( $ listener -> timeout ) ? $ listener -> timeout : null ; } ) ; }
Propogate listener options to the job .
12,208
public static function isAccessTokenValid ( $ token ) { if ( empty ( $ token ) ) { return false ; } $ data = Yii :: $ app -> jwt -> getValidationData ( ) ; $ data -> setIssuer ( Yii :: getAlias ( "@restIssuer" ) ) ; $ data -> setAudience ( Yii :: getAlias ( "@restAudience" ) ) ; $ data -> setId ( Yii :: getAlias ( "@restId" ) + strtotime ( date ( 'Y-m-d' , time ( ) ) ) , true ) ; if ( is_string ( $ token ) ) $ token = Yii :: $ app -> jwt -> getParser ( ) -> parse ( $ token ) ; return $ token -> validate ( $ data ) ; }
Validates access_token .
12,209
public function generateAccessToken ( ) { $ signer = new Sha256 ( ) ; $ token = Yii :: $ app -> jwt -> getBuilder ( ) -> setIssuer ( Yii :: getAlias ( "@restIssuer" ) ) -> setAudience ( Yii :: getAlias ( "@restAudience" ) ) -> setId ( Yii :: getAlias ( "@restId" ) + strtotime ( date ( 'Y-m-d' , time ( ) ) ) , true ) -> setExpiration ( time ( ) + Yii :: $ app -> params [ 'accessTokenExpire' ] ) -> setIssuedAt ( time ( ) ) -> sign ( $ signer , Yii :: $ app -> jwt -> key ) -> getToken ( ) ; $ this -> access_token = ( string ) $ token ; }
Generates new api access token .
12,210
public function getAst ( Node \ Node $ b , $ path = '' ) { $ ret = array ( 'type' => str_replace ( 'Zicht\Tool\Script\Node\\' , '' , get_class ( $ b ) ) ) ; if ( $ b instanceof Node \ Branch ) { if ( count ( $ b -> nodes ) ) { $ ret [ 'nodes' ] = array ( ) ; foreach ( $ b -> nodes as $ n ) { if ( null === $ n ) { $ ret [ 'nodes' ] [ ] = $ n ; } else { if ( ! $ n instanceof Node \ Node ) { throw new \ InvalidArgumentException ( "Invalid child node in " . Util :: toPhp ( $ path ) ) ; } $ ret [ 'nodes' ] [ ] = $ this -> getAst ( $ n ) ; } } } } return $ ret ; }
Returns the AST for a specified node as an array representation
12,211
public function isDue ( ) { $ expression = $ this -> getExpression ( ) ; $ cron = CronExpression :: factory ( $ expression ) ; return $ cron -> isDue ( ) ; }
Check cron expression
12,212
public function getExpression ( ) { $ expression = array ( $ this -> minute , $ this -> hour , $ this -> dayOfMonth , $ this -> month , $ this -> dayOfWeek ) ; return implode ( ' ' , $ expression ) ; }
Return the cron expression
12,213
public function getArgument ( InputInterface $ input , $ key ) { if ( $ input -> hasArgument ( $ key ) ) { return $ input -> getArgument ( $ key ) ; } if ( isset ( $ this -> arguments [ $ key ] ) ) { return $ this -> arguments [ $ key ] ; } return false ; }
Get Cron arguments
12,214
public function execute ( $ cmd , & $ captureOutput = null ) { $ isInteractive = $ this -> container -> get ( 'INTERACTIVE' ) ; $ process = $ this -> createProcess ( $ isInteractive ) ; if ( $ isInteractive ) { $ process -> setCommandLine ( sprintf ( '/bin/bash -c \'%s\'' , $ cmd ) ) ; } else { $ process -> setInput ( $ cmd ) ; } if ( null !== $ captureOutput && false === $ isInteractive ) { $ process -> run ( function ( $ type , $ data ) use ( & $ captureOutput ) { $ captureOutput .= $ data ; } ) ; } else { $ process -> run ( array ( $ this , 'processCallback' ) ) ; } $ ret = $ process -> getExitCode ( ) ; if ( $ ret != 0 ) { if ( ( int ) $ ret == Container :: ABORT_EXIT_CODE ) { throw new ExecutionAbortedException ( "Command '$cmd' was aborted" ) ; } else { throw new \ UnexpectedValueException ( "Command '$cmd' failed with exit code {$ret}" ) ; } } return $ ret ; }
Executes the passed command line in the shell .
12,215
protected function createProcess ( $ interactive = false ) { $ process = new Process ( $ this -> container -> resolve ( 'SHELL' ) , null , null , null , null , [ ] ) ; if ( $ interactive ) { $ process -> setTty ( true ) ; } else { if ( $ this -> container -> has ( 'TIMEOUT' ) && $ timeout = $ this -> container -> get ( 'TIMEOUT' ) ) { $ process -> setTimeout ( $ this -> container -> get ( 'TIMEOUT' ) ) ; } } return $ process ; }
Create the process instance to use for non - interactive handling
12,216
public function processCallback ( $ mode , $ data ) { if ( isset ( $ this -> container -> output ) ) { $ this -> container -> output -> write ( $ data ) ; } }
The callback used for the process executed by Process
12,217
protected function addCommands ( Application $ app ) { $ app -> command ( new Command \ Manual \ ToHtmlCommand ( null , $ app [ self :: TEMPLATE_FACTORY ] , $ app [ self :: CONVERTER_FACTORY ] ) ) ; }
Method responsible for adding the commands for this application .
12,218
public function get ( Container $ container ) { if ( $ this -> scope === null ) { $ this -> scope = $ this -> getDefaultScope ( ) ; } return $ this -> scope -> get ( $ this , $ container ) ; }
Resolves the value of this definition according to the current scope .
12,219
private function reconnect ( ) { if ( 0 === ( int ) $ this -> getOption ( self :: OPT_MAX_RECONNECT_ATTEMPTS ) ) { throw new MaxConnectAttempsException ( "Connection lost." ) ; } elseif ( $ this -> reconnectAttempts === ( int ) $ this -> getOption ( self :: OPT_MAX_RECONNECT_ATTEMPTS ) ) { throw new MaxConnectAttempsException ( "Max attempts to connect to database has been reached." ) ; } if ( null === $ this -> credentials ) { throw new AccessDeniedException ( "Unable to reconnect: credentials not provided." ) ; } try { if ( 0 !== $ this -> reconnectAttempts ) { usleep ( ( int ) $ this -> getOption ( self :: OPT_USLEEP_AFTER_FIRST_ATTEMPT ) ) ; } $ this -> cnx = self :: createLink ( $ this -> getCredentials ( ) , $ this -> options ) ; if ( $ this -> isConnected ( ) ) { $ this -> reconnectAttempts = 0 ; } else { $ this -> reconnect ( ) ; } } catch ( Throwable $ e ) { $ this -> reconnectAttempts ++ ; } }
Tries to reconnect to database .
12,220
public function translation ( ) { if ( is_null ( $ this -> translationsClass ) ) $ this -> translationsClass = get_class ( $ this ) . 'Translations' ; return $ this -> hasOne ( $ this -> translationsClass , 'record_id' , 'id' ) -> where ( 'language_code' , app ( ) -> getLocale ( ) ) ; }
Single translation only
12,221
public static function translatedList ( string $ nameKey = "name" ) { return ( new static ( ) ) -> with ( 'translations' ) -> get ( ) -> map ( function ( $ item , $ key ) use ( $ nameKey ) { return [ 'id' => $ item -> id , 'label' => get_translation_name ( $ nameKey , app ( ) -> getLocale ( ) , array_get ( $ item , 'translations' ) ) , ] ; } ) ; }
Get translated id - > value names
12,222
public function insert ( string $ from , array $ data , array $ options = [ ] ) { if ( ! $ data ) { throw new \ RuntimeException ( 'The data inserted into the database cannot be empty' ) ; } list ( $ statement , $ bindings ) = $ this -> compileInsert ( $ from , $ data ) ; if ( isset ( $ options [ 'dumpSql' ] ) ) { return [ $ statement , $ bindings ] ; } $ this -> fetchAffected ( $ statement , $ bindings ) ; return isset ( $ options [ 'sequence' ] ) ? $ this -> lastInsertId ( $ options [ 'sequence' ] ) : $ this -> lastInsertId ( ) ; }
Run a statement for insert a row
12,223
public function ping ( ) { try { $ this -> connect ( ) ; $ this -> pdo -> query ( 'select 1' ) -> fetchColumn ( ) ; } catch ( \ PDOException $ e ) { if ( strpos ( $ e -> getMessage ( ) , 'server has gone away' ) !== false ) { return false ; } } return true ; }
Check whether the connection is available
12,224
public function isEnabled ( ) { if ( $ this -> enabled === null ) { $ environments = config ( 'songshenzong-log.env' , [ 'dev' , 'local' , 'production' ] ) ; $ this -> enabled = in_array ( env ( 'APP_ENV' ) , $ environments , true ) ; } return $ this -> enabled ; }
Check if is enabled
12,225
protected function getProcesses ( ) { $ data = $ this -> getCommand ( ) -> run ( ) ; $ parser = new TopProcessParser ( $ data ) ; $ parser -> parse ( ) ; return $ parser -> getProcesses ( ) ; }
Return parsed data for processes
12,226
protected function aggregateCpu ( $ processes ) { $ cpus = array ( ) ; foreach ( $ processes as $ process ) { if ( isset ( $ cpus [ $ process -> getName ( ) ] ) ) { $ cpus [ $ process -> getName ( ) ] += $ process -> getCpu ( ) ; } else { $ cpus [ $ process -> getName ( ) ] = $ process -> getCpu ( ) ; } } return $ cpus ; }
Aggregate CPU for processes with the same name
12,227
protected function aggregateMemory ( $ processes ) { $ memory = array ( ) ; foreach ( $ processes as $ process ) { if ( isset ( $ memory [ $ process -> getName ( ) ] ) ) { $ memory [ $ process -> getName ( ) ] += $ process -> getMemory ( ) ; } else { $ memory [ $ process -> getName ( ) ] = $ process -> getMemory ( ) ; } } return $ memory ; }
Aggregate memory for processes with the same name
12,228
protected function persistCollection ( $ collection ) { $ cache = new FilesystemAdapter ( $ this -> namespace ) ; $ item = $ cache -> getItem ( 'collection' ) ; $ item -> set ( $ collection ) ; $ cache -> save ( $ item ) ; }
Persist collection values to a temporary storage key is the command string value
12,229
protected function retrieveCollection ( ) { $ cache = new FilesystemAdapter ( $ this -> namespace ) ; $ item = $ cache -> getItem ( 'collection' ) ; $ collection = null ; if ( $ item -> isHit ( ) ) { $ collection = $ item -> get ( 'collection' ) ; } if ( empty ( $ collection ) || ! $ collection instanceof ValuesCollection ) { $ collection = new ValuesCollection ( ) ; } return $ collection ; }
\ Retrieve a new collection of a previous collection
12,230
protected function removeEmpty ( $ collection ) { foreach ( $ collection as $ key => $ value ) { if ( empty ( $ value ) ) { unset ( $ collection [ $ key ] ) ; } } return $ collection ; }
Remove empty values from collection
12,231
public function getTeams ( $ params = [ ] ) { $ defaults = [ 'limit' => 25 , 'offset' => 0 , ] ; return $ this -> wrapper -> request ( 'GET' , 'teams' , [ 'query' => $ this -> resolveOptions ( $ params , $ defaults ) ] ) ; }
Returns a list of active teams .
12,232
protected function build_input ( $ data , array $ fields = [ ] ) { return parent :: build_input ( $ data , $ fields ) . $ this -> length_helper ( $ data ) ; }
Return input field
12,233
protected function length_helper ( $ data ) { if ( ( $ this -> min || $ this -> max ) && $ this -> length_helper ) { $ notice = [ ] ; $ class_name = 'ok' ; if ( $ this -> min ) { $ notice [ ] = sprintf ( $ this -> __ ( '%s chars or more' ) , number_format ( $ this -> min ) ) ; if ( $ this -> min > mb_strlen ( $ data , 'utf-8' ) ) { $ class_name = 'ng' ; } } if ( $ this -> max ) { $ notice [ ] = sprintf ( $ this -> __ ( '%s chars or less' ) , number_format ( $ this -> max ) ) ; if ( $ this -> max < mb_strlen ( $ data , 'utf-8' ) ) { $ class_name = 'ng' ; } } return sprintf ( '<p class="char-counter %s"><i class="dashicons"></i> <strong>%s</strong><span> %s</span><small>%s</small></p>' , $ class_name , mb_strlen ( $ data , 'utf-8' ) , $ this -> __ ( 'Letters' ) , implode ( ', ' , $ notice ) ) ; } else { return '' ; } }
Returns length helper
12,234
public function get ( string $ key , $ default = null ) { $ result = $ this -> iterateConfig ( $ key ) ; return is_null ( $ result ) ? $ default : $ result ; }
Return given key from array .
12,235
public function has ( string $ key ) : bool { $ result = $ this -> iterateConfig ( $ key ) ; return ! ( $ result === null ) ; }
Return of givent key is present .
12,236
protected function iterateConfig ( string $ key ) { $ result = $ this -> config ; foreach ( explode ( '.' , $ key ) as $ p ) { if ( ! isset ( $ result [ $ p ] ) ) { return null ; } $ result = $ result [ $ p ] ; } return $ result ; }
Iterate through configuration .
12,237
public function addMeta ( array $ data ) : SuccessResponseBuilder { $ this -> meta = array_merge ( $ this -> meta , $ data ) ; return $ this ; }
Add data to the meta data appended to the response data .
12,238
public function transform ( $ data = null , $ transformer = null , string $ resourceKey = null ) : SuccessResponseBuilder { $ resource = $ this -> resourceFactory -> make ( $ data ) ; if ( ! is_null ( $ resource -> getData ( ) ) ) { $ model = $ this -> resolveModel ( $ resource -> getData ( ) ) ; $ transformer = $ this -> resolveTransformer ( $ model , $ transformer ) ; $ resourceKey = $ this -> resolveResourceKey ( $ model , $ resourceKey ) ; } if ( $ transformer instanceof Transformer ) { $ this -> include ( $ relations = $ this -> resolveNestedRelations ( $ resource -> getData ( ) ) ) ; if ( $ transformer -> allRelationsAllowed ( ) ) { $ transformer -> setRelations ( $ relations ) ; } } $ this -> resource = $ resource -> setTransformer ( $ transformer ) -> setResourceKey ( $ resourceKey ) ; return $ this ; }
Set the transformation data . This will set a new resource instance on the response builder depending on what type of data is provided .
12,239
public function getResource ( ) : ResourceInterface { $ this -> manager -> parseIncludes ( $ this -> relations ) ; $ transformer = $ this -> resource -> getTransformer ( ) ; if ( $ transformer instanceof Transformer && $ transformer -> allRelationsAllowed ( ) ) { $ this -> resource -> setTransformer ( $ transformer -> setRelations ( $ this -> manager -> getRequestedIncludes ( ) ) ) ; } return $ this -> resource -> setMeta ( $ this -> meta ) ; }
Get the Fractal resource instance .
12,240
protected function resolveSerializer ( $ serializer ) : SerializerAbstract { if ( is_string ( $ serializer ) ) { $ serializer = new $ serializer ; } if ( ! $ serializer instanceof SerializerAbstract ) { throw new InvalidSerializerException ( ) ; } return $ serializer ; }
Resolve a serializer instance from the value .
12,241
protected function resolveModel ( $ data ) : Model { if ( $ data instanceof Model ) { return $ data ; } $ model = array_values ( $ data ) [ 0 ] ; if ( ! $ model instanceof Model ) { throw new InvalidArgumentException ( 'You can only transform data containing Eloquent models.' ) ; } return $ model ; }
Resolve a model instance from the data .
12,242
protected function resolveTransformer ( Model $ model , $ transformer = null ) { $ transformer = $ transformer ? : $ this -> resolveTransformerFromModel ( $ model ) ; if ( is_string ( $ transformer ) ) { $ transformer = new $ transformer ; } return $ this -> parseTransformer ( $ transformer , $ model ) ; }
Resolve a transformer .
12,243
protected function resolveTransformerFromModel ( Model $ model ) { if ( ! $ model instanceof Transformable ) { return function ( $ model ) { return $ model -> toArray ( ) ; } ; } return $ model :: transformer ( ) ; }
Resolve a transformer from the model . If the model is not transformable a closure based transformer will be created instead from the model s fillable attributes .
12,244
protected function parseTransformer ( $ transformer , Model $ model ) { if ( $ transformer instanceof Transformer ) { $ relations = $ transformer -> allRelationsAllowed ( ) ? $ this -> resolveRelations ( $ model ) : $ transformer -> getRelations ( ) ; $ transformer = $ transformer -> setRelations ( $ relations ) ; } elseif ( ! is_callable ( $ transformer ) ) { throw new InvalidTransformerException ( $ model ) ; } return $ transformer ; }
Parse a transformer class and set relations .
12,245
protected function resolveNestedRelations ( $ data ) : array { if ( is_null ( $ data ) ) { return [ ] ; } $ data = $ data instanceof Model ? [ $ data ] : $ data ; return collect ( $ data ) -> flatMap ( function ( $ model ) { $ relations = collect ( $ model -> getRelations ( ) ) ; return $ relations -> keys ( ) -> merge ( $ relations -> flatMap ( function ( $ relation , $ key ) { return collect ( $ this -> resolveNestedRelations ( $ relation ) ) -> map ( function ( $ nestedRelation ) use ( $ key ) { return $ key . '.' . $ nestedRelation ; } ) ; } ) ) ; } ) -> unique ( ) -> toArray ( ) ; }
Resolve eager loaded relations from the model including any nested relations .
12,246
protected function resolveResourceKey ( Model $ model , string $ resourceKey = null ) : string { if ( ! is_null ( $ resourceKey ) ) { return $ resourceKey ; } if ( method_exists ( $ model , 'getResourceKey' ) ) { return $ model -> getResourceKey ( ) ; } return $ model -> getTable ( ) ; }
Resolve the resource key from the model .
12,247
private static function add_view ( $ path , $ mode , mvc \ view $ view ) { if ( ! isset ( self :: $ loaded_views [ $ mode ] [ $ path ] ) ) { self :: $ loaded_views [ $ mode ] [ $ path ] = $ view ; } return self :: $ loaded_views [ $ mode ] [ $ path ] ; }
This function gets the content of a view file and adds it to the loaded_views array .
12,248
public function get_external_view ( string $ full_path , string $ mode = 'html' , array $ data = null ) { if ( ! router :: is_mode ( $ mode ) ) { die ( "Incorrect mode $full_path $mode" ) ; } if ( ( $ this -> get_mode ( ) === 'dom' ) && ( ! defined ( 'BBN_DEFAULT_MODE' ) || ( BBN_DEFAULT_MODE !== 'dom' ) ) ) { $ full_path .= ( $ full_path === '' ? '' : '/' ) . 'index' ; } $ view = null ; if ( $ this -> has_view ( $ full_path , $ mode ) ) { $ view = self :: $ loaded_views [ $ mode ] [ $ full_path ] ; } else if ( $ info = $ this -> router -> route ( basename ( $ full_path ) , 'free-' . $ mode , \ dirname ( $ full_path ) ) ) { $ view = new mvc \ view ( $ info ) ; $ this -> add_to_views ( $ full_path , $ mode , $ view ) ; } if ( \ is_object ( $ view ) && $ view -> check ( ) ) { return \ is_array ( $ data ) ? $ view -> get ( $ data ) : $ view -> get ( ) ; } return '' ; }
This will get a view from a different root .
12,249
public function get_cached_model ( $ path , array $ data , mvc \ controller $ ctrl , $ ttl = 10 ) { if ( \ is_null ( $ data ) ) { $ data = $ this -> data ; } if ( $ route = $ this -> router -> route ( $ path , 'model' ) ) { $ model = new mvc \ model ( $ this -> db , $ route , $ ctrl , $ this ) ; return $ model -> get_from_cache ( $ data , '' , $ ttl ) ; } return [ ] ; }
This will get the model as it is in cache if any and otherwise will save it in cache then return it
12,250
public function set_cached_model ( $ path , array $ data , mvc \ controller $ ctrl , $ ttl = 10 ) { if ( \ is_null ( $ data ) ) { $ data = $ this -> data ; } if ( $ route = $ this -> router -> route ( $ path , 'model' ) ) { $ model = new mvc \ model ( $ this -> db , $ route , $ ctrl , $ this ) ; return $ model -> set_cache ( $ data , '' , $ ttl ) ; } return [ ] ; }
This will set the model in cache
12,251
public function delete_cached_model ( $ path , array $ data , mvc \ controller $ ctrl ) { if ( \ is_null ( $ data ) ) { $ data = $ this -> data ; } if ( $ route = $ this -> router -> route ( $ path , 'model' ) ) { $ model = new mvc \ model ( $ this -> db , $ route , $ ctrl , $ this ) ; return $ model -> delete_cache ( $ data , '' ) ; } return [ ] ; }
This will unset the model in cache
12,252
public function add_inc ( $ name , $ obj ) { if ( ! isset ( $ this -> inc -> { $ name } ) ) { $ this -> inc -> { $ name } = $ obj ; } }
Adds a property to the MVC object inc if it has not been declared .
12,253
function csrf ( ) { return Cache :: instance ( ) -> exists ( ( $ this -> sid ? : session_id ( ) ) . '.@' , $ data ) ? $ data [ 'csrf' ] : FALSE ; }
Return anti - CSRF token
12,254
function parseRateLimit ( Response $ response ) { $ newRateLimit = \ GithubService \ RateLimit :: createFromResponse ( $ response ) ; if ( $ newRateLimit != null ) { $ this -> rateLimit = $ newRateLimit ; } }
Try to get some rate limiting info from the response and store it if it is available .
12,255
function createOrRetrieveAuth ( $ username , $ password , callable $ enterPasswordCallback , $ scopes , $ note , $ noteURL = "http://www.github.com/danack/GithubArtaxService" , $ maxAttempts = 3 ) { $ basicToken = new BasicAuthToken ( $ username , $ password ) ; $ otp = false ; for ( $ i = 0 ; $ i < $ maxAttempts ; $ i ++ ) { try { $ createAuthToken = $ this -> createAuthorization ( $ basicToken -> __toString ( ) , $ scopes , $ note ) ; $ createAuthToken -> setNote_url ( $ noteURL ) ; if ( $ otp ) { $ createAuthToken -> setOtp ( $ otp ) ; } $ authResult = $ createAuthToken -> execute ( ) ; return $ authResult ; } catch ( OneTimePasswordAppException $ otpae ) { $ otp = $ enterPasswordCallback ( "Please enter the code from your 2nd factor auth app:" ) ; } catch ( OneTimePasswordSMSException $ otse ) { $ otp = $ enterPasswordCallback ( "Please enter the code from the SMS Github should have sent you:" ) ; } } throw new GithubArtaxServiceException ( "Failed to create or retrieve oauth token." ) ; }
Creates an Oauth token for a named application .
12,256
public function getSource ( ) { $ field = $ this -> getForm ( ) -> Fields ( ) -> dataFieldByName ( $ this -> country_field ) ; if ( empty ( $ field ) || empty ( $ field -> Value ( ) ) ) { $ locale = strtoupper ( Locale :: getRegion ( i18n :: get_locale ( ) ) ) ; } else { $ locale = $ field -> Value ( ) ; } return $ this -> getList ( $ locale ) -> map ( "Code" , "Name" ) -> toArray ( ) ; }
Overwrite default get source to return custom list of regions
12,257
public function Field ( $ properties = [ ] ) { Requirements :: javascript ( "silvercommerce/geozones: client/dist/js/RegionSelectionField.min.js" ) ; $ country_field = $ this -> country_field ; $ field = $ this -> getForm ( ) -> Fields ( ) -> dataFieldByName ( $ country_field ) ; $ this -> setAttribute ( "data-region-field" , true ) -> setAttribute ( "data-country-field" , $ field -> ID ( ) ) -> setAttribute ( "data-link" , $ this -> Link ( "regionslist" ) ) ; if ( $ this -> getHasEmptyDefault ( ) ) { $ this -> setAttribute ( "data-empty-string" , $ this -> getEmptyString ( ) ) ; } return parent :: Field ( $ properties ) ; }
Render the final field
12,258
public function getList ( $ country ) { $ list = Region :: get ( ) -> filter ( "CountryCode" , strtoupper ( $ country ) ) ; if ( ! $ list -> exists ( ) && $ this -> getCreateEmptyDefault ( ) ) { $ countries = i18n :: getData ( ) -> getCountries ( ) ; if ( isset ( $ countries [ strtolower ( $ country ) ] ) ) { $ name = $ countries [ strtolower ( $ country ) ] ; } else { $ name = $ country ; } $ list = ArrayList :: create ( ) ; $ list -> push ( Region :: create ( [ "Name" => $ name , "Type" => "Nation" , "Code" => strtoupper ( $ country ) , "CountryCode" => strtoupper ( $ country ) ] ) ) ; } return $ list ; }
Get a list of regions filtered by the provided country code
12,259
public function regionslist ( ) { $ id = $ this -> getRequest ( ) -> param ( "ID" ) ; $ data = $ this -> getList ( $ id ) -> map ( "Code" , "Name" ) -> toArray ( ) ; return json_encode ( $ data ) ; }
Return a list of regions based on the supplied country ID
12,260
protected function is_sub_class_of ( $ class_name , $ should , $ allow_abstract = false ) { if ( class_exists ( $ class_name ) ) { $ refl = new \ ReflectionClass ( $ class_name ) ; return ( $ allow_abstract || ! $ refl -> isAbstract ( ) ) && $ refl -> isSubclassOf ( $ should ) ; } return false ; }
Detect if specifies class is subclass
12,261
public static function clean ( $ request = null ) { switch ( $ request ) { case 'post' : unset ( $ _POST ) ; break ; case 'get' : unset ( $ _GET ) ; break ; case 'any' : unset ( $ _REQUEST ) ; break ; default : unset ( $ _POST ) ; unset ( $ _REQUEST ) ; unset ( $ _GET ) ; } }
limpa toda requisicao passada
12,262
public function getInvoices ( Get \ RequestData $ requestData ) { $ request = new Get \ Request ( $ requestData ) ; $ apiResponse = $ this -> sendRequest ( $ request , Get \ ApiResponse :: class ) ; $ response = $ apiResponse -> getResponse ( ) ; foreach ( $ response -> getInvoices ( ) as $ invoice ) { $ invoiceDate = $ invoice -> getInvoiceDate ( ) ; if ( $ invoiceDate !== null ) { $ invoiceDate -> setTime ( 0 , 0 , 0 ) ; } $ dueDate = $ invoice -> getDueDate ( ) ; if ( $ dueDate !== null ) { $ dueDate = new \ DateTime ( $ dueDate ) ; $ dueDate -> setTime ( 0 , 0 , 0 ) ; $ invoice -> setDueDate ( $ dueDate ) ; } } return $ apiResponse ; }
Get the invoices .
12,263
public function create ( ServerRequestInterface $ request ) : CallbackInterface { $ callbacks = [ XmlCallback :: class , FormCallback :: class , RedirectCallback :: class ] ; foreach ( $ callbacks as $ callback ) { if ( call_user_func ( [ $ callback , 'initable' ] , $ request ) ) { return new $ callback ( $ request ) ; } } throw new \ InvalidArgumentException ( 'A callback could not be instantiated' ) ; }
Will take a Psr Server Request and return a Form Xml or Redirect callback object that represent the actual callback
12,264
public function generate ( array $ config ) { $ defaultHTTPCodes = $ this -> getDefaultHTTPCodes ( $ config ) ; $ defaultOptions = $ this -> getDefaultOptions ( $ config ) ; return $ this -> createUrlChainFromConfig ( $ config , $ defaultHTTPCodes , $ defaultOptions ) ; }
Given a configuration array generates a chain of urls
12,265
protected function getDefaultHTTPCodes ( $ config ) { $ defaultHttpCodes = ( isset ( $ config [ 'defaults' ] ) && is_array ( $ config [ 'defaults' ] ) && isset ( $ config [ 'defaults' ] [ 'http_codes' ] ) && ! empty ( $ config [ 'defaults' ] [ 'http_codes' ] ) ) ? $ config [ 'defaults' ] [ 'http_codes' ] : [ 200 ] ; if ( ! is_array ( $ defaultHttpCodes ) ) { $ defaultHttpCodes = [ $ defaultHttpCodes ] ; } return $ defaultHttpCodes ; }
Get default http Codes
12,266
protected function getDefaultOptions ( $ config ) { $ defaultOptions = ( isset ( $ config [ 'defaults' ] ) && is_array ( $ config [ 'defaults' ] ) && isset ( $ config [ 'defaults' ] [ 'options' ] ) && is_array ( $ config [ 'defaults' ] [ 'options' ] ) ) ? $ config [ 'defaults' ] [ 'options' ] : [ ] ; return $ defaultOptions ; }
Get default options
12,267
protected function createUrlChainFromConfig ( array $ config , array $ defaultHTTPCodes , array $ defaultOptions ) { $ urlChain = $ this -> urlChainFactory -> create ( ) ; if ( ! isset ( $ config [ 'urls' ] ) || ! is_array ( $ config [ 'urls' ] ) ) { return $ urlChain ; } $ profiles = ( isset ( $ config [ 'profiles' ] ) && is_array ( $ config [ 'profiles' ] ) ) ? $ config [ 'profiles' ] : [ ] ; foreach ( $ config [ 'urls' ] as $ urlConfig ) { $ urlChain -> addUrl ( $ this -> getURLInstanceFromConfig ( $ urlConfig , $ defaultHTTPCodes , $ defaultOptions , $ profiles ) ) ; } return $ urlChain ; }
Given a config array create an URLChain instance filled with all defined URL instances .
12,268
protected function getUrlInstanceFromConfig ( $ urlConfig , array $ defaultHTTPCodes , array $ defaultOptions , array $ profiles ) { $ url = $ this -> getUrlPathFromConfig ( $ urlConfig ) ; $ urlHTTPCodes = $ this -> getUrlHTTPCodesFromConfig ( $ urlConfig , $ defaultHTTPCodes ) ; $ urlOptions = $ this -> getUrlOptionsFromConfig ( $ urlConfig , $ defaultOptions ) ; if ( isset ( $ urlOptions [ 'profile' ] ) && isset ( $ profiles [ $ urlOptions [ 'profile' ] ] ) && is_array ( $ profiles [ $ urlOptions [ 'profile' ] ] ) ) { $ urlOptions = array_merge ( $ profiles [ $ urlOptions [ 'profile' ] ] , $ urlOptions ) ; } return $ this -> urlFactory -> create ( $ url , $ urlHTTPCodes , $ urlOptions ) ; }
Get Url instance given its configuration
12,269
protected function getUrlHTTPCodesFromConfig ( $ urlConfig , array $ defaultHTTPCodes ) { $ HTTPCodes = ( is_array ( $ urlConfig ) && isset ( $ urlConfig [ 1 ] ) && ! empty ( $ urlConfig [ 1 ] ) ) ? $ urlConfig [ 1 ] : $ defaultHTTPCodes ; return is_array ( $ HTTPCodes ) ? $ HTTPCodes : [ $ HTTPCodes ] ; }
Get url HTTP Codes given its configuration
12,270
protected function getUrlOptionsFromConfig ( $ urlConfig , array $ defaultOptions ) { $ urlOptions = ( is_array ( $ urlConfig ) && isset ( $ urlConfig [ 2 ] ) && is_array ( $ urlConfig [ 2 ] ) ) ? $ urlConfig [ 2 ] : [ ] ; return array_merge ( $ defaultOptions , $ urlOptions ) ; }
Get url options
12,271
public function count ( $ entityType , $ filter = '' ) { $ params = array ( 'type_name' => $ entityType ) ; if ( ! empty ( $ filter ) ) { $ params [ 'filter' ] = $ filter ; } return $ this -> post ( 'entity.count' , $ params ) ; }
Count the number of records in an entityType .
12,272
public function delete ( $ uuid , array $ params = array ( ) ) { $ params [ 'uuid' ] = $ uuid ; if ( ! isset ( $ params [ 'type_name' ] ) ) { throw new MissingArgumentException ( 'type_name' ) ; } return $ this -> _del ( $ params ) ; }
Default by UUID .
12,273
public function replaceByAttribute ( $ attributeKey , $ attributeValue , array $ params ) { $ params [ 'key_attribute' ] = $ attributeKey ; $ params [ 'key_value' ] = $ this -> wrapAttributeValueWithQuotes ( $ attributeValue ) ; return $ this -> _replace ( $ params ) ; }
Replace part of an entity by attribute .
12,274
public function updateByAttribute ( $ attributeKey , $ attributeValue , array $ params ) { $ params [ 'key_attribute' ] = $ attributeKey ; $ params [ 'key_value' ] = $ this -> wrapAttributeValueWithQuotes ( $ attributeValue ) ; return $ this -> _update ( $ params ) ; }
Update entity by attribute
12,275
public function send ( $ printaitorViewObj ) { $ dv = $ printaitorViewObj -> dataToView ; $ factura [ 'AfipFactura' ] = array ( 'json_data' => $ printaitorViewObj -> viewTextRender , 'mesa_id' => Hash :: get ( $ dv , 'Mesa.id' ) , 'importe_total' => Hash :: get ( $ dv , 'Mesa.total' ) , 'importe_neto' => Hash :: get ( $ dv , 'importe_neto' ) , 'importe_iva' => Hash :: get ( $ dv , 'importe_iva' ) , 'punto_de_venta' => Hash :: get ( $ dv , 'punto_de_venta' ) , 'comprobante_nro' => Hash :: get ( $ dv , 'numero_comprobante' ) , 'tipo_factura_id' => Hash :: get ( $ dv , 'tipo_factura_id' ) , 'cae' => Hash :: get ( $ dv , 'cae' ) , 'iva_porcentaje' => Configure :: read ( 'Afip.default_iva_porcentaje' ) , ) ; $ AfipFactura = ClassRegistry :: init ( "Printers.AfipFactura" ) ; $ factura = $ AfipFactura -> save ( $ factura ) ; if ( ! $ factura ) { foreach ( $ AfipFactura -> validationErrors as $ field => $ msg ) { $ msgErr = implode ( ',' , $ msg ) ; throw new CakeException ( __ ( "No se pudo guardar la factura. Campo: %s, Error: %s" , $ field , $ msgErr ) , 1 ) ; } } return $ factura ; }
Crea un archivo y lo guarda en la tabla afip_facturas
12,276
private function show_plugin_update_notices ( ) { add_action ( 'in_plugin_update_message-' . $ this -> app -> define -> plugin_base_name , function ( $ data , $ r ) { $ new_version = $ r -> new_version ; $ url = $ this -> app -> utility -> array_get ( $ data , 'PluginURI' ) ; $ notices = $ this -> get_upgrade_notices ( $ new_version , $ url ) ; if ( ! empty ( $ notices ) ) { $ this -> get_view ( 'admin/include/upgrade' , [ 'notices' => $ notices , ] , true ) ; } } , 10 , 2 ) ; }
show plugin upgrade notices
12,277
public function createService ( ServiceLocatorInterface $ serviceLocator ) { $ config = $ serviceLocator -> get ( 'Configuration' ) ; if ( ! isset ( $ config [ 'ocr' ] ) ) { throw new Exception \ RuntimeException ( 'No "ocr" section available in configuration.' ) ; } if ( ! isset ( $ config [ 'ocr' ] [ 'service' ] ) ) { throw new Exception \ RuntimeException ( 'No "service" specified in "ocr" section of configuration.' ) ; } $ service = $ serviceLocator -> get ( $ config [ 'ocr' ] [ 'service' ] ) ; if ( ! $ service instanceof OcrServiceInterface ) { throw new Exception \ RuntimeException ( 'Provided service class is not a valid ocr service.' ) ; } if ( isset ( $ config [ 'ocr' ] [ 'config' ] ) ) { $ service -> setConfig ( $ config [ 'ocr' ] [ 'config' ] ) ; } return $ service ; }
Create OCR service
12,278
public function hasEndpoint ( $ uri ) { $ urlsFound = $ this -> getEndpoints ( ) -> filter ( function ( Endpoint $ endpoint ) use ( $ uri ) { return ( string ) $ endpoint -> getUri ( ) === $ uri ; } ) ; return $ urlsFound -> isEmpty ( ) === false ; }
Checks if the given uri is already added to collection .
12,279
public function addEndpoint ( Endpoint $ newEndpoint ) { if ( $ this -> hasEndpoint ( ( string ) $ newEndpoint -> getUri ( ) ) ) { throw new InputException ( 'Endpoint already added' ) ; } $ status = $ this -> getEndpoints ( ) -> isEmpty ( ) ? Endpoint :: STATUS_ACTIVE : Endpoint :: STATUS_DISABLED ; $ newEndpoint -> setStatus ( $ status ) ; $ this -> getEndpoints ( ) -> add ( $ newEndpoint ) ; }
Add Endpoint into the pool .
12,280
public function activateEndpoint ( Endpoint $ newActive , $ force = false ) { if ( ! $ this -> getEndpoints ( ) -> contains ( $ newActive ) ) { throw new InputException ( 'Endpoint is not part of this manager' ) ; } if ( $ force === false && $ this -> canBeActivated ( $ newActive ) === false ) { throw new InputException ( 'Can not activate this endpoint' ) ; } $ this -> disableAll ( ) ; $ newActive -> setStatus ( Endpoint :: STATUS_ACTIVE ) ; return $ newActive ; }
Try to activate an Endpoint as the active endpoint . If endpoint status is Error first check if it can be safely enabled .
12,281
private function canBeActivated ( Endpoint $ newActive ) { if ( $ newActive -> isError ( ) === true ) { $ offlineInterval = new \ DateTime ( ) ; $ offlineInterval -> modify ( '-60 minutes' ) ; return $ newActive -> getLastConnected ( ) !== null && $ newActive -> getLastConnected ( ) <= $ offlineInterval ; } return true ; }
Determine if this endpoint can re - enabled .
12,282
private function disableAll ( ) { $ this -> getEndpoints ( ) -> map ( function ( Endpoint $ endpoint ) { if ( $ endpoint -> isError ( ) === false ) { $ endpoint -> setStatus ( Endpoint :: STATUS_DISABLED ) ; } } ) ; }
Disable all endpoints except the ones in error .
12,283
public function getActiveEndpoint ( ) { $ active = $ this -> getEndpoints ( ) -> filter ( function ( Endpoint $ endpoint ) { return $ endpoint -> isActive ( ) ; } ) ; if ( $ active -> isEmpty ( ) === true ) { $ active = $ this -> getEndpoints ( ) -> filter ( function ( Endpoint $ endpoint ) { return $ this -> canBeActivated ( $ endpoint ) ; } ) ; } if ( $ active -> isEmpty ( ) === true ) { throw new NoServerAvailableException ( 'No active server available' ) ; } $ endpoint = $ active -> first ( ) ; $ endpoint -> setStatus ( Endpoint :: STATUS_ACTIVE ) ; return $ endpoint ; }
Returns a active endpoint . Tries to find the current active endpoint or enable one .
12,284
public function connect ( ) { if ( ! preg_match ( '/([0-9]{1,3}\\.){3,3}[0-9]{1,3}/' , $ this -> host ) ) { $ ip = gethostbyname ( $ this -> host ) ; if ( $ this -> host == $ ip ) { throw new \ Exception ( "Cannot resolve $this->host" ) ; } else { $ this -> host = $ ip ; } } $ this -> socket = fsockopen ( $ this -> host , $ this -> port , $ this -> errno , $ this -> errstr , $ this -> timeout ) ; if ( ! $ this -> socket ) { throw new \ Exception ( "Cannot connect to " . $ this -> host . " on port " . $ this -> port . "\n" . $ this -> errstr . ": " . $ this -> errstr ) ; } return true ; }
Attempts connection to remote host . Returns TRUE if sucessful .
12,285
public function disconnect ( ) { if ( $ this -> socket ) { if ( ! fclose ( $ this -> socket ) ) { throw new \ Exception ( "Error while closing telnet socket" ) ; } $ this -> socket = NULL ; } return true ; }
Closes IP socket
12,286
public function readTo ( $ prompt ) { if ( ! $ this -> socket ) { throw new \ Exception ( "Telnet connection closed" ) ; } $ this -> clearBuffer ( ) ; $ until_t = time ( ) + $ this -> timeout ; do { if ( time ( ) > $ until_t ) { throw new \ Exception ( "Couldn't find the requested : '$prompt' within {$this->timeout} seconds" ) ; } $ c = $ this -> getc ( ) ; if ( $ c === false ) { throw new \ Exception ( "Couldn't find the requested : '" . $ prompt . "', it was not in the data returned from server: " . $ this -> buffer ) ; } if ( $ c == $ this -> IAC ) { if ( $ this -> negotiateTelnetOptions ( ) ) { continue ; } } $ this -> buffer .= $ c ; if ( $ this -> debug_mode === 1 || $ this -> debug_mode === 3 ) { $ this -> log ( $ c ) ; } if ( ( substr ( $ this -> buffer , strlen ( $ this -> buffer ) - strlen ( $ prompt ) ) ) == $ prompt ) { return true ; } } while ( $ c != $ this -> NULL || $ c != $ this -> DC1 ) ; }
Reads characters from the socket and adds them to command buffer . Handles telnet control characters . Stops when prompt is ecountered .
12,287
public function write ( $ buffer , $ addNewLine = true ) { if ( ! $ this -> socket ) { throw new \ Exception ( "Telnet connection closed" ) ; } $ this -> clearBuffer ( ) ; if ( $ addNewLine == true ) { $ buffer .= "\n" ; } $ this -> global_buffer .= $ buffer ; if ( $ this -> debug_mode === 2 || $ this -> debug_mode === 3 ) { $ this -> log ( $ buffer ) ; } if ( ! fwrite ( $ this -> socket , $ buffer ) < 0 ) { throw new \ Exception ( "Error writing to socket" ) ; } return true ; }
Write command to a socket
12,288
public function getBuffer ( ) { $ buf = explode ( "\n" , $ this -> buffer ) ; unset ( $ buf [ count ( $ buf ) - 1 ] ) ; $ buf = implode ( "\n" , $ buf ) ; return trim ( $ buf ) ; }
Returns the content of the command buffer
12,289
public function negotiateTelnetOptions ( ) { $ c = $ this -> getc ( ) ; if ( $ c != $ this -> IAC ) { if ( ( $ c == $ this -> DO ) || ( $ c == $ this -> DONT ) ) { $ opt = $ this -> getc ( ) ; fwrite ( $ this -> socket , $ this -> IAC . $ this -> WONT . $ opt ) ; } else if ( ( $ c == $ this -> WILL ) || ( $ c == $ this -> WONT ) ) { $ opt = $ this -> getc ( ) ; fwrite ( $ this -> socket , $ this -> IAC . $ this -> DONT . $ opt ) ; } else { throw new \ Exception ( 'Error: unknown control character ' . ord ( $ c ) ) ; } } else { throw new \ Exception ( 'Error: Something Wicked Happened' ) ; } return true ; }
Telnet control character magic
12,290
public function changeUsername ( ) { if ( $ this -> validate ( ) ) { $ username = $ this -> user -> createUsername ( $ this -> username ) ; if ( ! $ username ) { return false ; } return $ username -> save ( ) ; } return false ; }
Change username .
12,291
private function buildUrl ( $ endpoint , array $ additional_parameters = [ ] ) { $ base = ( $ this -> use_stage ? 'stg.' : '' ) . $ this -> domain ; $ parameters = [ 'passKey=' . $ this -> apiKey , 'ApiVersion=' . self :: $ api_version , ] ; if ( ! empty ( $ additional_parameters ) ) { foreach ( $ additional_parameters as $ param_name => $ param_value ) { if ( is_array ( $ param_value ) ) { foreach ( $ param_value as $ sub_param_name => $ sub_param_value ) { $ sub_param_value = is_array ( $ sub_param_value ) ? implode ( "," , $ sub_param_value ) : $ sub_param_value ; $ parameters [ ] = $ param_name . '=' . $ sub_param_name . ':' . $ sub_param_value ; } } else { $ parameters [ ] = $ param_name . '=' . $ param_value ; } } } $ parameters = implode ( '&' , $ parameters ) ; return $ base . '/' . $ endpoint . '.json?' . $ parameters ; }
Create Bazaarvoice URL with added parameters .
12,292
private function splitConfiguration ( array $ options ) { $ return_array = [ 'method' => 'GET' , 'arguments' => [ ] , 'options' => [ ] , ] ; if ( isset ( $ options [ 'method' ] ) ) { $ return_array [ 'method' ] = $ options [ 'method' ] ; } if ( isset ( $ options [ 'arguments' ] ) ) { $ return_array [ 'arguments' ] = $ options [ 'arguments' ] ; } ; if ( isset ( $ options [ 'options' ] ) ) { $ return_array [ 'options' ] = $ options [ 'options' ] ; } return array_values ( $ return_array ) ; }
Splits API request options array into main buckets .
12,293
private function buildResponse ( $ response_type , $ method , $ status_code , $ request_url , array $ configuration = [ ] , array $ response_data = [ ] ) { $ object = FALSE ; if ( is_string ( $ response_type ) ) { if ( class_exists ( $ response_type ) ) { if ( is_subclass_of ( $ response_type , 'BazaarvoiceRequest\\Response\\BazaarvoiceResponseBase' ) ) { $ object = new $ response_type ( $ method , $ status_code , $ request_url , $ configuration , $ response_data ) ; } } } return $ object ; }
Returns a BazaarvoiceRequest \ Response object .
12,294
protected function getDestinationPath ( Transformation $ transformation ) { $ artifact = $ transformation -> getTransformer ( ) -> getTarget ( ) . DIRECTORY_SEPARATOR . $ transformation -> getArtifact ( ) ; return $ artifact ; }
Retrieves the destination location for this artifact .
12,295
public function getQueryParams ( array $ list = null ) { return isset ( $ list ) ? $ this -> listQueryParams ( $ list ) : ( array ) $ this -> getRequest ( ) -> getQueryParams ( ) ; }
Get the request query parameters .
12,296
protected function listQueryParams ( array $ list ) { $ result = [ ] ; $ params = $ this -> getRequest ( ) -> getQueryParams ( ) ; foreach ( $ list as $ key => $ value ) { if ( is_int ( $ key ) ) { $ key = $ value ; $ value = null ; } $ result [ ] = isset ( $ params [ $ key ] ) ? $ params [ $ key ] : $ value ; } return $ result ; }
Apply list to query params
12,297
public function getQueryParam ( $ param , $ default = null , $ filter = null , $ filterOptions = null ) { $ params = $ this -> getQueryParams ( ) ; $ value = isset ( $ params [ $ param ] ) ? $ params [ $ param ] : $ default ; if ( isset ( $ filter ) && isset ( $ value ) ) { $ value = filter_var ( $ value , $ filter , $ filterOptions ) ; } return $ value ; }
Get a query parameter .
12,298
public function getInput ( ) { $ data = $ this -> getRequest ( ) -> getParsedBody ( ) ; if ( is_array ( $ data ) ) { $ files = $ this -> getRequest ( ) -> getUploadedFiles ( ) ; $ data = array_replace_recursive ( $ data , ( array ) $ files ) ; } return $ data ; }
Get parsed body and uploaded files as input
12,299
public static function isSupported ( string $ driver ) : bool { if ( $ driver === self :: DRIVER_MONGO_DB ) { return \ extension_loaded ( 'mongodb' ) ; } if ( $ driver === self :: DRIVER_MONGO ) { return \ extension_loaded ( 'mongo' ) ; } return false ; }
Is this driver supported .