idx
int64
0
60.3k
question
stringlengths
101
6.21k
target
stringlengths
7
803
47,000
public function update ( $ attributes ) { try { self :: init ( ) ; foreach ( $ attributes as $ column => $ value ) { $ columns [ ] = $ column . ' = :' . $ column ; } $ sql = 'UPDATE ' . self :: $ modelTable . ' SET ' . implode ( ', ' , $ columns ) . ' WHERE id = ' . $ this -> id ; $ stm = self :: $ connect -> prepare ( $ sql ) ; $ stm -> execute ( $ attributes ) ; $ this -> setAttributes ( $ attributes ) ; return $ this ; } catch ( \ Exception $ exception ) { var_dump ( $ exception -> getMessage ( ) ) ; } }
Update object record
47,001
public static function select ( ) { try { self :: init ( ) ; $ columns = func_get_args ( ) ; $ query = 'SELECT ' . implode ( ', ' , $ columns ) . ' FROM ' . self :: $ modelTable ; return new QueryBuilder ( self :: $ connect , $ query ) ; } catch ( \ Exception $ exception ) { var_dump ( $ exception -> getMessage ( ) ) ; } }
Select specified columns from table
47,002
public static function find ( $ id ) { self :: init ( ) ; $ query = 'SELECT * FROM ' . self :: $ modelTable . ' WHERE id = ' . $ id ; $ qb = new QueryBuilder ( self :: $ connect , $ query ) ; $ rows = $ qb -> get ( ) ; $ collection = self :: makeCollection ( $ rows ) ; return ! empty ( $ collection ) ? array_shift ( $ collection ) : null ; }
Get object of record
47,003
public static function makeCollection ( $ rows ) { $ collection = [ ] ; foreach ( $ rows as $ row ) { $ obj = new static ; $ collection [ ] = $ obj -> setAttributes ( get_object_vars ( $ row ) ) ; } return $ collection ; }
Mace collection of objects
47,004
public function fgets ( $ length = null ) { return $ this -> validHandle ( ) ? fgets ( $ this -> _fileHandle , $ length ) : false ; }
Retrieves a string from the current file
47,005
public static function makePath ( $ validate = true , $ forceCreate = false ) { $ _arguments = func_get_args ( ) ; $ _validate = $ _path = null ; foreach ( $ _arguments as $ _part ) { if ( is_bool ( $ _part ) ) { $ _validate = $ _part ; continue ; } $ _path .= DIRECTORY_SEPARATOR . trim ( $ _part , DIRECTORY_SEPARATOR . ' ' ) ; } if ( ! is_dir ( $ _path = realpath ( $ _path ) ) ) { if ( $ _validate && ! $ forceCreate ) { return false ; } if ( $ forceCreate ) { if ( false === @ mkdir ( $ _path , 0 , true ) ) { throw new UtilityException ( 'The result path "' . $ _path . '" could not be created.' ) ; } } } return $ _path ; }
Builds a path from arguments and validates existence .
47,006
public static function rmdir ( $ dirPath , $ force = false ) { $ _path = rtrim ( $ dirPath ) . DIRECTORY_SEPARATOR ; if ( ! $ force ) { return rmdir ( $ _path ) ; } if ( ! is_dir ( $ _path ) ) { throw new \ InvalidArgumentException ( '"' . $ _path . '" is not a directory or bogus in some other way.' ) ; } $ _files = glob ( $ _path . '*' , GLOB_MARK ) ; foreach ( $ _files as $ _file ) { if ( is_dir ( $ _file ) ) { static :: rmdir ( $ _file , true ) ; } else { unlink ( $ _file ) ; } } return rmdir ( $ _path ) ; }
rmdir function with force
47,007
function FilterFields ( $ array , $ operation = 'where' ) { if ( ! $ array ) return ; $ out = array ( ) ; foreach ( $ array as $ field => $ value ) { if ( $ operation == 'where' && $ this -> source == 'internal' && preg_match ( '/^(.*) (.*)$/' , $ field , $ matches ) ) { $ key = $ matches [ 1 ] ; $ cond = $ matches [ 2 ] ; $ val = $ value ; } elseif ( $ operation == 'where' && $ this -> source == 'controller' && is_string ( $ value ) && preg_match ( '/^([\<\>]=?)(.*)$/' , $ value , $ matches ) ) { $ key = $ field ; $ cond = $ matches [ 1 ] ; $ val = $ matches [ 2 ] ; } elseif ( $ operation == 'where' && $ this -> source == 'controller' && is_array ( $ value ) && preg_match ( '/^([\<\>]=?)(.*)$/' , $ value [ 0 ] , $ matches ) ) { $ key = $ field ; $ cond = $ matches [ 1 ] ; $ val = $ matches [ 2 ] ; array_shift ( $ value ) ; foreach ( $ value as $ valIndex => $ valArray ) { if ( preg_match ( '/^([\<\>]=?)(.*)$/' , $ value [ $ valIndex ] , $ matches ) ) $ out [ isset ( $ matches [ 1 ] ) && $ matches [ 1 ] != '=' ? "$key {$matches[1]}" : $ key ] = $ matches [ 2 ] ; } } else { $ key = $ field ; $ cond = '=' ; $ val = $ value ; } if ( ! isset ( $ this -> schema [ $ key ] ) ) continue ; if ( $ operation == 'set' && isset ( $ this -> schema [ $ key ] [ 'allowset' ] ) && ! $ this -> schema [ $ key ] [ 'allowset' ] ) continue ; if ( $ operation == 'where' && isset ( $ this -> schema [ $ key ] [ 'allowquery' ] ) && ! $ this -> schema [ $ key ] [ 'allowquery' ] ) continue ; $ out [ $ cond && $ cond != '=' ? "$key $cond" : $ key ] = $ val ; } return $ out ; }
Return an input array filtered by fields we are allowed to perform an operation on
47,008
function GetCache ( $ type , $ id ) { if ( ! isset ( $ this -> cache [ $ type ] ) || ! $ this -> cache [ $ type ] ) return FALSE ; if ( isset ( $ this -> _cache [ $ type ] [ $ id ] ) ) return $ this -> _cache [ $ type ] [ $ id ] ; return FALSE ; }
Get the value of a cache entity
47,009
function SetCache ( $ type , $ id , $ value ) { if ( ! isset ( $ this -> cache [ $ type ] ) || ! $ this -> cache [ $ type ] ) return $ value ; if ( $ value ) { if ( ! isset ( $ this -> _cache [ $ type ] ) ) $ this -> _cache [ $ type ] = array ( ) ; $ this -> _cache [ $ type ] [ $ id ] = $ value ; return $ this -> _cache [ $ type ] [ $ id ] ; } elseif ( isset ( $ this -> _cache [ $ type ] [ $ id ] ) ) { unset ( $ this -> _cache [ $ type ] [ $ id ] ) ; return null ; } }
Set a cache item
47,010
function ClearCache ( $ type = null , $ id = null ) { if ( ! $ type ) { $ this -> _cache = array ( ) ; } elseif ( ! $ id ) { $ this -> _cache [ $ type ] = array ( ) ; } else { $ this -> SetCache ( $ type , $ id , null ) ; } }
Clears the cache of a specific item type or entirely
47,011
function Get ( $ id ) { $ this -> continue = TRUE ; $ this -> LoadSchema ( ) ; if ( $ value = $ this -> GetCache ( 'get' , $ id ) ) return $ value ; $ this -> ResetQuery ( array ( 'method' => 'get' , 'table' => $ this -> table , 'where' => array ( $ this -> schema [ '_id' ] [ 'field' ] => $ id , ) , 'limit' => 1 , ) ) ; $ this -> db -> from ( $ this -> query [ 'table' ] ) ; $ this -> db -> where ( "{$this->table}.{$this->schema['_id']['field']}" , $ id ) ; $ this -> db -> limit ( 1 ) ; $ row = $ this -> db -> get ( ) -> row_array ( ) ; if ( $ row ) $ this -> ApplyRow ( $ row ) ; if ( ! $ this -> continue ) return FALSE ; $ this -> Trigger ( 'access' , $ this -> query [ 'where' ] ) ; if ( ! $ this -> continue ) return FALSE ; $ this -> Trigger ( 'pull' , $ this -> query [ 'where' ] ) ; if ( ! $ this -> continue ) return FALSE ; return $ this -> SetCache ( 'get' , $ id , $ row ) ; }
Retrieve a single item by its ID Calls the get trigger on the retrieved row
47,012
function GetAll ( $ where = null , $ orderby = null , $ limit = null , $ offset = null ) { $ this -> LoadSchema ( ) ; if ( $ this -> UseCache ( 'getall' ) ) { $ params = func_get_args ( ) ; $ cacheid = md5 ( json_encode ( $ params ) ) ; if ( $ value = $ this -> GetCache ( 'getall' , $ cacheid ) ) return $ value ; } $ this -> ResetQuery ( array ( 'method' => 'getall' , 'table' => $ this -> table , 'where' => $ where , 'orderby' => $ orderby , 'limit' => $ limit , 'offset' => $ offset , ) ) ; $ this -> Trigger ( 'access' , $ where ) ; if ( ! $ this -> continue ) return array ( ) ; $ this -> Trigger ( 'pull' , $ where ) ; if ( ! $ this -> continue ) return array ( ) ; $ this -> Trigger ( 'getall' , $ where , $ orderby , $ limit , $ offset ) ; if ( ! $ this -> continue ) return array ( ) ; $ this -> db -> from ( $ this -> table ) ; if ( $ where = $ this -> FilterFields ( $ where , 'where' ) ) $ this -> db -> where ( $ where ) ; if ( $ orderby ) $ this -> db -> order_by ( $ orderby ) ; if ( $ limit || $ offset ) $ this -> db -> limit ( $ limit , $ offset ) ; $ out = array ( ) ; foreach ( $ this -> db -> get ( ) -> result_array ( ) as $ row ) { $ this -> ApplyRow ( $ row ) ; if ( ! $ this -> continue ) return array ( ) ; $ out [ ] = $ row ; } $ this -> Trigger ( 'rows' , $ out ) ; if ( ! $ this -> continue ) return array ( ) ; return isset ( $ cacheid ) ? $ this -> SetCache ( 'getall' , $ cacheid , $ out ) : $ out ; }
Retrieves multiple items filtered by where conditions Calls the getall trigger to apply additional filters Calls the get trigger on each retrieved row
47,013
function UnCastType ( $ type , $ data , & $ row = null ) { switch ( $ type ) { case 'json' : return json_encode ( $ data ) ; case 'json-import' : if ( ! is_array ( $ data ) ) $ data = array ( ) ; foreach ( $ row as $ key => $ val ) { if ( substr ( $ key , 0 , 1 ) == '_' ) continue ; if ( ! isset ( $ this -> schema [ $ key ] ) ) { $ data [ $ key ] = $ val ; unset ( $ row [ $ key ] ) ; } } $ data = json_encode ( $ data ) ; return $ data ; default : return $ data ; } }
Converts a data type back into the DB format from the PHP object
47,014
function Create ( $ data ) { if ( ! $ this -> allowBlankCreate && ! $ data ) return ; $ this -> LoadSchema ( ) ; if ( $ this -> enforceTypes ) foreach ( $ this -> schema as $ key => $ props ) if ( isset ( $ data [ $ key ] ) || $ props [ 'type' ] == 'json-import' ) $ data [ $ key ] = $ this -> UnCastType ( $ props [ 'type' ] , isset ( $ data [ $ key ] ) ? $ data [ $ key ] : null , $ data ) ; $ this -> ResetQuery ( array ( 'method' => 'create' , 'table' => $ this -> table , 'data' => $ data , ) ) ; $ this -> Trigger ( 'access' , $ data ) ; if ( ! $ this -> continue ) return FALSE ; $ this -> Trigger ( 'push' , $ data ) ; if ( ! $ this -> continue ) return FALSE ; $ this -> Trigger ( 'create' , $ data ) ; if ( ! $ data = $ this -> FilterFields ( $ data , 'set' ) ) return FALSE ; if ( ! $ this -> continue ) return FALSE ; $ this -> db -> insert ( $ this -> table , $ data ) ; $ id = $ this -> db -> insert_id ( ) ; $ this -> Trigger ( 'created' , $ id , $ data ) ; return $ this -> returnRow ? $ this -> Get ( $ id ) : $ id ; }
Attempt to create a database record using the provided data Calls the create trigger on the data before it is saved
47,015
function Save ( $ id , $ data = null ) { if ( ! $ id ) return ; $ this -> LoadSchema ( ) ; if ( is_array ( $ id ) ) { $ data = $ id ; if ( ! isset ( $ data [ $ this -> schema [ '_id' ] [ 'field' ] ] ) ) return ; $ id = $ data [ $ this -> schema [ '_id' ] [ 'field' ] ] ; } else { $ data [ $ this -> schema [ '_id' ] [ 'field' ] ] = $ id ; } if ( ! $ data ) return ; if ( $ this -> enforceTypes ) foreach ( $ this -> schema as $ key => $ props ) if ( isset ( $ data [ $ key ] ) || $ props [ 'type' ] == 'json-import' ) $ data [ $ key ] = $ this -> UnCastType ( $ props [ 'type' ] , isset ( $ data [ $ key ] ) ? $ data [ $ key ] : null , $ data ) ; $ this -> ResetQuery ( array ( 'method' => 'save' , 'table' => $ this -> table , 'where' => array ( $ this -> schema [ '_id' ] [ 'field' ] => $ id , ) , 'data' => $ data , ) ) ; $ this -> Trigger ( 'access' , $ data ) ; if ( ! $ this -> continue ) return FALSE ; $ this -> Trigger ( 'push' , $ data ) ; if ( ! $ this -> continue ) return FALSE ; unset ( $ data [ $ this -> schema [ '_id' ] [ 'field' ] ] ) ; $ this -> trigger ( 'save' , $ id , $ data ) ; if ( ! $ this -> continue ) return FALSE ; if ( ! $ data = $ this -> FilterFields ( $ data , 'set' ) ) return FALSE ; if ( ! $ this -> continue ) return FALSE ; $ this -> db -> where ( "{$this->table}.{$this->schema['_id']['field']}" , $ id ) ; $ this -> db -> update ( $ this -> table , $ data ) ; $ this -> Trigger ( 'saved' , $ id , $ save ) ; $ this -> ClearCache ( 'get' , $ id ) ; return $ this -> returnRow ? $ this -> Get ( $ id ) : $ save ; }
Attempt to save a database record using the provided data Calls the save trigger on the data before it is saved
47,016
function Delete ( $ id ) { $ this -> LoadSchema ( ) ; $ data = array ( $ this -> schema [ '_id' ] [ 'field' ] => $ id ) ; $ this -> ResetQuery ( array ( 'method' => 'delete' , 'table' => $ this -> table , 'where' => array ( $ this -> schema [ '_id' ] [ 'field' ] => $ id , ) , ) ) ; $ this -> Trigger ( 'access' , $ data ) ; if ( ! $ this -> continue ) return FALSE ; $ this -> Trigger ( 'push' , $ data ) ; if ( ! $ this -> continue ) return FALSE ; $ this -> Trigger ( 'delete' , $ id ) ; if ( ! $ id ) return FALSE ; if ( ! $ this -> continue ) return FALSE ; $ this -> db -> from ( $ this -> table ) ; $ this -> db -> where ( "{$this->table}.{$this->schema['_id']['field']}" , $ id ) ; $ this -> db -> delete ( ) ; $ this -> Trigger ( 'deleted' , $ id ) ; return TRUE ; }
Delete a single item by its ID Calls the delete trigger on the retrieved row
47,017
function ResetQuery ( $ query = null ) { $ this -> db -> ar_select = array ( ) ; $ this -> db -> ar_distinct = FALSE ; $ this -> db -> ar_from = array ( ) ; $ this -> db -> ar_join = array ( ) ; $ this -> db -> ar_where = array ( ) ; $ this -> db -> ar_like = array ( ) ; $ this -> db -> ar_groupby = array ( ) ; $ this -> db -> ar_having = array ( ) ; $ this -> db -> ar_keys = array ( ) ; $ this -> db -> ar_limit = FALSE ; $ this -> db -> ar_offset = FALSE ; $ this -> db -> ar_order = FALSE ; $ this -> db -> ar_orderby = array ( ) ; $ this -> db -> ar_set = array ( ) ; $ this -> db -> ar_wherein = array ( ) ; $ this -> db -> ar_aliased_tables = array ( ) ; $ this -> db -> ar_store_array = array ( ) ; $ this -> joystError = '' ; $ this -> continue = TRUE ; $ this -> query = $ query ; }
Force CI ActiveRecord + Joyst to discard any half formed AR queries
47,018
public function configureAction ( Request $ request ) { if ( $ this -> get ( 'tenside.status' ) -> isTensideConfigured ( ) ) { throw new NotAcceptableHttpException ( 'Already configured.' ) ; } $ inputData = new JsonArray ( $ request -> getContent ( ) ) ; $ secret = bin2hex ( random_bytes ( 40 ) ) ; if ( $ inputData -> has ( 'credentials/secret' ) ) { $ secret = $ inputData -> get ( 'credentials/secret' ) ; } $ tensideConfig = $ this -> get ( 'tenside.config' ) ; $ tensideConfig -> set ( 'secret' , $ secret ) ; if ( $ inputData -> has ( 'configuration' ) ) { $ this -> handleConfiguration ( $ inputData -> get ( 'configuration' , true ) ) ; } $ user = $ this -> createUser ( $ inputData -> get ( 'credentials/username' ) , $ inputData -> get ( 'credentials/password' ) ) ; return new JsonResponse ( [ 'status' => 'OK' , 'token' => $ this -> get ( 'tenside.jwt_authenticator' ) -> getTokenForData ( $ user ) ] , JsonResponse :: HTTP_CREATED ) ; }
Configure tenside .
47,019
public function getProjectVersionsAction ( $ vendor , $ project ) { $ this -> checkUninstalled ( ) ; $ url = sprintf ( 'https://packagist.org/packages/%s/%s.json' , $ vendor , $ project ) ; $ rfs = new RemoteFilesystem ( $ this -> getInputOutput ( ) ) ; $ results = $ rfs -> getContents ( $ url , $ url ) ; $ data = new JsonArray ( $ results ) ; $ versions = [ ] ; foreach ( $ data -> get ( 'package/versions' ) as $ information ) { $ version = [ 'name' => $ information [ 'name' ] , 'version' => $ information [ 'version' ] , 'version_normalized' => $ information [ 'version_normalized' ] , ] ; $ normalized = $ information [ 'version' ] ; if ( 'dev-' === substr ( $ normalized , 0 , 4 ) ) { if ( isset ( $ information [ 'extra' ] [ 'branch-alias' ] [ $ normalized ] ) ) { $ version [ 'version_normalized' ] = $ information [ 'extra' ] [ 'branch-alias' ] [ $ normalized ] ; } } if ( isset ( $ information [ 'source' ] [ 'reference' ] ) ) { $ version [ 'reference' ] = $ information [ 'source' ] [ 'reference' ] ; } elseif ( isset ( $ information [ 'dist' ] [ 'reference' ] ) ) { $ version [ 'reference' ] = $ information [ 'dist' ] [ 'reference' ] ; } $ versions [ ] = $ version ; } return new JsonResponse ( [ 'status' => 'OK' , 'versions' => $ versions ] ) ; }
Retrieve the available versions of a package .
47,020
public function getInstallationStateAction ( ) { $ status = $ this -> get ( 'tenside.status' ) ; return new JsonResponse ( [ 'state' => [ 'tenside_configured' => $ status -> isTensideConfigured ( ) , 'project_created' => $ status -> isProjectPresent ( ) , 'project_installed' => $ status -> isProjectInstalled ( ) , ] , 'status' => 'OK' ] ) ; }
Check if installation is new partial or complete .
47,021
private function createUser ( $ username , $ password ) { $ user = new UserInformation ( [ 'username' => $ username , 'acl' => UserInformationInterface :: ROLE_ALL ] ) ; $ user -> set ( 'password' , $ this -> get ( 'security.password_encoder' ) -> encodePassword ( $ user , $ password ) ) ; $ user = $ this -> get ( 'tenside.user_provider' ) -> addUser ( $ user ) -> refreshUser ( $ user ) ; return $ user ; }
Add an user to the database .
47,022
private function handleConfiguration ( $ configuration ) { $ tensideConfig = $ this -> get ( 'tenside.config' ) ; if ( isset ( $ configuration [ 'php_cli' ] ) ) { $ tensideConfig -> setPhpCliBinary ( $ configuration [ 'php_cli' ] ) ; } if ( isset ( $ configuration [ 'php_cli_arguments' ] ) ) { $ tensideConfig -> setPhpCliArguments ( $ configuration [ 'php_cli_arguments' ] ) ; } if ( isset ( $ configuration [ 'php_cli_environment' ] ) ) { $ tensideConfig -> setPhpCliEnvironment ( $ configuration [ 'php_cli_environment' ] ) ; } if ( isset ( $ configuration [ 'php_force_background' ] ) ) { $ tensideConfig -> setForceToBackground ( $ configuration [ 'php_force_background' ] ) ; } if ( isset ( $ configuration [ 'php_can_fork' ] ) ) { $ tensideConfig -> setForkingAvailable ( $ configuration [ 'php_can_fork' ] ) ; } if ( isset ( $ configuration [ 'github_oauth_token' ] ) ) { $ composerAuth = new AuthJson ( $ this -> get ( 'tenside.home' ) -> tensideDataDir ( ) . DIRECTORY_SEPARATOR . 'auth.json' , null ) ; $ composerAuth -> setGithubOAuthToken ( $ configuration [ 'github_oauth_token' ] ) ; } }
Absorb the passed configuration .
47,023
function loadFile ( $ file , $ optional = false , $ varname = false , $ recursive = false ) { if ( ! is_file ( $ file ) ) { if ( $ optional ) return $ this ; else throw new Exception ( "Failed to read config file '$file'" ) ; } $ newConfig = @ include ( $ file ) ; if ( ! is_array ( $ newConfig ) && $ varname ) $ newConfig = $ $ varname ; if ( ! is_array ( $ newConfig ) && ! $ optional ) throw new Exception ( "Config file '$file' doesn't contain a config" ) ; else if ( is_array ( $ newConfig ) ) { if ( $ recursive ) $ this -> _data = array_merge_recursive ( $ this -> _data , $ newConfig ) ; else $ this -> _data = array_merge ( $ this -> _data , $ newConfig ) ; } return $ this ; }
Loads a config file and merges its contents with the previously loaded settings
47,024
public function find ( PageDocument $ page ) { $ request = $ this -> requestStack -> getCurrentRequest ( ) ; $ template = $ page -> getDefault ( AbstractPhpcrDocument :: DEFAULT_TEMPLATE_KEY ) ; if ( $ template === null ) { $ defaults = [ ] ; foreach ( $ this -> dynamicRouter -> getRouteEnhancers ( ) as $ enhancer ) { $ defaults = array_merge ( $ defaults , $ enhancer -> enhance ( [ '_content' => $ page ] , $ request ) ) ; } if ( array_key_exists ( AbstractPhpcrDocument :: DEFAULT_TEMPLATE_KEY , $ defaults ) ) { $ template = $ defaults [ AbstractPhpcrDocument :: DEFAULT_TEMPLATE_KEY ] ; } } return $ template ; }
Returns the default template for a given page
47,025
public function setPodmiot1 ( \ KCH \ PCC3 \ Deklaracja \ Podmiot1AnonymousType $ podmiot1 ) { $ this -> podmiot1 = $ podmiot1 ; return $ this ; }
Sets a new podmiot1
47,026
public function setZalaczniki ( \ KCH \ PCC3 \ Deklaracja \ ZalacznikiAnonymousType $ zalaczniki ) { $ this -> zalaczniki = $ zalaczniki ; return $ this ; }
Sets a new zalaczniki
47,027
public function restore ( $ workerInstance ) { list ( $ hostname , $ pid , $ queues ) = explode ( ':' , $ workerInstance , 3 ) ; if ( ! is_array ( $ queues ) ) { $ queues = explode ( ',' , $ queues ) ; } $ this -> queues = $ queues ; $ this -> pid = $ pid ; $ this -> id = $ workerInstance ; $ data = $ this -> resqueInstance -> redis -> get ( $ this -> workerName ( ) . ':' . $ workerInstance ) ; if ( $ data !== false ) { $ data = json_decode ( $ data , true ) ; $ this -> currentJob = new ResqueJobBase ( $ this -> resqueInstance , $ data [ 'queue' ] , $ data [ 'payload' ] , true ) ; } $ workerPids = self :: workerPids ( ) ; if ( ! in_array ( $ pid , $ workerPids ) ) { $ this -> unregisterWorker ( ) ; return false ; } return true ; }
Method for regenerate worker from the current ID saved in the redis and the instance in the server
47,028
private function interpolateString ( $ message , array $ context = [ ] ) { $ replace = [ ] ; foreach ( $ context as $ key => $ value ) { if ( ! is_array ( $ value ) && ( ! is_object ( $ value ) || method_exists ( $ value , '__toString' ) ) ) { $ replace [ '{' . $ key . '}' ] = $ value ; } } $ result = strtr ( $ message , $ replace ) ; if ( is_string ( $ result ) ) { return $ result ; } return sprintf ( '%s (WARNING: Unable to interpolate the context values into the message. %s).' , $ message , var_export ( $ replace , true ) ) ; }
Interpolate context values into the given string .
47,029
public static function file ( $ name , & $ exists = false ) { if ( ! defined ( "APP_DIR" ) ) { return [ ] ; } $ file = APP_DIR . "config" . DIRECTORY_SEPARATOR . $ name . '.php' ; if ( file_exists ( $ file ) ) { $ data = Helper :: includeImport ( $ file ) ; $ exists = true ; } if ( ! isset ( $ data ) || ! is_array ( $ data ) ) { $ data = [ ] ; } return $ data ; }
Get array data from file
47,030
public static function cache ( $ name ) { static $ cache = [ ] ; $ name = ( string ) $ name ; if ( ! isset ( $ cache [ $ name ] ) ) { $ cache [ $ name ] = new self ( $ name ) ; } return $ cache [ $ name ] ; }
Get cache property from file
47,031
public function group ( $ name ) { $ name = rtrim ( $ name , '.' ) ; $ pref = $ name . '.' ; $ len = strlen ( $ pref ) ; $ data = [ ] ; foreach ( array_keys ( $ this -> items ) as $ key ) { if ( $ key === $ name ) { $ data [ '.' ] = $ this -> items [ $ key ] ; } else if ( strlen ( $ key ) > $ len && substr ( $ key , 0 , $ len ) === $ pref ) { $ data [ substr ( $ key , $ len ) ] = $ this -> items [ $ key ] ; } } return new self ( $ data ) ; }
Get new property group
47,032
public function pathSet ( $ path , $ value ) { $ path = $ this -> createPath ( $ path ) ; if ( $ path [ 0 ] == 1 ) { $ this -> offsetSet ( $ path [ 1 ] , $ value ) ; } else { $ array = & $ this -> items ; for ( $ i = 1 , $ len = $ path [ 0 ] ; $ i <= $ len ; $ i ++ ) { $ key = $ path [ $ i ] ; if ( $ i == $ len ) { $ array [ $ key ] = $ value ; } else { if ( ! isset ( $ array [ $ key ] ) || ! is_array ( $ array [ $ key ] ) ) { $ array [ $ key ] = [ ] ; } $ array = & $ array [ $ key ] ; } } } return $ this ; }
Set value for path .
47,033
public function pathGetIs ( $ path , $ accessible = false ) { $ path = $ this -> createPath ( $ path ) ; $ array = & $ this -> items ; $ key = $ path [ 1 ] ; if ( $ path [ 0 ] > 1 ) { for ( $ i = 1 , $ len = $ path [ 0 ] ; $ i <= $ len ; $ i ++ ) { $ key = $ path [ $ i ] ; if ( ! array_key_exists ( $ key , $ array ) ) { return false ; } if ( $ i < $ len ) { if ( is_array ( $ array [ $ key ] ) ) { $ array = & $ array [ $ key ] ; } else { return false ; } } } } else if ( ! array_key_exists ( $ key , $ array ) ) { return false ; } if ( $ accessible ) { return is_array ( $ array [ $ key ] ) ; } return true ; }
Check value exists for path exist .
47,034
public function pathGetOr ( $ path , $ default ) { $ path = $ this -> createPath ( $ path ) ; if ( $ path [ 0 ] == 1 ) { return $ this -> get ( $ path [ 1 ] ) ; } $ array = & $ this -> items ; for ( $ i = 1 , $ len = $ path [ 0 ] ; $ i <= $ len ; $ i ++ ) { $ key = $ path [ $ i ] ; if ( ! array_key_exists ( $ key , $ array ) ) { break ; } if ( $ i == $ len ) { return $ array [ $ key ] ; } if ( ! isset ( $ array [ $ key ] ) || ! is_array ( $ array [ $ key ] ) ) { break ; } $ array = & $ array [ $ key ] ; } return $ default ; }
Get value from path or get default value if not exists .
47,035
function it_provides_useful_information_about_iterations ( ) { $ this -> next ( 'one' ) ; $ this -> getIndex ( ) -> shouldBe ( 0 ) ; $ this -> getKey ( ) -> shouldBe ( 'one' ) ; $ this -> isFirst ( ) -> shouldBe ( true ) ; $ this -> isLast ( ) -> shouldBe ( false ) ; $ this -> next ( 'two' ) ; $ this -> getIndex ( ) -> shouldBe ( 1 ) ; $ this -> getKey ( ) -> shouldBe ( 'two' ) ; $ this -> isFirst ( ) -> shouldBe ( false ) ; $ this -> isLast ( ) -> shouldBe ( false ) ; $ this -> next ( 'three' ) ; $ this -> getIndex ( ) -> shouldBe ( 2 ) ; $ this -> getKey ( ) -> shouldBe ( 'three' ) ; $ this -> isFirst ( ) -> shouldBe ( false ) ; $ this -> isLast ( ) -> shouldBe ( true ) ; }
It provides useful information about iterations .
47,036
public static function init ( $ config ) { if ( static :: $ initialized ) { throw new \ FuelException ( "You can't initialize Fuel more than once." ) ; } class_exists ( 'Redis' , false ) or class_alias ( 'Redis_Db' , 'Redis' ) ; static :: $ _paths = array ( APPPATH , COREPATH ) ; static :: $ is_cli = ( bool ) defined ( 'STDIN' ) ; \ Config :: load ( $ config ) ; if ( static :: $ is_cli or ! in_array ( 'gzip' , explode ( ', ' , \ Input :: headers ( 'Accept-Encoding' , '' ) ) ) ) { \ Config :: set ( 'ob_callback' , null ) ; } ob_start ( \ Config :: get ( 'ob_callback' ) ) ; if ( \ Config :: get ( 'caching' , false ) ) { \ Finder :: instance ( ) -> read_cache ( 'FuelFileFinder' ) ; } static :: $ profiling = \ Config :: get ( 'profiling' , false ) ; static :: $ profiling and \ Profiler :: init ( ) ; try { static :: $ timezone = \ Config :: get ( 'default_timezone' ) ? : date_default_timezone_get ( ) ; date_default_timezone_set ( static :: $ timezone ) ; } catch ( \ Exception $ e ) { date_default_timezone_set ( 'UTC' ) ; throw new \ PHPErrorException ( $ e -> getMessage ( ) ) ; } static :: $ encoding = \ Config :: get ( 'encoding' , static :: $ encoding ) ; MBSTRING and mb_internal_encoding ( static :: $ encoding ) ; static :: $ locale = \ Config :: get ( 'locale' , static :: $ locale ) ; if ( ! static :: $ is_cli ) { if ( \ Config :: get ( 'base_url' ) === null ) { \ Config :: set ( 'base_url' , static :: generate_base_url ( ) ) ; } } \ Security :: clean_input ( ) ; \ Event :: register ( 'fuel-shutdown' , 'Fuel::finish' ) ; static :: always_load ( ) ; \ Config :: load ( 'routes' , true ) ; \ Router :: add ( \ Config :: get ( 'routes' ) ) ; if ( static :: $ locale ) { setlocale ( LC_ALL , static :: $ locale ) or logger ( \ Fuel :: L_WARNING , 'The configured locale ' . static :: $ locale . ' is not installed on your system.' , __METHOD__ ) ; } static :: $ initialized = true ; \ Event :: instance ( ) -> has_events ( 'app_created' ) and \ Event :: instance ( ) -> trigger ( 'app_created' , '' , 'none' ) ; if ( static :: $ profiling ) { \ Profiler :: mark ( __METHOD__ . ' End' ) ; } }
Initializes the framework . This can only be called once .
47,037
public static function finish ( ) { if ( \ Config :: get ( 'caching' , false ) ) { \ Finder :: instance ( ) -> write_cache ( 'FuelFileFinder' ) ; } if ( static :: $ profiling and ! static :: $ is_cli and ! \ Input :: is_ajax ( ) ) { $ output = ob_get_clean ( ) ; $ headers = headers_list ( ) ; $ show = true ; foreach ( $ headers as $ header ) { if ( stripos ( $ header , 'content-type' ) === 0 and stripos ( $ header , 'text/html' ) === false ) { $ show = false ; } } if ( $ show ) { \ Profiler :: mark ( 'End of Fuel Execution' ) ; if ( preg_match ( "|</body>.*?</html>|is" , $ output ) ) { $ output = preg_replace ( "|</body>.*?</html>|is" , '' , $ output ) ; $ output .= \ Profiler :: output ( ) ; $ output .= '</body></html>' ; } else { $ output .= \ Profiler :: output ( ) ; } } ob_start ( \ Config :: get ( 'ob_callback' ) ) ; echo $ output ; } }
Cleans up Fuel execution ends the output buffering and outputs the buffer contents .
47,038
protected static function generate_base_url ( ) { $ base_url = '' ; if ( \ Input :: server ( 'http_host' ) ) { $ base_url .= \ Input :: protocol ( ) . '://' . \ Input :: server ( 'http_host' ) ; } if ( \ Input :: server ( 'script_name' ) ) { $ common = get_common_path ( array ( \ Input :: server ( 'request_uri' ) , \ Input :: server ( 'script_name' ) ) ) ; $ base_url .= $ common ; } return rtrim ( $ base_url , '/' ) . '/' ; }
Generates a base url .
47,039
public static function always_load ( $ array = null ) { is_null ( $ array ) and $ array = \ Config :: get ( 'always_load' , array ( ) ) ; isset ( $ array [ 'packages' ] ) and \ Package :: load ( $ array [ 'packages' ] ) ; isset ( $ array [ 'modules' ] ) and \ Module :: load ( $ array [ 'modules' ] ) ; if ( isset ( $ array [ 'classes' ] ) ) { foreach ( $ array [ 'classes' ] as $ class ) { if ( ! class_exists ( $ class = \ Str :: ucwords ( $ class ) ) ) { throw new \ FuelException ( 'Class ' . $ class . ' defined in your "always_load" config could not be loaded.' ) ; } } } if ( isset ( $ array [ 'config' ] ) ) { foreach ( $ array [ 'config' ] as $ config => $ config_group ) { \ Config :: load ( ( is_int ( $ config ) ? $ config_group : $ config ) , ( is_int ( $ config ) ? true : $ config_group ) ) ; } } if ( isset ( $ array [ 'language' ] ) ) { foreach ( $ array [ 'language' ] as $ lang => $ lang_group ) { \ Lang :: load ( ( is_int ( $ lang ) ? $ lang_group : $ lang ) , ( is_int ( $ lang ) ? true : $ lang_group ) ) ; } } }
Always load packages modules classes config & language files set in always_load . php config
47,040
public static function clean_path ( $ path ) { static $ search = array ( APPPATH , COREPATH , PKGPATH , DOCROOT , '\\' ) ; static $ replace = array ( 'APPPATH/' , 'COREPATH/' , 'PKGPATH/' , 'DOCROOT/' , '/' ) ; return str_ireplace ( $ search , $ replace , $ path ) ; }
Cleans a file path so that it does not contain absolute file paths .
47,041
public function send ( Request $ request ) { $ interface = $ request -> getInterface ( ) ; $ service = ConfigFactory :: getClient ( ) -> getService ( $ interface ) ; $ url = $ service -> getUrl ( ) ; $ requestRaw = Formatter :: serialize ( $ request ) ; $ responseRaw = $ this -> protocol -> sendData ( $ url , $ requestRaw ) ; $ response = @ Formatter :: unserialize ( $ responseRaw ) ; if ( ! ( $ response instanceof Response ) ) { LoggerProxy :: getInstance ( ) -> error ( "illegal response" , array ( $ responseRaw ) ) ; throw new InitiallyRpcException ( "illegal response" ) ; } elseif ( $ response -> isHasException ( ) ) { $ exception = $ response -> getException ( ) ; if ( is_object ( $ exception ) && $ exception instanceof Exception ) { throw $ exception ; } else if ( is_string ( $ exception ) ) { if ( class_exists ( $ exception ) ) { throw new $ exception ( $ response -> getExceptionMessage ( ) ) ; } else { throw new InitiallyRpcException ( $ response -> getExceptionMessage ( ) ) ; } } } return $ response -> getResult ( ) ; }
Send Rpc Request
47,042
protected function send ( $ content ) { $ streamOptions = array ( 'http' => array ( 'method' => 'POST' , 'header' => 'Content-Type: application/json' , 'content' => $ content , ) ) ; $ context = stream_context_create ( $ streamOptions ) ; $ result = @ file_get_contents ( $ this -> getServerUrl ( ) , false , $ context ) ; if ( $ result === false ) { throw new Exception ( 'Unable to connect to server' ) ; } return $ result ; }
Send low level data by http
47,043
public function sendActivationMessage ( ) { $ macros = new Macros ( $ this -> _data ) ; $ message = $ this -> _params -> get ( 'msg_account_activate_msg' ) ; $ message = $ macros -> text ( $ message ) ; $ subject = $ this -> _params -> get ( 'msg_account_activate_subject' ) ; return $ this -> send ( $ subject , $ message , $ this -> _data -> email , null , $ this -> _getFromMail ( ) ) ; }
Send user message when have success activation profile .
47,044
public function addAuthor ( string $ name = null , string $ email = null ) { is_null ( $ name ) and $ name = '' ; is_null ( $ email ) and $ email = '' ; if ( empty ( $ name ) and empty ( $ email ) ) { throw new AuthorNoDataException ( ) ; } if ( ! empty ( $ email ) ) { $ author = trim ( sprintf ( self :: FORMAT_AUTHOR , $ name , $ email ) ) ; } else { $ author = trim ( $ name ) ; } $ this -> authors [ ] = $ author ; return $ this ; }
Adds an author
47,045
public function addInterface ( string $ interfaceName , string $ alias = null ) { $ this -> interfaces [ ] = $ this -> addUse ( $ interfaceName , $ alias ) ; }
Adds an interface
47,046
public function addTrait ( string $ traitName , string $ alias = null ) { $ this -> traits [ ] = $ this -> addUse ( $ traitName , $ alias ) ; return $ this ; }
Adds a trait
47,047
public function extractClassNameFromUse ( string $ use ) { $ matches = [ ] ; if ( preg_match ( self :: USE_CLASS_EXTRACT_REGEXP , $ use , $ matches ) === 0 ) { throw new InvalidNamespaceException ( $ use ) ; } $ className = $ matches [ 'classname' ] ; $ namespace = array_key_exists ( 'namespace' , $ matches ) ? $ matches [ 'namespace' ] : '' ; if ( substr ( $ namespace , - 1 , 1 ) === '\\' ) { $ namespace = substr ( $ namespace , 0 , - 1 ) ; } return [ $ className , $ namespace ] ; }
Extracts the class name from a used namespaced class
47,048
public static function installJSDependencies ( $ event ) { echo "Installing JS Library dependencies for the AltamiraBundle\n" ; $ dir = getcwd ( ) ; ScriptHandler :: gitSubmodulesUpdate ( ) ; ScriptHandler :: cleanPublicJSDir ( ) ; echo "Installing jqplot\n" ; mkdir ( static :: getJSDir ( ) . DIRECTORY_SEPARATOR . "jqplot" , 0777 , true ) ; $ source = static :: getLibsDir ( ) . DIRECTORY_SEPARATOR . "jqplot" . DIRECTORY_SEPARATOR . "src" ; $ dest = static :: getJSDir ( ) . DIRECTORY_SEPARATOR . "jqplot" ; recursiveAssetsOnlyCopy ( $ source , $ dest ) ; echo "Installing flot\n" ; mkdir ( static :: getJSDir ( ) . DIRECTORY_SEPARATOR . "flot" , 0777 , true ) ; recursiveAssetsOnlyCopy ( static :: getLibsDir ( ) . DIRECTORY_SEPARATOR . "flot" , static :: getJSDir ( ) . DIRECTORY_SEPARATOR . "flot" ) ; echo "Installing flot-bubbles\n" ; mkdir ( static :: getJSDir ( ) . DIRECTORY_SEPARATOR . "flot-bubbles" , 0777 , true ) ; recursiveAssetsOnlyCopy ( static :: getLibsDir ( ) . DIRECTORY_SEPARATOR . "flot-bubbles" , static :: getJSDir ( ) . DIRECTORY_SEPARATOR . "flot-bubbles" ) ; }
if this gets any bigger break it up into separate methods
47,049
public static function getInstance ( array $ config = [ ] ) { if ( ! isset ( $ config [ 'name' ] ) ) { throw new \ Exception ( "You have to set the name of the field" , 1 ) ; } if ( ! isset ( $ config [ 'class' ] ) ) { $ config [ 'class' ] = Text :: className ( ) ; } return parent :: getInstance ( $ config ) ; }
Builds the field and returns it
47,050
public function rewindFile ( ) { $ this -> openFile ( ) ; if ( ! rewind ( $ this -> getFile ( ) ) ) { throw FileOperationException :: createForFailedToRewindFile ( $ this -> getFilePath ( ) ) ; } return $ this ; }
Rewind the file
47,051
public function isFileEmpty ( ) { $ this -> openFile ( ) ; $ saved_pointer = $ this -> getFilePointer ( ) ; $ this -> rewindFile ( ) -> seekFileToEnd ( ) ; $ size_pointer = $ this -> getFilePointer ( ) ; $ this -> seekFile ( $ saved_pointer ) ; return $ size_pointer === 0 ; }
Find whether file is empty
47,052
protected function checkFile ( $ writable = true ) { if ( ! $ this -> fileExists ( ) ) throw NonExistentFileException :: createForFileDoesNotExists ( $ this -> getFilePath ( ) ) ; if ( ! is_readable ( $ this -> file_path ) ) throw NotReadableFileException :: createForNotReadable ( $ this -> getFilePath ( ) ) ; if ( $ writable ) { if ( ! is_writable ( $ this -> file_path ) ) throw NotWritableFileException :: createForNotWritable ( $ this -> getFilePath ( ) ) ; } }
Checks the file whether exists and is readable or writable
47,053
protected function fileExists ( ) { $ this -> clearStatCache ( true ) ; return ( file_exists ( $ this -> file_path ) && is_file ( $ this -> file_path ) ) ; }
Checks whether file exists
47,054
public function createService ( ServiceLocatorInterface $ serviceLocator ) { $ identityRoleProvider = new IdentityRoleProvider ( $ serviceLocator -> get ( 'UserRbac\UserRoleLinkerMapper' ) , $ serviceLocator -> get ( 'UserRbac\ModuleOptions' ) ) ; if ( $ serviceLocator -> get ( 'zfcuser_auth_service' ) -> hasIdentity ( ) ) { $ identityRoleProvider -> setDefaultIdentity ( $ serviceLocator -> get ( 'zfcuser_auth_service' ) -> getIdentity ( ) ) ; } return $ identityRoleProvider ; }
Gets identity role provider
47,055
public function setValue ( $ value ) { foreach ( ( array ) $ this as $ element ) { if ( $ value == $ element -> getElement ( ) -> getValue ( ) ) { $ element -> getElement ( ) -> check ( ) ; } else { $ element -> getElement ( ) -> check ( false ) ; } } }
Sets the element where the value matches to checked .
47,056
public function getValue ( ) : ArrayObject { foreach ( ( array ) $ this as $ element ) { if ( $ element -> getElement ( ) instanceof Radio && $ element -> getElement ( ) -> checked ( ) ) { return new class ( [ $ element -> getElement ( ) -> getValue ( ) ] ) extends ArrayObject { public function __toString ( ) : string { return "{$this[0]}" ; } } ; } } return new class ( [ $ this -> value ] ) extends ArrayObject { public function __toString ( ) : string { return "{$this[0]}" ; } } ; }
Gets the checked value in the group .
47,057
public function isRequired ( ) : Group { foreach ( ( array ) $ this as $ el ) { if ( ! is_object ( $ el ) ) { continue ; } $ el -> getElement ( ) -> attribute ( 'required' , 1 ) ; } return $ this -> addTest ( 'required' , function ( $ value ) { foreach ( $ value as $ option ) { if ( $ option -> getElement ( ) instanceof Radio && $ option -> getElement ( ) -> checked ( ) ) { return true ; } } return false ; } ) ; }
Marks the group as required .
47,058
protected function getSections ( ) : array { $ sections = explode ( $ this -> getDivider ( ) , $ this -> getNotation ( ) ) ; foreach ( $ sections as $ index => $ section ) { $ sections [ $ index ] = explode ( $ this -> getSeparator ( ) , $ section ) ; } return $ sections ; }
Get exploded notation string .
47,059
protected function normalizeResultSet ( array $ resultSet ) { $ normalized = [ ] ; foreach ( $ resultSet as $ result ) { if ( ( $ normalizedResult = $ this -> normalizeResult ( $ result ) ) === null ) { continue ; } $ normalized [ $ normalizedResult ] = $ normalizedResult ; } return array_keys ( $ normalized ) ; }
Normalize a result set .
47,060
public static function create ( $ totalPage , $ pageSize = 10 , $ page = 1 , $ gets = [ ] ) { $ p = new PageUtil ( ) ; if ( $ pageSize < 1 ) { $ pageSize = 1 ; } $ total = ceil ( $ totalPage / $ pageSize ) ; if ( $ page < 1 ) { $ page = 1 ; } else if ( $ page > $ total ) { $ page = $ total ; } $ p -> page = $ page ; $ p -> gets = $ gets ; $ p -> total = $ total ; $ p -> pageSize = $ pageSize ; return $ p ; }
Page constructor .
47,061
public function make ( string $ alias ) { if ( array_key_exists ( $ alias , $ this -> bindings ) ) { $ classOrObject = $ this -> bindings [ $ alias ] ; if ( is_object ( $ classOrObject ) ) { return $ classOrObject ; } return $ this -> makeInstance ( $ classOrObject ) ; } if ( class_exists ( $ alias ) ) { return self :: register ( $ alias , $ this -> makeInstance ( $ alias ) ) -> make ( $ alias ) ; } throw new SimplesRunTimeError ( "Class '{$alias}' not found" ) ; }
Resolves and created a new instance of a desired class .
47,062
public function makeInstance ( $ className ) { $ reflection = new ReflectionClass ( $ className ) ; $ constructor = $ reflection -> getConstructor ( ) ; if ( ! $ constructor ) { return $ reflection -> newInstance ( ) ; } return $ reflection -> newInstanceArgs ( $ this -> resolveParameters ( $ constructor -> getParameters ( ) , [ ] ) ) ; }
Created a instance of a desired class .
47,063
public function exists ( $ instance , string $ method ) { $ reflection = new ReflectionClass ( get_class ( $ instance ) ) ; return $ reflection -> hasMethod ( $ method ) ; }
Checks whether a specific method is defined in a class
47,064
public function invoke ( $ instance , string $ method , array $ data ) { $ parameters = $ this -> resolveMethodParameters ( $ instance , $ method , $ data , true ) ; $ reflection = new ReflectionMethod ( get_class ( $ instance ) , $ method ) ; $ reflection -> setAccessible ( true ) ; return $ reflection -> invokeArgs ( $ instance , $ parameters ) ; }
Invoke a method of an instance of a class
47,065
public function resolveMethodParameters ( $ instance , $ method , $ parameters , $ labels = false ) { $ reflectionMethod = new ReflectionMethod ( $ instance , $ method ) ; return $ this -> resolveParameters ( $ reflectionMethod -> getParameters ( ) , $ parameters , $ labels ) ; }
Generate a list of values to be used like parameters to one method
47,066
public function resolveFunctionParameters ( $ callable , $ parameters , $ labels = false ) { $ reflectionFunction = new ReflectionFunction ( $ callable ) ; return $ this -> resolveParameters ( $ reflectionFunction -> getParameters ( ) , $ parameters , $ labels ) ; }
Generate a list of values to be used like parameters to one function
47,067
private function resolveParameters ( $ parameters , $ data , $ labels = false ) { $ resolved = [ ] ; foreach ( $ parameters as $ reflectionParameter ) { $ parameter = $ this -> parseParameter ( $ reflectionParameter , $ data , $ labels ) ; if ( ! is_null ( $ parameter ) ) { $ resolved [ ] = $ parameter ; continue ; } if ( $ parameterClassName = $ this -> extractClassName ( $ reflectionParameter ) ) { $ resolved [ ] = static :: make ( $ parameterClassName ) ; continue ; } $ resolved [ ] = null ; } return $ resolved ; }
Generate a list of values to be used like parameters to one method or function
47,068
private function parseParameter ( ReflectionParameter $ reflectionParameter , & $ data , $ labels ) { $ name = $ reflectionParameter -> getName ( ) ; $ value = null ; if ( $ reflectionParameter -> isOptional ( ) ) { $ value = $ reflectionParameter -> getDefaultValue ( ) ; } if ( $ labels ) { if ( isset ( $ data [ $ name ] ) ) { $ value = off ( $ data , $ name , $ value ) ; unset ( $ data [ $ name ] ) ; } return $ value ; } if ( isset ( $ data [ 0 ] ) ) { $ value = $ data [ 0 ] ; array_shift ( $ data ) ; reset ( $ data ) ; } return $ value ; }
Configure the beste resource to each parameter of one method or function
47,069
private function extractClassName ( ReflectionParameter $ reflectionParameter ) { if ( isset ( $ reflectionParameter -> getClass ( ) -> name ) ) { return $ reflectionParameter -> getClass ( ) -> name ; } return '' ; }
Get the name of class related to a list of parameters
47,070
public function execute ( ) { $ DB = $ this -> getDBO ( ) ; $ resultId = $ DB -> exec ( ) ; $ this -> setResultId ( $ resultId ) -> setConnectionId ( $ DB -> getResourceId ( ) ) -> setAffectedRows ( $ this -> getAffectedRows ( ) ) ; $ DB -> resetRun ( ) ; return $ this ; }
Executes the prepared Statement
47,071
public function listColumns ( ) { $ fieldNames = array ( ) ; $ field = NULL ; while ( $ field = mysqli_fetch_field ( $ this -> getResultId ( ) ) ) { $ fieldNames [ ] = $ field -> name ; } return $ fieldNames ; }
Lists all columns in a result row
47,072
public function getColumnMeta ( $ name = '' ) { $ retval = array ( ) ; $ field = NULL ; while ( $ field = mysqli_fetch_field ( $ this -> getResultId ( ) ) ) { $ f = new stdClass ( ) ; $ f -> name = $ field -> name ; $ f -> type = $ field -> type ; $ f -> default = $ field -> def ; $ f -> maxLength = $ field -> max_length ; $ f -> primaryKey = $ field -> primary_key ; $ retval [ ] = $ f ; } return $ retval ; }
Returns metadata for a column or all columns in a result set
47,073
public function freeResults ( ) { if ( is_a ( $ this -> getResultId ( ) , "mysqli_result" ) ) { mysqli_free_result ( $ this -> getResultId ( ) ) ; $ this -> setResultId ( FALSE ) ; } }
Frees the result
47,074
public function createOne ( \ Psr \ Http \ Message \ ServerRequestInterface $ p_request ) { $ this -> logger -> debug ( 'FreeFW.ApiController.createOne.start' ) ; $ apiParams = $ p_request -> getAttribute ( 'api_params' , false ) ; if ( $ apiParams -> hasData ( ) ) { $ data = $ apiParams -> getData ( ) ; if ( ! $ data -> isValid ( ) ) { $ this -> logger -> debug ( 'FreeFW.ApiController.createOne.end' ) ; return $ this -> createResponse ( 409 , $ data ) ; } $ data -> create ( ) ; $ this -> logger -> debug ( 'FreeFW.ApiController.createOne.end' ) ; return $ this -> createResponse ( 201 , $ data ) ; } else { return $ this -> createResponse ( 409 ) ; } }
Add new single element
47,075
public function removeOne ( \ Psr \ Http \ Message \ ServerRequestInterface $ p_request ) { $ this -> logger -> debug ( 'FreeFW.ApiController.removeOne.start' ) ; $ apiParams = $ p_request -> getAttribute ( 'api_params' , false ) ; if ( $ apiParams -> hasData ( ) ) { $ data = $ apiParams -> getData ( ) ; $ data -> remove ( ) ; $ this -> logger -> debug ( 'FreeFW.ApiController.removeOne.end' ) ; return $ this -> createResponse ( 204 ) ; } else { return $ this -> createResponse ( 409 ) ; } }
Remove single element
47,076
public function filter ( Query $ query ) { if ( ! empty ( $ this -> filterOptions [ 'conditions' ] ) ) { $ query -> where ( $ this -> filterOptions [ 'conditions' ] ) ; } if ( ! empty ( $ this -> filterOptions [ 'order' ] ) ) { $ query -> order ( $ this -> filterOptions [ 'order' ] ) ; } return $ query ; }
Apply filter conditions and order options to the given query .
47,077
public static function getBacklink ( $ url , ServerRequest $ request ) { if ( ! isset ( $ url [ 'plugin' ] ) ) { $ url [ 'plugin' ] = $ request -> getParam ( 'plugin' ) ; } if ( ! isset ( $ url [ 'controller' ] ) ) { $ url [ 'controller' ] = $ request -> getParam ( 'controller' ) ; } $ path = join ( '.' , [ 'FILTER_' . ( $ url [ 'plugin' ] ? $ url [ 'plugin' ] : '' ) , $ url [ 'controller' ] , $ url [ 'action' ] ] ) ; if ( ( $ filterOptions = $ request -> getSession ( ) -> read ( $ path ) ) ) { if ( isset ( $ filterOptions [ 'slug' ] ) ) { $ url [ 'sluggedFilter' ] = $ filterOptions [ 'slug' ] ; unset ( $ filterOptions [ 'slug' ] ) ; } if ( ! empty ( $ filterOptions ) ) { if ( ! isset ( $ url [ '?' ] ) ) { $ url [ '?' ] = [ ] ; } $ url [ '?' ] = array_merge ( $ url [ '?' ] , $ filterOptions ) ; } } return $ url ; }
Try to retrieve a filtered backlink from the session .
47,078
protected function _initFilterOptions ( ) { if ( ! $ this -> _filterEnabled && ! $ this -> _sortEnabled ) { return ; } $ options = [ 'conditions' => [ ] , 'order' => [ ] ] ; if ( ! empty ( $ this -> request -> getData ( ) ) ) { foreach ( $ this -> request -> getData ( ) as $ field => $ value ) { if ( ! isset ( $ this -> filterFields [ $ field ] ) || $ value === '' ) { continue ; } $ options = $ this -> _createFilterFieldOption ( $ field , $ value , $ options ) ; $ this -> activeFilters [ $ field ] = $ value ; } } if ( isset ( $ this -> sortFields [ $ this -> request -> getQuery ( 's' ) ] ) ) { $ d = 'asc' ; if ( $ this -> request -> getQuery ( 'd' ) ) { $ dir = strtolower ( $ this -> request -> getQuery ( 'd' ) ) ; if ( in_array ( $ dir , [ 'asc' , 'desc' ] ) ) { $ d = $ dir ; } } $ field = $ this -> request -> getQuery ( 's' ) ; $ options = $ this -> _createSortFieldOption ( $ field , $ d , $ options ) ; $ this -> activeSort [ $ field ] = $ d ; } elseif ( ! empty ( $ this -> defaultSort ) ) { $ options = $ this -> _createSortFieldOption ( $ this -> defaultSort [ 'field' ] , $ this -> defaultSort [ 'dir' ] , $ options ) ; $ this -> activeSort [ $ this -> defaultSort [ 'field' ] ] = $ this -> defaultSort [ 'dir' ] ; } if ( $ this -> request -> getQuery ( 'p' ) ) { $ this -> page = $ this -> request -> getQuery ( 'p' ) ; } $ this -> filterOptions = $ options ; }
Create the filter options that can be used for model find calls in the controller .
47,079
protected function _isSortEnabled ( ) { if ( ! isset ( $ this -> controller -> sortFields ) ) { return false ; } foreach ( $ this -> controller -> sortFields as $ field ) { if ( isset ( $ field [ 'actions' ] ) && is_array ( $ field [ 'actions' ] ) && in_array ( $ this -> action , $ field [ 'actions' ] ) ) { return true ; } } return false ; }
Check if sorting for the current controller action is enabled .
47,080
protected function _isFilterEnabled ( ) { if ( ! isset ( $ this -> controller -> filterFields ) ) { return false ; } foreach ( $ this -> controller -> filterFields as $ field ) { if ( isset ( $ field [ 'actions' ] ) && is_array ( $ field [ 'actions' ] ) && in_array ( $ this -> action , $ field [ 'actions' ] ) ) { return true ; } } return false ; }
Check if filtering for the current controller action is enabled .
47,081
protected function _isPaginationEnabled ( ) { if ( ! isset ( $ this -> controller -> limits ) || ! isset ( $ this -> controller -> limits [ $ this -> action ] ) || ! isset ( $ this -> controller -> limits [ $ this -> action ] [ 'default' ] ) || ! isset ( $ this -> controller -> limits [ $ this -> action ] [ 'limits' ] ) ) { return false ; } return true ; }
Check if pagination is enabled for the current controller action .
47,082
protected function _getSortFields ( ) { $ sortFields = [ ] ; foreach ( $ this -> controller -> sortFields as $ field => $ options ) { if ( isset ( $ options [ 'actions' ] ) && is_array ( $ options [ 'actions' ] ) && in_array ( $ this -> action , $ options [ 'actions' ] ) ) { $ sortFields [ $ field ] = $ options ; } } return $ sortFields ; }
Get all available sort fields for the current controller action .
47,083
protected function _getFilterFields ( ) { $ filterFields = [ ] ; foreach ( $ this -> controller -> filterFields as $ field => $ options ) { if ( isset ( $ options [ 'actions' ] ) && is_array ( $ options [ 'actions' ] ) && in_array ( $ this -> action , $ options [ 'actions' ] ) ) { $ filterFields [ $ field ] = $ options ; } } return $ filterFields ; }
Get all available filter fields for the current controller action .
47,084
protected function _createSortFieldOption ( $ field , $ dir , $ options ) { $ sortField = $ this -> sortFields [ $ field ] ; if ( isset ( $ sortField [ 'custom' ] ) ) { if ( ! is_array ( $ sortField [ 'custom' ] ) ) { $ sortField [ 'custom' ] = [ $ sortField [ 'custom' ] ] ; } foreach ( $ sortField [ 'custom' ] as $ sortEntry ) { $ options [ 'order' ] [ ] = preg_replace ( '/:dir/' , $ dir , $ sortEntry ) ; } } else { $ options [ 'order' ] [ ] = $ sortField [ 'modelField' ] . ' ' . $ dir ; } return $ options ; }
Create the order find condition part for a sorted field .
47,085
protected function _extractPassParams ( ) { if ( ! empty ( $ this -> controller -> filterPassParams [ $ this -> action ] ) ) { foreach ( $ this -> controller -> filterPassParams [ $ this -> action ] as $ key ) { if ( ! empty ( $ this -> request -> getParam ( $ key ) ) ) { $ this -> _passParams [ $ key ] = $ this -> request -> getParam ( $ key ) ; } } } }
Puts the values in the passParams array
47,086
protected function _getFilterData ( ) { $ rawFilterData = $ this -> request -> getData ( ) ; $ filterData = [ ] ; foreach ( $ this -> filterFields as $ filterField => $ options ) { if ( isset ( $ rawFilterData [ $ filterField ] ) && $ rawFilterData [ $ filterField ] !== '' ) { $ filterData [ $ filterField ] = $ rawFilterData [ $ filterField ] ; } } return $ filterData ; }
Get the filter data .
47,087
protected function _setupSort ( ) { if ( ! ( $ this -> _sortEnabled = $ this -> _isSortEnabled ( ) ) ) { return ; } $ this -> sortFields = $ this -> _getSortFields ( ) ; foreach ( $ this -> sortFields as $ field => $ options ) { if ( ! isset ( $ options [ 'default' ] ) ) { continue ; } $ dir = strtolower ( $ options [ 'default' ] ) ; if ( in_array ( $ dir , [ 'asc' , 'desc' ] ) ) { $ this -> defaultSort = [ 'field' => $ field , 'dir' => $ dir ] ; } } }
Setup default sort options .
47,088
protected function _setupFilters ( ) { if ( ! ( $ this -> _filterEnabled = $ this -> _isFilterEnabled ( ) ) ) { return ; } $ this -> filterFields = $ this -> _getFilterFields ( ) ; $ sluggedFilter = $ this -> request -> getParam ( 'sluggedFilter' , '' ) ; if ( $ sluggedFilter === '' ) { return ; } $ filterData = $ this -> Filters -> find ( 'filterDataBySlug' , [ 'request' => $ this -> request ] ) ; if ( empty ( $ filterData ) ) { return ; } $ data = array_merge ( $ this -> request -> getData ( ) , $ filterData ) ; foreach ( $ data as $ key => $ value ) { $ this -> request = $ this -> request -> withData ( $ key , $ value ) ; } $ this -> slug = $ sluggedFilter ; }
Setup the filter field options .
47,089
protected function _setupPagination ( ) { if ( ! ( $ this -> _paginationEnabled = $ this -> _isPaginationEnabled ( ) ) ) { return ; } $ this -> defaultLimit = $ this -> controller -> limits [ $ this -> action ] [ 'default' ] ; $ this -> limits = $ this -> controller -> limits [ $ this -> action ] [ 'limits' ] ; }
Setup the default pagination params .
47,090
protected function _isFilterRequest ( ) { return ( $ this -> controller !== null && $ this -> request !== null && $ this -> action !== null && $ this -> _filterEnabled ) ; }
Check if the current request is a filter request .
47,091
protected function _createFilterSlug ( array $ filterData ) { $ existingFilter = $ this -> Filters -> find ( 'slugForFilterData' , [ 'request' => $ this -> request , 'filterData' => $ filterData ] ) -> first ( ) ; if ( $ existingFilter ) { return $ existingFilter -> slug ; } return $ this -> Filters -> createFilterForFilterData ( $ this -> request , $ filterData ) ; }
Create a filter slug for the given filter data .
47,092
protected function _applyFilterData ( $ url ) { $ filterData = $ this -> _getFilterData ( ) ; if ( empty ( $ filterData ) ) { return $ url ; } return $ url + [ 'sluggedFilter' => $ this -> _createFilterSlug ( $ filterData ) , '?' => $ this -> request -> getQuery ( ) ] ; }
Apply filter data to the given url .
47,093
protected function _applyPassedParams ( $ url ) { if ( empty ( $ this -> _passParams ) ) { return $ url ; } return array_merge ( $ url , $ this -> _passParams ) ; }
Apply configured pass params to the url array .
47,094
protected function _applySort ( $ url ) { if ( ! $ this -> _sortEnabled ) { return $ url ; } if ( ! empty ( $ this -> request -> getQuery ( 's' ) ) ) { $ url [ '?' ] [ 's' ] = $ this -> request -> getQuery ( 's' ) ; } if ( ! empty ( $ this -> request -> getQuery ( 'd' ) ) ) { $ url [ '?' ] [ 'd' ] = $ this -> request -> getQuery ( 'd' ) ; } return $ url ; }
Pass sort options through to the filtered url .
47,095
public function getIsInstructable ( ) { $ isAjax = ( isset ( Yii :: $ app -> request -> isAjax ) && Yii :: $ app -> request -> isAjax ) ; if ( isset ( $ _GET [ '_instruct' ] ) ) { if ( ! empty ( $ _GET [ '_instruct' ] ) ) { $ this -> forceInstructions = true ; $ this -> disableInstructions = false ; } else { $ this -> forceInstructions = false ; $ this -> disableInstructions = true ; } } return ( is_array ( $ this -> data ) || $ this -> forceInstructions || $ isAjax ) && ! $ this -> disableInstructions ; }
Get is instructable .
47,096
public static function classInheritance ( $ object ) { $ class = new ReflectionClass ( $ object ) ; $ classNames = [ $ class -> getName ( ) ] ; while ( $ class = $ class -> getParentClass ( ) ) { $ classNames [ ] = $ class -> getName ( ) ; } return $ classNames ; }
Returns an array of the classname and all parent class names of the passed class or object
47,097
public function initApps ( ) { if ( count ( $ this -> apps ) > 0 ) { throw new AlreadyInitiatedException ( 'The apps are already loaded!' ) ; } foreach ( $ this -> appList as $ className ) { $ instance = new $ className ( $ this ) ; $ this -> apps -> append ( $ instance ) ; } foreach ( $ this -> apps as $ app ) { $ app -> load ( ) ; } foreach ( $ this -> apps as $ app ) { $ app -> registerRoutes ( Router :: getInstance ( ) ) ; } }
Load and initiate all apps .
47,098
public function findSection ( $ section ) { if ( ! isset ( $ this -> sectionMap [ $ section ] ) ) { throw new UnknownSection ( $ section ) ; } return $ this -> sectionMap [ $ section ] ; }
Finds a section class by name
47,099
public function parseArray ( array $ ini ) { $ sections = [ ] ; foreach ( $ ini as $ name => $ section ) { $ section = $ this -> parseSection ( $ name , $ section ) ; $ sections [ ] = $ section ; } return $ sections ; }
Parses an INI array