idx
int64
0
60.3k
question
stringlengths
92
4.62k
target
stringlengths
7
635
600
protected static function _getBaseRenderPayload ( $ viewFile = null , $ additional = array ( ) ) { $ additional = array_merge ( $ additional , \ Kisma :: get ( 'view.defaults' , array ( ) ) ) ; if ( null !== $ viewFile ) { $ additional = array_merge ( $ additional , \ Kisma :: get ( 'view.config.' . $ viewFile , array ( ) ) ) ; } $ _payload = array ( 'app_name' => \ Kisma :: get ( 'app.name' ) , 'app_root' => \ Kisma :: get ( 'app.root' ) , 'app_version' => \ Kisma :: get ( 'app.version' ) , 'page_date' => date ( 'Y-m-d H:i:s' ) , 'vendor_path' => \ Kisma :: get ( 'app.base_path' ) . '/vendor' , 'navbar' => \ Kisma :: get ( 'app.navbar' ) , ) ; return array_merge ( $ _payload , $ additional ) ; }
Returns an array of standard values passed to all views
601
public function attach ( Entity $ entity , $ forceReplace = false ) { $ hash = $ this -> getEntityHash ( $ entity ) ; if ( $ this -> isAttached ( $ hash ) && ! $ forceReplace ) throw new \ Exception ( 'Entity "' . $ entity -> getName ( ) . ' (' . $ hash . ')" already attached' ) ; $ this -> _entities [ $ hash ] = $ entity ; }
attach entity into entities list
602
public function detach ( $ entity ) { if ( ! is_string ( $ entity ) && ! is_object ( $ entity ) ) throw new \ Exception ( 'Entity must be a string or an object' ) ; if ( is_object ( $ entity ) ) { if ( ! $ entity instanceof Entity ) throw new \ Exception ( 'Entity must an instance of MidiChloriansPHP\mvc\model\Entity' ) ; $ entity = $ this -> getEntityHash ( $ entity ) ; } if ( $ this -> isAttached ( $ entity ) ) unset ( $ this -> _entities [ $ entity ] ) ; }
detach entity into entities list
603
public function delete ( $ entity = null ) { if ( ! is_null ( $ entity ) ) { if ( is_string ( $ entity ) ) { $ entity = $ this -> getEntity ( $ entity ) ; if ( is_null ( $ entity ) ) return false ; } elseif ( is_object ( $ entity ) ) { if ( ! $ entity instanceof Entity ) throw new \ Exception ( 'Entity must an instance of MidiChloriansPHP\mvc\model\Entity' ) ; } else throw new \ Exception ( 'Entity must be a string or an object' ) ; $ deleted = $ this -> _deleteEntity ( $ entity ) ; if ( $ deleted && $ this -> isAttached ( $ entity ) ) $ this -> detach ( $ entity ) ; return $ deleted ; } else { $ entityDeletedCount = 0 ; foreach ( $ this -> _entities as & $ entity ) { $ deleted = $ this -> _deleteEntity ( $ entity ) ; $ entityDeletedCount = $ entityDeletedCount + $ deleted ; if ( $ deleted ) $ this -> detach ( $ entity ) ; } return $ entityDeletedCount ; } }
delete into bdd
604
public static function assumePhpVersion ( $ atLeast , $ message = '' ) : void { assumeThat ( version_compare ( PHP_VERSION , $ atLeast , '>=' ) , is ( true ) , $ message ) ; }
Assumes that a specific version string is greater or equal to the PHP version .
605
public static function assumeExtensionLoaded ( $ extension , $ message = '' ) : void { assumeThat ( \ extension_loaded ( $ extension ) , is ( true ) , $ message ) ; }
Assumes that a specific PHP extension is loaded .
606
public static function assumeEnvironment ( $ varname , $ message = '' ) : void { assumeThat ( getenv ( $ varname ) , is ( not ( false ) ) , $ message ) ; }
Assumes that a specific environment variable is set .
607
public static function assumeFreeDiskSpace ( $ directory , $ available = null , $ message = '' ) : void { if ( $ available === null ) { assumeThat ( disk_free_space ( $ directory ) , is ( not ( false ) ) , $ message ) ; } else { assumeThat ( disk_free_space ( $ directory ) , is ( greaterThanOrEqualTo ( $ available ) ) , $ message ) ; } }
Assumes that a specific directory has free disk space .
608
public static function assumeOperatingSystem ( $ pattern , $ message = '' ) : void { $ regEx = sprintf ( '/%s/i' , addcslashes ( $ pattern , '/' ) ) ; assumeThat ( PHP_OS , matchesPattern ( $ regEx ) , $ message ) ; }
Assumes that a specific OS is used .
609
public static function arraySearch ( $ pValue , array $ pArray ) { foreach ( $ pArray as $ key => $ value ) { $ currentKey = $ key ; if ( $ pValue === $ value or ( is_array ( $ value ) and self :: arraySearch ( $ pValue , $ value ) !== false ) ) { return $ currentKey ; } } return false ; }
Search a value in a multidimensional array .
610
private function logQuery ( $ path , $ method , $ data , array $ query , $ start , $ engineMS = 0 , $ itemCount = 0 ) { if ( ! $ this -> _logger or ! $ this -> _logger instanceof ElasticaLogger ) { return ; } $ time = microtime ( true ) - $ start ; $ connection = $ this -> getLastRequest ( ) -> getConnection ( ) ; $ connection_array = array ( 'host' => $ connection -> getHost ( ) , 'port' => $ connection -> getPort ( ) , 'transport' => $ connection -> getTransport ( ) , 'headers' => $ connection -> hasConfig ( 'headers' ) ? $ connection -> getConfig ( 'headers' ) : array ( ) , ) ; $ this -> _logger -> logQuery ( $ path , $ method , $ data , $ time , $ connection_array , $ query , $ engineMS , $ itemCount ) ; }
Log the query if we have an instance of ElasticaLogger .
611
public function beforeExecuteRoute ( Dispatcher $ dispatcher ) { $ controllerName = $ dispatcher -> getControllerName ( ) ; if ( $ this -> acl -> isPrivate ( $ controllerName ) ) { $ identity = $ this -> auth -> getIdentity ( ) ; if ( ! is_array ( $ identity ) ) { $ this -> flash -> notice ( 'You don\'t have access to this module: private' ) ; $ dispatcher -> forward ( [ 'namespace' => 'Modules\Frontend\Controllers' , 'controller' => 'index' , 'action' => 'error' , ] ) ; return false ; } $ actionName = $ dispatcher -> getActionName ( ) ; if ( ! $ this -> acl -> isAllowed ( $ identity [ 'profile' ] , $ controllerName , $ actionName ) ) { $ this -> flash -> notice ( 'You don\'t have access to this module: ' . $ controllerName . ':' . $ actionName ) ; if ( $ this -> acl -> isAllowed ( $ identity [ 'profile' ] , $ controllerName , 'index' ) ) { $ dispatcher -> forward ( [ 'namespace' => 'Modules\Frontend\Controllers' , 'controller' => $ controllerName , 'action' => 'error' ] ) ; } else { $ dispatcher -> forward ( [ 'namespace' => 'Modules\Frontend\Controllers' , 'controller' => 'index' , 'action' => 'error' ] ) ; } return false ; } } }
Execute before the router so we can determine if this is a private controller and must be authenticated or a public controller that is open to all .
612
public static function on ( $ event , $ callback ) { if ( ! isset ( self :: $ observers [ $ event ] ) ) { self :: $ observers [ $ event ] = array ( ) ; } self :: $ observers [ $ event ] [ ] = $ callback ; }
Add watches to event
613
public static function fire ( $ event , $ data = array ( ) ) { if ( ! isset ( self :: $ observers [ $ event ] ) ) { return $ data ; } $ observers = self :: $ observers [ $ event ] ; foreach ( $ observers as $ observer ) { App :: runMethod ( $ observer , $ data ) ; } return $ data ; }
Fire event and process all watches
614
public function get_config ( $ section , $ key = '' , $ default = null ) { if ( $ section === '' || ! isset ( $ this -> data [ $ section ] ) ) { return null ; } if ( $ key === '' ) { return $ this -> data [ $ section ] ; } if ( ! isset ( $ this -> data [ $ section ] [ $ key ] ) ) { return $ default ; } return $ this -> data [ $ section ] [ $ key ] ; }
Get Config item
615
private function getReason ( OperationInterface $ operation ) { if ( ! $ this -> pool ) { return null ; } $ reason = $ operation -> getReason ( ) ; if ( $ reason instanceof Rule ) { switch ( $ reason -> getReason ( ) ) { case Rule :: RULE_JOB_INSTALL : return 'Required by the root package: ' . $ reason -> getPrettyString ( $ this -> pool ) ; case Rule :: RULE_PACKAGE_REQUIRES : return $ reason -> getPrettyString ( $ this -> pool ) ; default : } } return null ; }
Convert reason to text .
616
public function instantiate ( \ stdClass $ data , \ ReflectionClass $ reflection ) { $ object = $ reflection -> newInstanceArgs ( $ this -> prepareConstructorArguments ( $ reflection -> getConstructor ( ) , $ data ) ) ; return $ object ; }
Returns a new instance of a class based on the given reflection class and the given stdClass data object To avoid weird errors always have your code run supports first
617
public function supports ( \ stdClass $ data , \ ReflectionClass $ reflection ) { $ constructor = $ reflection -> getConstructor ( ) ; $ constructorParams = $ constructor -> getParameters ( ) ; $ invalidParams = array_filter ( $ constructorParams , function ( $ param ) use ( $ data ) { $ name = $ param -> getName ( ) ; if ( $ param -> isDefaultValueAvailable ( ) || property_exists ( $ data , $ name ) ) { return false ; } else { return true ; } } ) ; return count ( $ invalidParams ) > 0 ? false : true ; }
Determines if this class can instantiate an object from the given data
618
public function initTable ( ) { $ tableExist = $ this -> db -> query ( "SHOW TABLES LIKE '{$this->table}'" ) -> execute ( ) ; if ( ! $ tableExist ) { $ sql = "CREATE TABLE `$this->table` ( `{$this->idCol}` VARBINARY(128) NOT NULL PRIMARY KEY, `{$this->dataCol}` BLOB NOT NULL, `{$this->lifetimeCol}` MEDIUMINT NOT NULL, `{$this->timeCol}` INTEGER UNSIGNED NOT NULL ) COLLATE utf8_bin, ENGINE = InnoDB;" ; $ result = $ this -> db -> query ( $ sql ) -> execute ( ) ; $ tableExist = $ this -> db -> query ( "SHOW TABLES LIKE '{$this->table}'" ) -> execute ( ) ; if ( ! $ tableExist ) { throw new Exception ( 'Fail to create database session table' ) ; } } }
Init session table on plugin activation .
619
public function close ( ) { if ( $ this -> gcCalled ) { $ this -> gcCalled = false ; $ sql = "DELETE FROM $this->table WHERE $this->lifetimeCol + $this->timeCol < :time" ; $ stmt = $ this -> db -> query ( $ sql ) -> bind ( ':time' , time ( ) ) -> execute ( ) ; } return true ; }
Closes the current session .
620
public function read ( $ sessionId ) { $ this -> sessionExpired = false ; $ selectSql = $ this -> getSelectSql ( ) ; $ selectStmt = $ this -> db -> query ( $ selectSql ) -> bind ( ':id' , $ sessionId ) ; $ sessionRows = $ selectStmt -> row ( ) ; if ( $ sessionRows ) { if ( $ sessionRows -> { $ this -> timeCol } + $ sessionRows -> { $ this -> lifetimeCol } < time ( ) ) { $ this -> sessionExpired = true ; return '' ; } return is_resource ( $ sessionRows -> { $ this -> dataCol } ) ? stream_get_contents ( $ sessionRows -> { $ this -> dataCol } ) : $ sessionRows -> { $ this -> dataCol } ; } return '' ; }
Reads the session data .
621
public function write ( $ sessionId , $ data ) { $ maxlifetime = ( int ) ini_get ( 'session.gc_maxlifetime' ) ; $ mergeSql = $ this -> getMergeSQL ( ) ; $ result = $ this -> db -> query ( $ mergeSql ) -> bind ( ':id' , $ sessionId ) -> bind ( ':data' , $ data ) -> bind ( ':lifetime' , $ maxlifetime ) -> bind ( ':time' , time ( ) ) -> execute ( ) ; if ( $ result !== false ) { return true ; } throw new Exception ( 'Fail to save session to database' ) ; }
Writes the session data to the storage .
622
public function setConfig ( array $ config ) { foreach ( $ config as $ key => $ value ) { switch ( $ key ) { case 'verbose' : case 'loadEnv' : if ( ! is_bool ( $ value ) ) { throw new ConfigurationException ( $ key , 'This should be a boolean value.' ) ; } $ this -> config [ $ key ] = $ value ; break ; default : throw new ConfigurationException ( $ key , 'This is an unknown configuration option.' ) ; } } }
Set some of the optional config elements .
623
public function write ( ) { try { $ this -> envWriter -> save ( $ this -> answers ) ; $ this -> io -> out ( sprintf ( 'Answers saved to %s' , $ this -> envFile ) ) ; return true ; } catch ( WritableException $ e ) { $ this -> io -> out ( $ e -> getMessage ( ) ) ; return false ; } }
Write the answers to a file .
624
public function ask ( $ name , $ prompt , $ default = '' , $ required = false ) { $ this -> questions [ $ name ] = [ 'prompt' => $ prompt , 'default' => $ default , 'required' => $ required , ] ; }
Set a question to ask the user .
625
protected function parse_vars ( $ string ) { foreach ( $ this -> vars as $ var => $ val ) { $ string = str_replace ( "%$var%" , $ val , $ string ) ; } return $ string ; }
Parses a string using all of the previously set variables . Allows you to use something like %APPPATH% in non - PHP files .
626
protected function prep_vars ( & $ array ) { static $ replacements = false ; if ( $ replacements === false ) { foreach ( $ this -> vars as $ i => $ v ) { $ replacements [ '#^(' . preg_quote ( $ v ) . '){1}(.*)?#' ] = "%" . $ i . "%$2" ; } } foreach ( $ array as $ i => $ value ) { if ( is_string ( $ value ) ) { $ array [ $ i ] = preg_replace ( array_keys ( $ replacements ) , array_values ( $ replacements ) , $ value ) ; } elseif ( is_array ( $ value ) ) { $ this -> prep_vars ( $ array [ $ i ] ) ; } } }
Replaces FuelPHP s path constants to their string counterparts .
627
protected function find_file ( ) { $ paths = array ( ) ; foreach ( $ this -> languages as $ lang ) { $ paths = array_merge ( $ paths , \ Finder :: search ( 'lang' . DS . $ lang , $ this -> file , $ this -> ext , true ) ) ; } if ( empty ( $ paths ) ) { throw new \ LangException ( sprintf ( 'File "%s" does not exist.' , $ this -> file ) ) ; } return array_reverse ( $ paths ) ; }
Finds the given language files
628
public function find ( $ key , $ default = null , $ filter = null ) { return $ this -> _store -> get ( $ key , $ default , $ filter ) ; }
Find config param .
629
public static function getInstance ( ) { if ( self :: $ _instance === null ) { self :: $ _instance = new Config ( ) ; if ( self :: $ _instance -> _store === null ) { self :: $ _instance -> _store = self :: $ _instance -> _setStore ( ) ; } } return self :: $ _instance ; }
Get config instance .
630
public function save ( $ name , array $ data = [ ] ) { $ table = $ this -> _getTable ( ) ; $ entity = $ table -> findByName ( $ name ) -> first ( ) ; $ newData = [ 'name' => $ name , 'params' => $ data ] ; if ( $ entity !== null && $ entity -> get ( 'name' ) === $ name ) { $ entity = $ table -> patchEntity ( $ entity , $ newData ) ; } else { $ entity = $ table -> newEntity ( $ newData ) ; } return $ table -> save ( $ entity ) ; }
Update or save config data by config name .
631
protected function _setStore ( ) { $ tmp = [ ] ; $ rows = $ this -> _getTable ( ) -> find ( ) ; foreach ( $ rows as $ row ) { $ tmp [ $ row -> name ] = $ row -> get ( 'params' ) ; } return new JSON ( $ tmp ) ; }
Setup config store .
632
public function hasValidData ( \ Psr \ Http \ Message \ ServerRequestInterface $ request , $ key = null ) { if ( ! in_array ( $ request -> getMethod ( ) , [ 'POST' , 'PATCH' , 'PUT' , 'DELETE' ] ) ) { return false ; } if ( ! $ this -> check ( $ request ) ) { return false ; } $ data = $ request -> getParsedBody ( ) ; return ! isset ( $ key ) or isset ( $ data [ $ key ] ) ; }
Whether or not the current request is has a valid token .
633
public function check ( \ Psr \ Http \ Message \ ServerRequestInterface $ request ) { $ data = $ request -> getParsedBody ( ) ; if ( ! is_array ( $ data ) ) { return false ; } if ( ! isset ( $ data [ $ this -> name ] ) ) { return false ; } return $ this -> token === $ data [ $ this -> name ] ; }
Check the request token of a request .
634
public function & addItem ( MenuItem $ menu_item ) { $ this -> items [ $ menu_item -> getName ( ) ] = $ menu_item ; return $ this -> items [ $ menu_item -> getName ( ) ] ; }
Method to add a menu item as child
635
public function & createItem ( $ name , $ text , $ url = '' ) { $ menu_item = new MenuItem ( ) ; $ menu_item -> setName ( $ name ) ; $ menu_item -> setText ( $ text ) ; if ( $ url ) { $ menu_item -> setUrl ( $ url ) ; } $ this -> items [ $ name ] = $ menu_item ; return $ this -> items [ $ name ] ; }
Creates new menuitem and adds it to items list
636
public function getItems ( $ name = '' ) { if ( empty ( $ name ) ) { return $ this -> items ; } if ( ! isset ( $ this -> items [ $ name ] ) ) { return false ; } return $ this -> items [ $ name ] ; }
Returns one or all child items
637
public function processDefaults ( $ data , $ defaults = [ ] ) { if ( is_array ( $ defaults ) ) { $ defaults = $ data + $ defaults ; foreach ( $ defaults as $ key => $ value ) { if ( ! isset ( $ data [ $ key ] ) ) { if ( $ value !== false && empty ( $ data [ $ key ] ) ) { $ data [ $ key ] = $ value ; } elseif ( empty ( $ data [ $ key ] ) ) { switch ( $ key ) { default : break ; } } } } } return $ data ; }
Process the default values for the given defaults configuration .
638
public function validateContext ( $ data , $ rules ) { $ returnStatus = 'valid' ; $ returnData = null ; if ( array_key_exists ( 'context' , $ rules ) ) { foreach ( $ rules [ 'context' ] as $ rule ) { switch ( $ rule ) { case 'EXAMPLE' : if ( 1 !== 2 ) { $ returnStatus = $ rule ; } break ; default : break ; } } } if ( $ returnStatus != 'valid' ) { if ( array_key_exists ( $ returnStatus , $ this -> messages ) ) { $ data = $ this -> messages [ $ returnStatus ] ; } } return new Payload ( $ data , $ returnStatus ) ; }
Validate data based on the given context of the data AKA Custom Validation .
639
public function addItemIfNotEmpty ( string $ key , $ value , bool $ checkIfKeyExists = false , bool $ strict = false ) : self { if ( ( $ strict && $ value !== null ) || ( ! $ strict && $ value ) ) { if ( $ checkIfKeyExists && array_key_exists ( $ key , $ this -> array ) ) { throw new Exception ( 'Key [' . $ key . '] already exists' ) ; } if ( $ value === self :: DELETE ) { if ( array_key_exists ( $ key , $ this -> array ) ) { unset ( $ this -> array [ $ key ] ) ; } } else { $ this -> array [ $ key ] = $ value ; } } return $ this ; }
null = nothing to do false = remove item
640
public static function arrayDiffReplaceRecursive ( array $ a1 , array $ a2 , $ valueIfDelete = null ) : array { $ diff = [ ] ; foreach ( $ a1 as $ key => $ value ) { if ( ! array_key_exists ( $ key , $ a2 ) ) { $ diff [ $ key ] = $ valueIfDelete ; } else { if ( ! is_array ( $ value ) && $ value !== $ a2 [ $ key ] ) { $ diff [ $ key ] = $ a2 [ $ key ] ; } else if ( is_array ( $ value ) && ! is_array ( $ a2 [ $ key ] ) ) { $ diff [ $ key ] = $ a2 [ $ key ] ; } else if ( is_array ( $ value ) && is_array ( $ a2 [ $ key ] ) ) { $ subDiff = self :: arrayDiffReplaceRecursive ( $ value , $ a2 [ $ key ] , $ valueIfDelete ) ; if ( $ subDiff !== [ ] ) { $ diff [ $ key ] = $ subDiff ; } } unset ( $ a2 [ $ key ] ) ; } } if ( count ( $ a2 ) ) { $ diff = array_merge ( $ diff , $ a2 ) ; } return $ diff ; }
Mix diff and replace recursive
641
public static function getPercentage ( array $ tab , array $ keys = null ) { $ plein = 0 ; $ total = 0 ; foreach ( $ tab as $ key => $ value ) { if ( is_array ( $ keys ) && ! in_array ( $ key , $ keys ) ) { continue ; } if ( $ value ) { $ plein ++ ; } $ total ++ ; } return floor ( ( $ plein / $ total ) * 100 ) ; }
Get percentage of not empty cells
642
public static function extract ( Feature $ feature ) { $ serialized = FeatureSerializer :: serialize ( $ feature ) ; return self :: extractFromArray ( $ serialized ) ; }
extract all voter names
643
public static function extractFromArray ( $ value ) { $ extractVoters = function ( array $ filters ) { $ voters = [ ] ; foreach ( $ filters as $ filter ) { if ( is_array ( $ filter ) ) { $ voters = array_merge ( $ voters , array_keys ( $ filter ) ) ; } } return array_unique ( $ voters ) ; } ; $ voters = [ ] ; if ( isset ( $ value [ 'filters' ] ) ) { $ voters = array_merge ( $ voters , $ extractVoters ( $ value [ 'filters' ] ) ) ; } if ( isset ( $ value [ 'breaker' ] ) ) { $ voters = array_merge ( $ voters , $ extractVoters ( $ value [ 'breaker' ] ) ) ; } if ( isset ( $ value [ 'values' ] ) ) { foreach ( $ value [ 'values' ] as $ valueValue ) { if ( isset ( $ valueValue [ 'filters' ] ) ) { $ voters = array_merge ( $ voters , $ extractVoters ( $ valueValue [ 'filters' ] ) ) ; } } } return array_values ( array_unique ( $ voters ) ) ; }
extract all voter names from a serialized feature
644
public function listAction ( Request $ request ) { $ folderId = $ request -> get ( 'folder_id' ) ; $ start = $ request -> get ( 'start' , 0 ) ; $ limit = $ request -> get ( 'limit' , 25 ) ; $ sort = $ request -> get ( 'sort' , 'name' ) ; $ dir = $ request -> get ( 'dir' , 'ASC' ) ; $ showHidden = $ request -> get ( 'show_hidden' , false ) ; $ filter = $ request -> get ( 'filter' ) ; if ( ! $ folderId ) { throw new \ RuntimeException ( 'No folder ID' ) ; } if ( $ filter ) { $ filter = json_decode ( $ filter , true ) ; } $ data = [ ] ; $ total = 0 ; $ volume = $ this -> getVolumeByFolderId ( $ folderId ) ; $ securityContext = $ this -> get ( 'security.context' ) ; $ folder = $ volume -> findFolder ( $ folderId ) ; if ( $ securityContext -> isGranted ( 'ROLE_SUPER_ADMIN' ) || $ securityContext -> isGranted ( 'FILE_READ' , $ folder ) ) { if ( $ sort === 'create_time' ) { $ sort = 'created_at' ; } elseif ( $ sort === 'document_type_key' ) { $ sort = 'mime_type' ; } if ( $ filter ) { $ filter [ 'folder' ] = $ folder ; if ( ! $ showHidden ) { $ filter [ 'hidden' ] = false ; } $ files = $ volume -> findFiles ( $ filter , [ $ this -> toCamelCase ( $ sort ) => $ dir ] , $ limit , $ start ) ; $ total = $ volume -> countFiles ( $ filter ) ; } else { $ files = $ volume -> findFilesByFolder ( $ folder , [ $ this -> toCamelCase ( $ sort ) => $ dir ] , $ limit , $ start , $ showHidden ) ; $ total = $ volume -> countFilesByFolder ( $ folder , $ showHidden ) ; } $ data = $ this -> filesToArray ( $ volume , $ files ) ; } return new JsonResponse ( [ 'files' => $ data , 'totalCount' => $ total ] ) ; }
List files .
645
public function deleteAction ( Request $ request ) { $ fileId = $ request -> get ( 'file_id' ) ; $ fileIds = explode ( ',' , $ fileId ) ; $ volumeManager = $ this -> get ( 'phlexible_media_manager.volume_manager' ) ; foreach ( $ fileIds as $ fileId ) { try { $ volume = $ volumeManager -> getByFileId ( $ fileId ) ; $ file = $ volume -> findFile ( $ fileId ) ; $ volume -> deleteFile ( $ file , $ this -> getUser ( ) -> getId ( ) ) ; } catch ( NotFoundException $ e ) { } } return new ResultResponse ( true , count ( $ fileIds ) . ' file(s) deleted.' ) ; }
Delete File .
646
public function hideAction ( Request $ request ) { $ fileId = $ request -> get ( 'file_id' ) ; $ fileIds = explode ( ',' , $ fileId ) ; $ volumeManager = $ this -> get ( 'phlexible_media_manager.volume_manager' ) ; foreach ( $ fileIds as $ fileId ) { $ volume = $ volumeManager -> getByFileId ( $ fileId ) ; $ file = $ volume -> findFile ( $ fileId ) ; $ volume -> hideFile ( $ file , $ this -> getUser ( ) -> getId ( ) ) ; } return new ResultResponse ( true , count ( $ fileIds ) . ' file(s) hidden.' ) ; }
Hide File .
647
public function get ( $ setting = null , $ default = null ) { $ setting = trim ( $ setting ) ; if ( empty ( $ setting ) ) { return $ this -> store -> dump ( ) ; } $ value = $ this -> store -> get ( $ setting , $ default ) ; return self :: parse ( $ value ) ; }
Get a config setting
648
public function remove ( $ setting ) : bool { $ this -> dirty = true ; return $ this -> store -> delete ( $ setting ) ; }
Delete a key from the config
649
public static function parse ( $ param ) { if ( ! is_array ( $ param ) && ! is_object ( $ param ) ) { $ compare = trim ( strtolower ( $ param ) ) ; if ( in_array ( $ compare , array ( 'yes' , 'true' , 'on' , '1' ) ) ) { return true ; } if ( in_array ( $ compare , array ( 'no' , 'false' , 'off' , '0' ) ) ) { return false ; } } return $ param ; }
Post - parse a returned value from the config
650
public function next ( ) { $ this -> getCurrentIterator ( ) -> next ( ) ; if ( ! $ this -> getCurrentIterator ( ) -> valid ( ) ) { $ this -> moveToNextValidIterator ( ) ; } return $ this -> current ( ) ; }
Move forward to and return the next element
651
public function rewind ( ) { for ( $ this -> index = 0 ; $ this -> index < $ this -> iterators -> count ( ) ; $ this -> index ++ ) { $ this -> getCurrentIterator ( ) -> rewind ( ) ; } $ this -> index = 0 ; $ this -> moveToNextValidIterator ( ) ; }
Rewinds all iterators
652
protected function findVariablesThatReferenceClass ( array $ tokens ) { $ inNew = false ; $ variables = array ( ) ; foreach ( $ tokens as $ i => $ token ) { if ( is_string ( $ token ) ) { if ( trim ( $ token ) == ';' ) { $ inNew = false ; } continue ; } list ( $ token , $ value ) = $ token ; switch ( $ token ) { case T_NEW : $ inNew = true ; break ; case T_STRING : if ( $ inNew ) { if ( $ value == $ this -> outClassName [ 'fullyQualifiedClassName' ] ) { $ variables [ ] = $ this -> findVariableName ( $ tokens , $ i ) ; } } $ inNew = false ; break ; } } return $ variables ; }
Returns the variables used in test methods that reference the class under test .
653
protected function findVariableName ( array $ tokens , $ start ) { for ( $ i = $ start - 1 ; $ i >= 0 ; $ i -- ) { if ( is_array ( $ tokens [ $ i ] ) && $ tokens [ $ i ] [ 0 ] == T_VARIABLE ) { $ variable = $ tokens [ $ i ] [ 1 ] ; if ( is_array ( $ tokens [ $ i + 1 ] ) && $ tokens [ $ i + 1 ] [ 0 ] == T_OBJECT_OPERATOR && $ tokens [ $ i + 2 ] != '(' && $ tokens [ $ i + 3 ] != '(' ) { $ variable .= '->' . $ tokens [ $ i + 2 ] [ 1 ] ; } return $ variable ; } } return false ; }
Finds the variable name of the object for the method call that is currently being processed .
654
public function configNodeListeners ( $ uri , array $ listeners ) { if ( array_key_exists ( 'listeners' , $ listeners ) && count ( $ listeners [ 'listeners' ] ) > 0 ) { try { $ this -> logger -> addDebug ( 'EventDispatcher::configListeners adding eventhandler for ' . $ uri ) ; $ this -> addEventHandler ( $ uri , $ listeners [ 'listeners' ] , true ) ; } catch ( \ Exception $ e ) { $ this -> logger -> addError ( 'EventDispatcher::configListeners threw exception adding eventhandler for ' . $ uri ) ; $ this -> logger -> addError ( $ e -> getMessage ( ) ) ; } } }
configures event listeners for a local node CP - 175
655
public function listen ( $ uri , EventHandler $ handler , $ overRideYamlKey ) { if ( $ uri != 'all' && $ uri != $ this -> ymlKey && ! $ overRideYamlKey ) { return ; } $ this -> logger -> addDebug ( 'adding eventhandler for ' . $ uri . ' to listeners list' ) ; $ this -> listeners [ $ uri ] [ ] = $ handler ; }
adds an event handler to the listeners list
656
protected function replaceSchemaIndex ( & $ stub ) { if ( $ schema = $ this -> scaffoldCommandObj -> option ( 'schema' ) ) { $ schemaArray = ( new SchemaParser ) -> parse ( $ schema ) ; } $ schema = ( new SyntaxBuilder ) -> create ( $ schemaArray , $ this -> scaffoldCommandObj -> getMeta ( ) , 'view-index-header' ) ; $ stub = str_replace ( '{{header_fields}}' , $ schema , $ stub ) ; $ schema = ( new SyntaxBuilder ) -> create ( $ schemaArray , $ this -> scaffoldCommandObj -> getMeta ( ) , 'view-index-content' ) ; $ stub = str_replace ( '{{content_fields}}' , $ schema , $ stub ) ; return $ this ; }
Replace the schema for the index . stub .
657
protected function replaceSchemaShow ( & $ stub ) { if ( $ schema = $ this -> scaffoldCommandObj -> option ( 'schema' ) ) { $ schemaArray = ( new SchemaParser ) -> parse ( $ schema ) ; } $ schema = ( new SyntaxBuilder ) -> create ( $ schemaArray , $ this -> scaffoldCommandObj -> getMeta ( ) , 'view-show-content' ) ; $ stub = str_replace ( '{{content_fields}}' , $ schema , $ stub ) ; return $ this ; }
Replace the schema for the show . stub .
658
public function create ( $ name = '' ) { $ names = explode ( "," , $ name ) ; foreach ( $ names as $ name ) { $ content = $ this -> migrate ( RESOURCE . 'migrations/migration.php.dist' , [ 'name' => $ name ] ) ; $ fileName = FacadeMigration :: createName ( $ name ) ; if ( ! $ this -> file -> exists ( $ fileName ) ) { $ this -> file -> create ( $ fileName ) ; $ this -> write ( MIGRATION , $ fileName , $ content ) ; $ this -> info ( sprintf ( '%s migration created with successfully' , $ name ) ) ; } else { $ this -> error ( sprintf ( '%s file already exists in %s' , $ name , $ fileName ) ) ; } } }
create a new migration
659
private function write ( $ src , $ fileName , $ content ) { if ( ! $ this -> file -> exists ( $ src ) ) { $ this -> file -> makeDirectory ( $ src ) ; } $ this -> file -> put ( $ fileName , $ content ) ; }
write the content
660
private function migrate ( $ name , $ params = [ ] ) { $ generator = new TemplateGenerator ( ) ; $ generator -> setContent ( file_get_contents ( $ name ) ) ; return $ generator -> generate ( $ params ) ; }
create the migration template
661
protected function pullGet ( ) : array { if ( ! is_array ( $ this -> getVars ) ) { $ this -> getVars = $ this -> request -> getQueryParams ( ) ; } return $ this -> getVars ; }
Initializes the getVars property when necessary and returns it
662
protected function pullPost ( ) { if ( ! is_array ( $ this -> postVars ) ) { $ this -> postVars = $ this -> request -> getParsedBody ( ) ; if ( ! is_array ( $ this -> postVars ) ) { $ this -> postVars = [ ] ; } } return $ this -> postVars ; }
Initializes postVars property if necessary and returns it
663
protected function pullServer ( ) { if ( ! is_array ( $ this -> serverVars ) ) { $ this -> serverVars = $ this -> request -> getServerParams ( ) ; } return $ this -> serverVars ; }
Initializes serverVars property if necessary and returns it
664
protected function pullCookies ( ) { if ( ! is_array ( $ this -> cookieVars ) ) { $ this -> cookieVars = $ this -> request -> getCookieParams ( ) ; } return $ this -> cookieVars ; }
Initializes cookieVars property if necessary and returns it
665
protected function pullFiles ( ) { if ( ! is_array ( $ this -> filesVars ) ) { $ this -> filesVars = $ this -> request -> getUploadedFiles ( ) ; } return $ this -> filesVars ; }
Initializes filesVars property if necessary and returns it
666
protected function registerBrowscap ( ) { if ( ! config ( 'nodes.project.browsecap' , false ) ) { return ; } $ this -> app -> singleton ( Browscap :: class , function ( $ app ) { $ cacheDir = storage_path ( 'framework/browscap4' ) ; $ fileCache = new \ Doctrine \ Common \ Cache \ FilesystemCache ( $ cacheDir ) ; $ cache = new \ Roave \ DoctrineSimpleCache \ SimpleCacheAdapter ( $ fileCache ) ; $ logger = new \ Monolog \ Logger ( 'logger' ) ; $ browscap = new \ BrowscapPHP \ Browscap ( $ cache , $ logger ) ; $ updater = new \ BrowscapPHP \ BrowscapUpdater ( $ cache , $ logger ) ; $ updater -> update ( \ BrowscapPHP \ Helper \ IniLoader :: PHP_INI ) ; return $ browscap ; } ) ; }
Register browscap .
667
protected function registerUserAgentParser ( ) { $ this -> app -> bind ( 'nodes.useragent' , function ( $ app ) { return new NodesUserAgentParser ( $ app [ 'request' ] ) ; } ) ; $ this -> app -> singleton ( NodesUserAgentParser :: class , function ( $ app ) { return $ app [ 'nodes.useragent' ] ; } ) ; }
Register user agent parser .
668
protected function autoloadFilesAndDirectories ( ) { $ autoload = config ( 'nodes.autoload' , null ) ; if ( empty ( $ autoload ) ) { return ; } foreach ( $ autoload as $ item ) { $ itemPath = base_path ( $ item ) ; if ( ! file_exists ( $ itemPath ) ) { continue ; } if ( is_file ( $ itemPath ) ) { include $ itemPath ; } else { load_directory ( $ itemPath ) ; } } }
Autoload files and directories .
669
public function setFixtures ( $ table , $ fixtures , $ generator = null , $ baseIndex = 0 ) { $ loading = $ this -> currentSession -> into ( $ table ) ; if ( $ generator ) { $ loading = $ loading -> with ( $ generator ) ; } return $ loading -> load ( $ fixtures , $ baseIndex ) ; }
Load fixtures to specific table .
670
public function generateFixtures ( $ table , $ amount , $ generator = null , $ baseIndex = 0 ) { $ loading = $ this -> currentSession -> into ( $ table ) ; if ( $ generator ) { $ loading = $ loading -> with ( $ generator ) ; } return $ loading -> generate ( $ amount , $ baseIndex ) ; }
Generate fixtures and load them to specific table .
671
static function load ( $ name ) { if ( $ name == '' ) { return self :: $ data ; } $ name = Loader :: getName ( $ name , 'config' ) ; $ key = $ name -> app . '.' . $ name -> class ; if ( ! isset ( static :: $ data [ $ key ] ) ) { if ( ! file_exists ( $ name -> path ) ) { user_error ( 'Config ' . $ name -> path . ' Not Found' ) ; exit ; } self :: $ data [ $ key ] = ( require_once $ name -> path ) ; } return self :: $ data [ $ key ] ; }
load file config
672
static function read ( $ key = '' ) { if ( $ key === '' ) { return self :: $ data ; } $ key = self :: engineName ( $ key ) ; $ file = implode ( $ key -> file , '.' ) ; if ( ! isset ( self :: $ data [ $ file ] ) ) { return null ; } $ config = self :: $ data [ $ file ] ; foreach ( $ key -> keys as $ keys ) { if ( ! isset ( $ config [ $ keys ] ) ) { return null ; } $ config = $ config [ $ keys ] ; } return $ config ; }
read config data
673
static function write ( $ key , $ value ) { $ segments = self :: engineName ( $ key ) ; $ file = [ implode ( $ segments -> file , '.' ) ] ; $ keys = array_merge ( $ file , $ segments -> keys ) ; self :: $ data = array_replace_recursive ( self :: $ data , self :: _makeDimensional ( $ keys , $ value ) ) ; }
create or update config data
674
public static function engineName ( $ name ) { $ segments = explode ( '.' , $ name ) ; $ index = 0 ; foreach ( $ segments as $ i => $ name ) { if ( ctype_upper ( substr ( $ name , 0 , 1 ) ) and $ i != 0 ) { $ index = $ i + 1 ; break ; } } if ( $ index == 0 ) { user_error ( 'No Index Key Name' ) ; exit ; } return ( object ) [ 'file' => array_slice ( $ segments , 0 , $ index ) , 'keys' => array_slice ( $ segments , $ index ) ] ; }
parse name key and value config
675
protected static function _makeDimensional ( $ path , $ value ) { $ a = [ ] ; $ temp = & $ a ; foreach ( $ path as $ key ) { $ temp = & $ temp [ $ key ] ; } $ temp = $ value ; return $ a ; }
make path multidimensional array
676
protected function clean ( $ string ) { $ string = str_replace ( $ this -> getDelimiter ( ) , '_' , Container :: underscore ( $ string ) ) ; $ string = str_replace ( '.' , '_' , $ string ) ; $ string = preg_replace ( '/[^A-Za-z0-9_]/' , '' , $ string ) ; return preg_replace ( '/_+/' , '_' , $ string ) ; }
Clean string to use inside key .
677
protected function generateFilePath ( ) { $ hash = $ this -> getHash ( ) ; $ dir = '' ; $ depth = $ this -> getDepth ( ) ; for ( $ i = 0 ; $ i < $ depth ; ++ $ i ) { $ dir .= $ hash [ $ i ] . '/' ; } if ( '' != $ this -> getExtension ( ) ) { $ hash .= '.' . $ this -> getExtension ( ) ; } $ parts = array ( $ this -> getClassName ( ) , $ this -> getFieldName ( ) , rtrim ( $ dir , '/' ) , $ hash , ) ; return implode ( '/' , $ parts ) ; }
Generate file path from parameters that have been parsed from the key .
678
protected function generateKey ( ) { if ( '' == $ this -> getStorageName ( ) ) { throw new MissingKeyParameterException ( 'Cannot generate key without storage name' ) ; } if ( '' == $ this -> getClassName ( ) ) { throw new MissingKeyParameterException ( 'Cannot generate key without class name' ) ; } if ( '' == $ this -> getDepth ( ) ) { throw new MissingKeyParameterException ( 'Cannot generate key without depth' ) ; } if ( '' == $ this -> getHash ( ) ) { throw new MissingKeyParameterException ( 'Cannot generate key without hash' ) ; } $ hash = $ this -> getHash ( ) ; if ( '' != $ this -> getExtension ( ) ) { $ hash .= '.' . $ this -> getExtension ( ) ; } $ parts = array ( $ this -> getStorageName ( ) , $ this -> getClassName ( ) , $ this -> getFieldName ( ) , $ this -> getDepth ( ) , $ hash , ) ; return implode ( $ this -> getDelimiter ( ) , $ parts ) ; }
Generate key from parameters that have been set .
679
protected function parseKey ( $ key ) { if ( substr_count ( $ key , $ this -> getDelimiter ( ) ) != 4 ) { throw new InvalidKeyException ( 'Invalid file key: ' . $ key ) ; } $ this -> key = $ key ; list ( $ storageName , $ className , $ fieldName , $ depth , $ hashExt ) = explode ( $ this -> getDelimiter ( ) , $ key ) ; if ( false !== strpos ( $ hashExt , '.' ) ) { list ( $ hash , $ extension ) = explode ( '.' , $ hashExt , 2 ) ; } else { $ hash = $ hashExt ; $ extension = '' ; } $ this -> storageName = $ storageName ; $ this -> className = $ className ; $ this -> fieldName = $ fieldName ; $ this -> depth = $ depth ; $ this -> hash = $ hash ; $ this -> extension = $ extension ; return $ this ; }
Parse existing key and split it into its parts .
680
function it_holds_the_sql_fragments ( ) { $ this -> appendSql ( 'SELECT * FROM Phn' ) ; $ this -> appendSql ( ' ' ) ; $ this -> appendSql ( 'WHERE true;' ) ; $ this -> getSql ( ) -> shouldBe ( 'SELECT * FROM Phn WHERE true;' ) ; }
It holds the SQL fragments .
681
function it_converts_the_placeholders_into_a_numbered_suite ( ) { $ this -> appendSql ( 'SELECT * FROM Phn' ) ; $ this -> appendSql ( ' ' ) ; $ this -> appendSql ( 'WHERE $* IS NOT NULL AND $* = true;' ) ; $ this -> getSql ( ) -> shouldBeLike ( 'SELECT * FROM Phn WHERE $1 IS NOT NULL AND $2 = true;' ) ; }
It converts the placeholders into a numbered suite .
682
public function getCurrentTime ( ) { $ config = $ this -> config ; $ time = $ config -> time ; if ( $ time !== null ) { if ( $ config -> timeChanging ) { return $ this -> __call ( 'time' , [ ] ) + $ time ; } return $ time ; } return $ this -> __call ( 'time' , [ ] ) ; }
Returns a timestamp of the current time
683
public function setDefaultAction ( ) { $ params = $ this -> params ( ) ; $ locator = $ this -> getServiceLocator ( ) ; $ model = $ locator -> get ( 'Grid\User\Model\User\Group\Model' ) ; $ group = $ model -> find ( $ params -> fromRoute ( 'id' ) ) ; if ( empty ( $ group ) ) { $ this -> getResponse ( ) -> setStatusCode ( 404 ) ; return ; } if ( $ group -> predefined ) { $ this -> getResponse ( ) -> setStatusCode ( 403 ) ; return ; } if ( ! $ this -> getPermissionsModel ( ) -> isAllowed ( $ group , 'edit' ) ) { $ this -> getResponse ( ) -> setStatusCode ( 403 ) ; return ; } if ( ! $ group -> default ) { $ group -> default = true ; if ( $ group -> save ( ) ) { $ this -> messenger ( ) -> add ( 'user.form.group.success' , 'user' , Message :: LEVEL_INFO ) ; } else { $ this -> messenger ( ) -> add ( 'user.form.group.failed' , 'user' , Message :: LEVEL_ERROR ) ; } } return $ this -> redirect ( ) -> toRoute ( 'Grid\User\GroupAdmin\List' , array ( 'locale' => ( string ) $ this -> locale ( ) , ) ) ; }
Set to default a group
684
public function grantAction ( ) { $ params = $ this -> params ( ) ; $ request = $ this -> getRequest ( ) ; $ locator = $ this -> getServiceLocator ( ) ; $ groupModel = $ locator -> get ( 'Grid\User\Model\User\Group\Model' ) ; $ group = $ groupModel -> find ( $ params -> fromRoute ( 'id' ) ) ; if ( empty ( $ group ) ) { $ this -> getResponse ( ) -> setStatusCode ( 404 ) ; return ; } if ( ! $ this -> getPermissionsModel ( ) -> isAllowed ( $ group , 'grant' ) ) { $ this -> getResponse ( ) -> setStatusCode ( 403 ) ; return ; } $ rightModel = $ locator -> get ( 'Grid\User\Model\User\Right\Model' ) ; $ rights = $ rightModel -> findAllByGroup ( $ group -> id ) ; if ( $ request -> isPost ( ) ) { $ data = $ request -> getPost ( ) ; if ( isset ( $ data [ 'save' ] ) && ! empty ( $ data [ 'rights' ] ) ) { foreach ( $ data [ 'rights' ] as $ rightId => $ grant ) { $ rightModel -> grantToGroup ( $ rightId , $ group -> id , $ grant ) ; } $ this -> messenger ( ) -> add ( 'user.form.grant.success' , 'user' , Message :: LEVEL_INFO ) ; return $ this -> redirect ( ) -> toRoute ( 'Grid\User\GroupAdmin\List' , array ( 'locale' => ( string ) $ this -> locale ( ) , ) ) ; } } return array ( 'group' => $ group , 'rights' => $ rights , ) ; }
Grant rights for a group
685
protected function copyBranch ( $ branch , $ parentId ) { $ Model = $ this -> Model ; $ copy = new $ Model ( $ branch -> attributesToArray ( ) ) ; $ copy -> parentId = $ parentId ; $ copy -> save ( ) ; $ parentId = $ copy -> id ; foreach ( $ branch -> children as $ child ) { $ this -> copyBranch ( $ child , $ parentId ) ; } return $ copy ; }
Duplicates a branch
686
public function get ( $ key = '' , $ default = null ) { $ key = $ this -> getCompositeKey ( $ key ) ; if ( empty ( $ key ) ) { return $ this -> storage ; } return ArrayHelper :: getValue ( $ this -> storage , $ key , $ default ) ; }
Get array value .
687
public function set ( $ key , $ value = null ) : void { if ( is_array ( $ key ) ) { $ this -> storage = array_replace_recursive ( $ this -> storage , $ key ) ; } elseif ( $ value !== null ) { $ key = $ this -> getCompositeKey ( $ key ) ; ArrayHelper :: set ( $ this -> storage , $ key , $ value ) ; } $ this -> cache -> set ( self :: KEY , $ this -> storage ) ; }
Set array value .
688
public function add ( $ key , $ value = null ) : void { if ( is_array ( $ key ) ) { $ this -> storage = array_replace_recursive ( $ this -> storage , $ key ) ; } elseif ( $ value !== null ) { $ key = $ this -> getCompositeKey ( $ key ) ; ArrayHelper :: set ( $ this -> storage , $ key , $ value ) ; } }
Add array value .
689
public function delete ( $ key ) : void { $ key = $ this -> getCompositeKey ( $ key ) ; ArrayHelper :: delete ( $ this -> storage , $ key ) ; $ this -> cache -> set ( self :: KEY , $ this -> storage ) ; }
Delete array value .
690
public function getOrSet ( $ key , \ Closure $ fn ) { $ key = $ this -> getCompositeKey ( $ key ) ; if ( ( $ value = $ this -> get ( $ key ) ) !== null ) { return $ value ; } if ( $ fn instanceof \ Closure ) { $ value = $ fn ( $ this ) ; $ this -> set ( $ key , $ value ) ; } }
Get or ser array value .
691
public function getAndDelete ( $ key ) { $ key = $ this -> getCompositeKey ( $ key ) ; $ value = $ this -> get ( $ key ) ; $ this -> delete ( $ key ) ; return $ value ; }
Get and delete array value .
692
public function existsOrSet ( $ key , \ Closure $ fn ) : bool { $ key = $ this -> getCompositeKey ( $ key ) ; if ( ! ArrayHelper :: key_exists ( $ this -> storage , $ key ) ) { if ( $ fn instanceof \ Closure ) { $ value = $ fn ( $ this ) ; $ this -> set ( $ key , $ value ) ; } return false ; } return true ; }
Key exists or ser array value .
693
protected function getCompositeKey ( string $ key ) : string { $ keys = $ this -> keys ; $ keys [ ] = $ key ; $ output = implode ( '.' , $ keys ) ; return trim ( $ output , '.' ) ; }
Get a composite key .
694
private function setOrder ( $ order ) { if ( ! \ in_array ( $ order , [ self :: ORDER_ASC , self :: ORDER_DESC ] ) ) { throw new \ InvalidArgumentException ( 'Invalid order: ' . $ order ) ; } $ this -> order = $ order ; return $ this ; }
Sets the order of the order
695
private function setNullsPosition ( $ nullsPosition ) { if ( ! \ in_array ( $ nullsPosition , [ self :: NULLS_FIRST , self :: NULLS_LAST ] ) ) { throw new \ InvalidArgumentException ( 'Invalid nulls position: ' . $ nullsPosition ) ; } $ this -> nullsPosition = $ nullsPosition ; return $ this ; }
Set the nulls position
696
private function setBaseURL ( ) { if ( isset ( $ _SERVER [ 'HTTP_HOST' ] ) ) { $ base_url = isset ( $ _SERVER [ 'HTTPS' ] ) && strtolower ( $ _SERVER [ 'HTTPS' ] ) !== 'off' ? 'https' : 'http' ; $ base_url .= '://' . $ _SERVER [ 'HTTP_HOST' ] ; $ base_url .= str_replace ( basename ( $ _SERVER [ 'SCRIPT_NAME' ] ) , '' , $ _SERVER [ 'SCRIPT_NAME' ] ) ; } else { $ base_url = 'http://localhost/' ; } self :: $ base_url = $ base_url ; }
Constructs base URL and registers it .
697
private function invokeMethod ( ) { if ( $ this -> located_controller === NULL ) { throw new Exception ( '404 Not Found.' ) ; } $ class = "App\\Controller\\" . $ this -> located_controller ; if ( ! class_exists ( $ class ) ) { throw new Exception ( "$class class not found." ) ; } $ controller = new $ class ; if ( method_exists ( $ controller , $ this -> located_method ) ) { $ reflection = new ReflectionMethod ( $ controller , $ this -> located_method ) ; $ parameter = array ( ) ; $ index = 0 ; foreach ( $ reflection -> getParameters ( ) as $ param ) { if ( array_key_exists ( $ index , $ this -> remaining_uri ) ) { $ parameter [ $ index ] = $ this -> remaining_uri [ $ index ] ; } else if ( $ param -> isOptional ( ) ) { $ parameter [ $ index ] = $ param -> getDefaultValue ( ) ; } else { throw new Exception ( 'Not found.' ) ; } $ index ++ ; } $ reflection -> invokeArgs ( $ controller , $ parameter ) ; } }
Invokes located method .
698
public function exceptionHandler ( Exception $ ex ) { return $ this -> errorHandler ( E_USER_ERROR , $ ex -> getMessage ( ) , $ ex -> getFile ( ) , $ ex -> getLine ( ) ) ; }
Custom exception handler .
699
private function setRequestURI ( ) { if ( ! isset ( $ _SERVER [ 'REQUEST_URI' ] ) || ! isset ( $ _SERVER [ 'SCRIPT_NAME' ] ) ) { $ this -> request_uri = '' ; } else { $ uri = $ _SERVER [ 'REQUEST_URI' ] ; $ script = $ _SERVER [ 'SCRIPT_NAME' ] ; if ( strpos ( $ uri , $ script ) === 0 ) { $ uri = substr ( $ uri , strlen ( $ script ) ) ; } elseif ( strpos ( $ uri , dirname ( $ script ) ) === 0 ) { $ uri = substr ( $ uri , strlen ( dirname ( $ script ) ) ) ; } if ( strncmp ( $ uri , '?/' , 2 ) === 0 ) { $ uri = substr ( $ uri , 2 ) ; } $ parts = preg_split ( '#\?#i' , $ uri , 2 ) ; $ uri = $ parts [ 0 ] ; if ( $ uri == '/' || empty ( $ uri ) ) { $ this -> request_uri = '' ; } $ uri = parse_url ( $ uri , PHP_URL_PATH ) ; $ this -> request_uri = str_replace ( array ( '//' , '../' ) , '/' , trim ( $ uri , '/' ) ) ; } }
Parses REQUEST_URI and set it to request_uri property of this class .