idx
int64 0
60.3k
| question
stringlengths 64
4.24k
| target
stringlengths 5
618
|
|---|---|---|
13,300
|
public function loadWithDefault ( string $ configPath , string $ defaultConfigPath ) : void { if ( ! file_exists ( $ configPath ) ) { return ; } $ configDefault = include $ defaultConfigPath ; $ config = include $ configPath ; if ( ! is_array ( $ configDefault ) && ! is_array ( $ config ) ) { return ; } $ this -> loadArray ( array_merge ( $ configDefault , $ config ) ) ; }
|
Loads configuration from configuration file and from default configuration file .
|
13,301
|
public function loadArray ( array $ config , $ overwrite = false ) : void { foreach ( $ config as $ name => $ value ) { if ( ! $ overwrite && property_exists ( $ this , $ name ) ) { continue ; } $ this -> $ name = $ value ; } }
|
Loads configuration from array .
|
13,302
|
public function loadFromIni ( string $ iniPath , bool $ overwrite = false ) : void { if ( ! file_exists ( $ iniPath ) ) { return ; } $ iniArr = null ; try { $ iniArr = parse_ini_file ( $ iniPath , false , INI_SCANNER_TYPED ) ; } catch ( \ Throwable $ e ) { } if ( ! is_array ( $ iniArr ) ) { return ; } $ iniArr = array_change_key_case ( $ iniArr , CASE_LOWER ) ; $ arr = [ ] ; foreach ( $ iniArr as $ name => $ value ) { $ arr [ lcfirst ( str_replace ( '_' , '' , ucwords ( str_replace ( '.' , '_' , $ name ) , '_' ) ) ) ] = $ value ; } $ this -> loadArray ( $ arr , $ overwrite ) ; }
|
Loads configuration from INI file .
|
13,303
|
protected function fieldsRemain ( ) { $ bufferlen = strlen ( $ this -> buffer ) ; $ minlen = strlen ( $ this -> lastBoundary ) ; if ( $ bufferlen < $ minlen ) { if ( feof ( $ this -> fp ) ) { fclose ( $ this -> fp ) ; throw new \ sndsgd \ http \ data \ DecodeException ( "Invalid multipart data encountered; " . "end of content was reached before expected" ) ; } $ bytes = fread ( $ this -> fp , $ this -> bytesPerRead ) ; if ( $ bytes === false ) { fclose ( $ this -> fp ) ; throw new \ RuntimeException ( "failed to read $minlen bytes from input stream" ) ; } $ this -> buffer .= $ bytes ; } return ( strpos ( $ this -> buffer , $ this -> lastBoundary ) !== 0 ) ; }
|
Determine if any more fields remain in the stream
|
13,304
|
private function getValueFromField ( ) { $ position = $ this -> readUntil ( $ this -> boundary ) ; $ value = substr ( $ this -> buffer , 0 , $ position - 2 ) ; $ this -> buffer = substr ( $ this -> buffer , $ position ) ; return $ value ; }
|
Get the value of the current field in the input stream
|
13,305
|
public static function replaceFirst ( $ search , $ replace , $ subject ) { if ( $ search == '' ) { return $ subject ; } $ position = mb_strpos ( $ subject , $ search ) ; if ( $ position !== false ) { return mb_substr ( $ subject , 0 , $ position ) . $ replace . mb_substr ( $ subject , $ position + mb_strlen ( $ search ) ) ; } return $ subject ; }
|
Replace the first occurrence of a given value in the string .
|
13,306
|
public static function getLevel ( $ level = null ) { $ level = strtoupper ( $ level ) ; if ( array_key_exists ( $ level , self :: $ levels ) ) return self :: $ levels [ $ level ] ; return self :: $ levels [ self :: DEFAULT_LOG_LEVEL ] ; }
|
Map provided log level to level code
|
13,307
|
protected function _get ( $ url , $ parameters = null , $ scopes = [ ] , $ class = null ) { $ client = new HttpClient ( $ this -> patrol , 'get' , $ url , $ parameters ) ; $ client -> setScopes ( $ scopes ) ; $ data = $ client -> response ( ) ; if ( isset ( $ data [ 'error' ] ) ) { $ this -> _error ( $ data ) ; } $ data = $ data [ 'data' ] ; $ callee = $ class ? $ class : get_called_class ( ) ; return Util :: parseResponseToPatrolObject ( $ this -> patrol , $ data , $ callee , $ this -> defaults ) ; }
|
Perform a GET request based on this model
|
13,308
|
protected function _post ( $ url , $ data = [ ] , $ class = null ) { $ client = new HttpClient ( $ this -> patrol , 'post' , $ url , $ data ) ; $ data = $ client -> response ( ) ; if ( isset ( $ data [ 'error' ] ) ) { $ this -> _error ( $ data ) ; } if ( ! isset ( $ data [ 'data' ] ) ) { return $ data ; } $ data = $ data [ 'data' ] ; $ callee = $ class ? $ class : get_called_class ( ) ; return Util :: parseResponseToPatrolObject ( $ this -> patrol , $ data , $ callee , $ this -> defaults ) ; }
|
Perform a POST request based on this model
|
13,309
|
public function redirectToRoute ( $ route , array $ params = [ ] , $ permanent = false ) { $ map = $ this -> app ( ) -> getRouteMap ( ) ; $ url = $ map -> assemble ( $ route , $ params ) ; return $ this -> redirect ( $ url , $ permanent ) ; }
|
Redirects to a named route .
|
13,310
|
protected function getHttpClient ( $ config ) { $ guzzleConfig = Arr :: get ( $ config , 'guzzle' , [ ] ) ; return new HttpClient ( Arr :: add ( $ guzzleConfig , 'connect_timeout' , 60 ) ) ; }
|
Get a fresh Guzzle HTTP client instance .
|
13,311
|
public function download ( $ request , $ match ) { $ resource = Pluf_Shortcuts_GetObjectOr404 ( 'Tenant_Resource' , $ match [ 'modelId' ] ) ; $ resource -> downloads += 1 ; $ resource -> update ( ) ; return new Pluf_HTTP_Response_File ( $ resource -> getAbsloutPath ( ) , $ resource -> mime_type ) ; }
|
Download a resource
|
13,312
|
protected function setValues ( $ data , $ duration ) { $ result = apc_store ( $ data , null , $ duration ) ; return is_array ( $ result ) ? array_keys ( $ result ) : [ ] ; }
|
Stores multiple key - value pairs in cache .
|
13,313
|
protected function addValues ( $ data , $ duration ) { $ result = apc_add ( $ data , null , $ duration ) ; return is_array ( $ result ) ? array_keys ( $ result ) : [ ] ; }
|
Adds multiple key - value pairs to cache .
|
13,314
|
public function build ( $ type , $ data , $ hypertextRoutes = [ ] ) { if ( ! isset ( $ this -> types [ $ type ] ) ) { throw new \ Exception ( "Unknown response type." ) ; } return new $ this -> types [ $ type ] ( $ data , $ hypertextRoutes ) ; }
|
Builds the response object .
|
13,315
|
public function default ( $ key , $ default = null ) { if ( $ this -> has ( $ key ) ) return $ this -> get ( $ key ) ; $ this -> put ( $ key , $ default ) ; return $ default ; }
|
If key is in the collection return its value . If not insert key with the given default as value and return default .
|
13,316
|
public function showTables ( ) { $ sql = 'SHOW TABLES' ; $ query = $ this -> pdo -> prepare ( $ sql ) ; $ query -> execute ( ) ; return $ query -> fetchAll ( PDO :: FETCH_ASSOC ) ; }
|
Run a SHOW TABLES query and return the results
|
13,317
|
public function getAll ( ) { $ fields = implode ( ', ' , $ this -> fields ) ; $ sql = 'SELECT ' . $ fields . ' FROM ' . $ this -> table ; $ query = $ this -> pdo -> prepare ( $ sql ) ; $ query -> execute ( ) ; return $ query -> fetchAll ( PDO :: FETCH_ASSOC ) ; }
|
Run a SELECT all query
|
13,318
|
public function getOneById ( $ id ) { $ id = ( string ) $ id ; $ fields = implode ( ', ' , $ this -> fields ) ; $ sql = 'SELECT ' . $ fields . ' FROM ' . $ this -> table . ' WHERE ' . $ this -> table . '.id = :id' ; $ query = $ this -> pdo -> prepare ( $ sql ) ; $ query -> bindParam ( ':id' , $ id ) ; $ query -> execute ( ) ; return $ query -> fetch ( PDO :: FETCH_ASSOC ) ; }
|
Run a SELECT query by ID
|
13,319
|
public function insert ( array $ values ) : int { $ fields = $ this -> fields ; array_shift ( $ fields ) ; $ sql = 'INSERT INTO `' . $ this -> table . '` (' . implode ( ', ' , $ fields ) . ') VALUES (:' . implode ( ', :' , $ fields ) . ')' ; $ query = $ this -> pdo -> prepare ( $ sql ) ; foreach ( $ values as $ key => & $ value ) { $ query -> bindParam ( ':' . $ fields [ $ key ] , $ value ) ; } $ query -> execute ( ) ; return $ this -> pdo -> lastInsertId ( ) ; }
|
Insert a new record in the database
|
13,320
|
public function deleteById ( $ id ) : int { $ sql = 'DELETE FROM `' . $ this -> table . '` WHERE ' ; if ( is_array ( $ id ) ) { $ i = 0 ; foreach ( $ id as $ _id ) { if ( $ i === 0 ) { $ sql .= ' id=:id' . $ i ; } else { $ sql .= ' OR id=:id' . $ i ; } $ i ++ ; } $ query = $ this -> pdo -> prepare ( $ sql ) ; for ( $ j = 0 ; $ j < 0 ; $ j ++ ) { $ query -> bindParam ( ':id' . $ j , $ id [ $ j ] ) ; } } else { $ sql .= 'id=:id' ; $ query = $ this -> pdo -> prepare ( $ sql ) ; $ query -> bindParam ( ':id' , $ id ) ; } $ query -> execute ( ) ; return $ query -> rowCount ( ) ; }
|
Run a DELETE query
|
13,321
|
public function readFile ( string $ file_name ) { $ reader = new XMLReader ; $ reader -> open ( $ file_name ) ; $ data = $ this -> toArray ( $ reader ) ; $ reader -> close ( ) ; return $ data ; }
|
Read a XML file into an array
|
13,322
|
public function readString ( string $ data ) { $ reader = new XMLReader ; $ reader -> XML ( $ data ) ; $ contents = $ this -> toArray ( $ reader ) ; $ reader -> close ( ) ; return $ contents ; }
|
Read XML Data from a string
|
13,323
|
public function parseTree ( XMLReader $ reader ) { libxml_use_internal_errors ( true ) ; $ root = new XMLNode ; $ cur = null ; $ read_anything = false ; while ( $ reader -> read ( ) ) { $ read_anything = true ; if ( $ reader -> nodeType === XMLReader :: ELEMENT ) { if ( $ cur === null ) { $ root -> name = $ reader -> name ; $ cur = $ root ; } else { $ node = new XMLNode ; $ node -> name = $ reader -> name ; $ node -> parent = $ cur ; $ cur -> children [ ] = $ node ; $ cur = $ node ; } if ( $ reader -> hasAttributes ) { while ( $ reader -> moveToNextAttribute ( ) ) { $ node = new XMLNode ; $ node -> name = $ reader -> name ; $ node -> content = $ reader -> value ; $ cur -> attributes [ ] = $ node ; } } } else if ( $ reader -> nodeType === XMLReader :: END_ELEMENT ) { $ cur = $ cur -> parent ; } else if ( $ reader -> nodeType === XMLReader :: TEXT ) { $ cur -> content = $ reader -> value ; } } try { foreach ( libxml_get_errors ( ) as $ error ) throw new XMLException ( $ error ) ; } finally { libxml_clear_errors ( ) ; } return $ root ; }
|
Parse the XML into an array . This will add all nodes and attributes to a tree of XML nodes . This is only basic XML flattening for full - blown XML support be sure to use a more fully featured solution like SimpleXML
|
13,324
|
public function init ( ) { $ this -> setImport ( array ( 'api.models.*' , 'api.components.*' , ) ) ; $ this -> layout = false ; foreach ( Yii :: app ( ) -> log -> routes as $ k => $ v ) { if ( get_class ( $ v ) == 'CWebLogRoute' || get_class ( $ v ) == "CProfileLogRoute" ) Yii :: app ( ) -> log -> routes [ $ k ] -> enabled = false ; } Yii :: app ( ) -> setComponents ( array ( 'errorHandler' => array ( 'errorAction' => 'api/default/error' , ) , 'messages' => array ( 'class' => 'cii.components.CiiPHPMessageSource' , 'basePath' => Yii :: getPathOfAlias ( 'application.modules.api' ) ) ) ) ; }
|
Yii Init method Implements basic configuration for module
|
13,325
|
public function call ( ) { if ( false === $ this -> shouldAuthenticate ( ) ) { $ this -> next -> call ( ) ; return ; } $ this -> checkSecure ( ) ; $ freePass = $ this -> hasFreePass ( ) ; if ( ( false === $ this -> data = $ this -> fetchData ( ) ) && ! $ freePass ) { $ this -> callError ( ) ; return ; } if ( false === $ this -> data && $ freePass ) { $ this -> next -> call ( ) ; return ; } $ authenticator = $ this -> options [ "authenticator" ] ; if ( false === $ authenticator ( $ this -> data ) ) { $ this -> error = $ authenticator -> getError ( ) ; $ this -> callError ( ) ; return ; } $ this -> app -> userData = $ authenticator -> getData ( ) ; if ( ! $ this -> customValidation ( ) ) { $ this -> callError ( ) ; return ; } if ( is_callable ( $ this -> options [ "callback" ] ) ) { $ params = $ this -> getParams ( ) ; if ( false === $ this -> options [ "callback" ] ( $ params ) ) { $ this -> error = new Error ( ) ; $ this -> error -> setDescription ( "Callback returned false" ) ; $ this -> callError ( ) ; return ; } } $ this -> next -> call ( ) ; }
|
Call the middleware
|
13,326
|
private function checkSecure ( ) { $ environment = $ this -> app -> environment ; $ scheme = $ environment [ "slim.url_scheme" ] ; if ( "https" !== $ scheme && true === $ this -> options [ "secure" ] ) { if ( ! in_array ( $ environment [ "SERVER_NAME" ] , $ this -> options [ "relaxed" ] ) ) { $ message = sprintf ( "Insecure use of middleware over %s denied by configuration." , strtoupper ( $ scheme ) ) ; throw new \ RuntimeException ( $ message ) ; } } }
|
HTTP allowed only if secure is false or server is in relaxed array .
|
13,327
|
private function hydrate ( $ data = array ( ) ) { foreach ( $ data as $ key => $ value ) { $ method = "set" . ucfirst ( $ key ) ; if ( method_exists ( $ this , $ method ) ) { call_user_func ( array ( $ this , $ method ) , $ value ) ; } } }
|
Hydate options from given array
|
13,328
|
public function callError ( ) { if ( ! ( $ this -> error instanceof Error ) ) { $ this -> error = new Error ( ) ; } $ status = $ this -> error -> getStatus ( ) ; $ this -> app -> response -> status ( $ status ) ; if ( is_callable ( $ this -> options [ "error" ] ) ) { $ this -> options [ "error" ] ( $ this -> error ) ; } }
|
Call the error handler if it exists
|
13,329
|
public function setRules ( array $ rules ) { unset ( $ this -> rules ) ; $ this -> rules = new \ SplStack ; foreach ( $ rules as $ callable ) { $ this -> addRule ( $ callable ) ; } return $ this ; }
|
Set all rules in the stack
|
13,330
|
public function add ( string $ key , $ value , bool $ override = false ) { if ( ! $ override && $ this -> exists ( $ key ) ) { return ; } $ this -> parameters [ $ key ] = $ value ; }
|
Add a parameter to the bag
|
13,331
|
public function start ( ) { $ modules = ModuleModel :: where ( 'module_status' , 1 ) -> get ( ) ; foreach ( $ modules as $ module ) { $ path = $ this -> getModuleDirectory ( $ module -> module_name ) ; if ( $ path ) { $ name = $ module -> module_name ; $ this -> modules [ $ name ] = new Module ( $ this -> app , $ module -> module_name , $ path ) ; } } }
|
Get all module from database and initialize
|
13,332
|
public function register ( ) { foreach ( $ this -> modules as $ module ) { $ module -> register ( ) ; } $ modules = ModuleModel :: where ( 'module_status' , 1 ) -> get ( ) ; foreach ( $ modules as $ module ) { if ( $ module -> module_is_installed ) { $ this -> app [ 'events' ] -> fire ( 'modules.install.' . $ module -> module_name , null ) ; $ module -> module_is_installed = 0 ; } if ( $ module -> module_is_updated ) { $ this -> app [ 'events' ] -> fire ( 'modules.update.' . $ module -> module_name , null ) ; $ module -> module_is_updated = 0 ; } if ( $ module -> module_is_enabled ) { $ this -> app [ 'events' ] -> fire ( 'modules.enable.' . $ module -> module_name , null ) ; $ module -> module_is_enabled = 0 ; } $ module -> save ( ) ; } }
|
Register modules with Moduel class
|
13,333
|
public function enable ( $ moduleName ) { $ module = $ this -> findOrFalse ( 'module_name' , $ moduleName ) ; if ( $ module ) { if ( ! $ module -> module_status ) { $ module -> module_status = 1 ; $ module -> module_is_enabled = 1 ; $ module -> save ( ) ; return true ; } return false ; } return false ; }
|
Enable module to load
|
13,334
|
protected function getListModules ( $ modulesModel ) { $ modules = array ( ) ; foreach ( $ modulesModel as $ module ) { $ modules [ $ module -> module_name ] [ 'name' ] = $ this -> def ( $ module -> module_name , 'name' ) ; $ modules [ $ module -> module_name ] [ 'icon' ] = $ this -> getConfig ( 'assets' ) . '/' . $ module -> module_name . '/' . $ this -> def ( $ module -> module_name , 'icon' ) ; $ modules [ $ module -> module_name ] [ 'description' ] = $ this -> def ( $ module -> module_name , 'description' ) ; $ modules [ $ module -> module_name ] [ 'author' ] = $ this -> def ( $ module -> module_name , 'author' ) ; $ modules [ $ module -> module_name ] [ 'website' ] = $ this -> def ( $ module -> module_name , 'website' ) ; $ modules [ $ module -> module_name ] [ 'version' ] = $ this -> def ( $ module -> module_name , 'version' ) ; } return $ modules ; }
|
Get list modules
|
13,335
|
public function buildAssets ( $ moduleName ) { $ module = $ this -> getModuleDirectory ( $ moduleName ) ; if ( $ module ) { $ module .= '/assets' ; if ( $ this -> files -> exists ( $ module ) ) { if ( ! @ $ this -> files -> copyDirectory ( $ module , $ this -> getAssetDirectory ( $ moduleName ) ) ) { $ this -> errors -> add ( 'build_assets' , 'Unable to build assets' ) ; return false ; } } return true ; } return false ; }
|
Move contents assets module to public directory
|
13,336
|
public function removeAssets ( $ moduleName ) { $ assets = $ this -> getAssetDirectory ( $ moduleName ) ; $ this -> files -> deleteDirectory ( $ assets ) ; if ( $ this -> files -> exists ( $ assets ) ) { $ this -> errors -> add ( 'delete_assets' , 'Unable to delete assets in: ' . $ assets ) ; return false ; } return true ; }
|
Remove assets of a module
|
13,337
|
protected function removeModuleDirectory ( $ moduleName ) { $ this -> files -> deleteDirectory ( $ this -> getModuleDirectory ( $ moduleName ) ) ; if ( $ this -> files -> exists ( $ this -> getModuleDirectory ( $ moduleName ) ) ) { $ this -> errors -> add ( 'delete_files' , 'Unable to delete ' . $ this -> getModuleDirectory ( $ moduleName ) ) ; return false ; } return true ; }
|
Remove module directory
|
13,338
|
protected function sysVersionDependency ( $ version ) { $ sysVersion = new Version ( $ this -> sysMajorVersion . '.' . $ this -> sysMinorVersion . '.' . $ this -> sysPathVersion ) ; $ needVersion = new Version ( $ version ) ; if ( ! $ sysVersion -> isPartOf ( $ needVersion ) ) { $ this -> errors -> add ( 'module_dependency_sys' , 'This module not made for current version of ' . $ this -> systemName . ', made for ' . $ version ) ; return false ; } return false ; }
|
Check system dependency
|
13,339
|
protected function checkDependency ( $ dependencies = null ) { $ errors = array ( ) ; if ( is_null ( $ dependencies ) ) $ dependencies = array ( ) ; $ i = 0 ; $ clean = true ; foreach ( $ dependencies as $ module => $ version ) { if ( $ module == $ this -> systemName ) { if ( ! $ this -> sysVersionDependency ( $ version ) ) $ clean = false ; continue ; } $ depModule = ModuleModel :: where ( 'module_name' , $ module ) -> first ( ) ; if ( ! $ depModule ) { $ this -> errors -> add ( "module_dependency_$i" , "Module $module with version $version not installed" ) ; $ clean = false ; } else { $ depVersion = $ depModule -> module_version ; $ needVersion = $ version ; $ depVersion = new Version ( $ depVersion ) ; $ needVersion = new Version ( $ needVersion ) ; if ( ! $ depVersion -> isPartOf ( $ needVersion ) ) { $ this -> errors -> add ( "module_dependency_$i" , 'Module ' . $ module . ' v' . $ needVersion -> getVersion ( ) . ' must install, but ' . $ depVersion -> getVersion ( ) . ' installed.' ) ; $ clean = false ; } } $ i ++ ; } if ( ! $ clean ) return false ; return true ; }
|
Check module dependencies
|
13,340
|
public function uninstall ( $ moduleName ) { $ module = $ this -> findOrFalse ( 'module_name' , $ moduleName ) ; if ( $ module ) { $ version = $ this -> def ( $ moduleName , 'version' ) ; if ( $ this -> checkModuleDepends ( $ moduleName , new Version ( $ version ) ) ) return false ; $ this -> app [ 'events' ] -> fire ( 'modules.uninstall.' . $ moduleName , null ) ; $ module -> delete ( ) ; if ( ! $ this -> removeAssets ( $ moduleName ) ) $ this -> errors -> add ( 'delete_assets' , "Unable to delete assets $moduleName" ) ; if ( ! $ this -> removeModuleDirectory ( $ moduleName ) ) $ this -> errors -> add ( 'delete_module' , "Unable to delete $moduleName" ) ; return true ; } return false ; }
|
Uninstall module and remove assets
|
13,341
|
public function install ( $ tempPath , $ moduleName ) { $ moduleDependency = $ this -> def ( $ tempPath , 'require' , true ) ; if ( ! $ moduleDependency = $ this -> checkDependency ( $ moduleDependency ) ) return false ; if ( ! $ this -> files -> copyDirectory ( $ tempPath , $ this -> path . '/' . $ moduleName ) ) { $ this -> errors -> add ( 'move_files_permission_denied' , 'Permission denied in: ' . $ this -> path . '/' . $ moduleName ) ; return false ; } $ this -> buildAssets ( $ moduleName ) ; if ( ! $ this -> registerModule ( $ moduleName ) ) { $ this -> errors -> add ( 'register_module' , 'Error in register module' ) ; return false ; } return true ; }
|
Install module and build assets
|
13,342
|
protected function updateRegisteredModule ( $ moduleName ) { $ module = $ this -> findOrFalse ( 'module_name' , $ moduleName ) ; $ module -> module_version = $ this -> def ( $ moduleName , 'version' ) ; $ module -> module_is_updated = 1 ; $ module -> save ( ) ; }
|
Update metadate of module updated
|
13,343
|
public function zipInit ( $ archive , $ callback = null ) { $ tempPath = $ this -> getAssetDirectory ( ) . '/#tmp/' . uniqid ( ) ; $ result = $ this -> traceZip ( $ archive , $ tempPath ) ; $ this -> files -> deleteDirectory ( $ tempPath ) ; if ( ! is_null ( $ callback ) ) call_user_func ( $ callback , $ result [ 0 ] , $ result [ 1 ] ) ; return $ result [ 0 ] ; }
|
Initialize zip module
|
13,344
|
protected function traceZip ( $ archive , $ tempPath ) { if ( ! $ archive = $ this -> extractZip ( $ archive , $ tempPath , true ) ) return array ( false , null ) ; if ( ! $ this -> checkRequires ( $ tempPath ) ) return array ( false , null ) ; $ moduleName = $ this -> def ( $ tempPath , 'name' , true ) ; if ( $ this -> moduleExists ( $ moduleName ) ) return array ( $ this -> update ( $ tempPath , $ moduleName ) , $ moduleName ) ; else return array ( $ this -> install ( $ tempPath , $ moduleName ) , $ moduleName ) ; }
|
Step by Step to install or update a module zip
|
13,345
|
protected function checkRequires ( $ modulePath ) { $ requires = $ this -> getConfig ( 'requires' , array ( ) ) ; foreach ( $ requires as $ key => $ value ) { if ( is_array ( $ value ) ) { if ( ! $ this -> files -> exists ( $ modulePath . '/' . $ key ) ) { $ this -> errors -> add ( $ this -> configFile , $ this -> configFile . ' is corrupted.' ) ; return false ; } $ jsonFile = json_decode ( $ this -> app [ 'files' ] -> get ( $ modulePath . '/' . $ key ) , true ) ; foreach ( $ value as $ key ) { if ( is_array ( $ jsonFile ) ) { if ( ! array_key_exists ( $ key , $ jsonFile ) || empty ( $ jsonFile [ $ key ] ) ) { $ this -> errors -> add ( 'module_requires' , 'This module has not requires files' ) ; return false ; } } else { $ this -> errors -> add ( $ this -> configFile , $ this -> configFile . ' is corrupted.' ) ; return false ; } } } else { if ( ! $ this -> files -> exists ( $ modulePath . '/' . $ value ) ) { $ this -> errors -> add ( 'module_requires' , 'This module has not requires files' ) ; return false ; } } } return true ; }
|
Check module has required file
|
13,346
|
public function checkModuleDepends ( $ moduleName , Version $ curVersion , Version $ newVersion = null ) { $ modules = $ this -> getListAllModules ( ) ; $ clean = true ; $ i = 0 ; foreach ( $ modules as $ module ) { $ depends = $ this -> def ( $ module [ 'name' ] , 'require' , false , array ( ) ) ; if ( ! is_array ( $ depends ) ) { $ this -> errors -> add ( $ this -> configFile , $ this -> configFile . ' is corrupted.' ) ; return false ; } if ( array_key_exists ( $ moduleName , $ depends ) ) { if ( ! is_null ( $ newVersion ) ) { $ dependVersion = new Version ( $ depends [ $ moduleName ] ) ; if ( ! $ newVersion -> isPartOf ( $ dependVersion ) ) { $ clean = false ; $ this -> errors -> add ( "module_depend_$i" , "Can not update $moduleName, " . $ module [ 'name' ] . ' Depend to version ' . $ dependVersion -> getOriginalVersion ( ) . ' of ' . $ moduleName ) ; } } else { $ clean = false ; $ this -> errors -> add ( "module_depend_$i" , "Can not uninstall $moduleName, " . $ module [ 'name' ] . ' Depend this module.' ) ; } } $ i ++ ; } if ( ! $ clean ) return true ; return false ; }
|
Check others modules depends to this module or not when update or delete module
|
13,347
|
protected function extractZip ( $ archive , $ target , $ deleteSource = false ) { if ( ! $ this -> files -> exists ( $ target ) ) { $ this -> files -> makeDirectory ( $ target , 0777 , true ) ; } $ archive = new Pclzip ( $ archive ) ; if ( $ archive -> extract ( PCLZIP_OPT_PATH , $ target ) == 0 ) { $ this -> errors -> add ( 'extract_zip' , $ archive -> error_string ) ; return false ; } if ( $ deleteSource ) $ this -> files -> delete ( $ archive -> zipname ) ; return $ archive ; }
|
Extract zip file
|
13,348
|
public function moduleExists ( $ moduleName , $ returnId = false ) { $ module = $ this -> findOrFalse ( 'module_name' , $ moduleName ) ; if ( $ module ) { if ( $ returnId ) return $ module -> module_id ; else return true ; } return false ; }
|
Check if module exists
|
13,349
|
public function findOrFalse ( $ field , $ name ) { $ module = ModuleModel :: where ( $ field , $ name ) -> first ( ) ; return ! is_null ( $ module ) ? $ module : false ; }
|
Find one record from model
|
13,350
|
public function getModuleDirectory ( $ moduleName ) { if ( $ this -> files -> exists ( $ this -> path . '/' . $ moduleName ) ) return $ this -> path . '/' . $ moduleName ; else return false ; }
|
Get path of specific module
|
13,351
|
public function getAssetDirectory ( $ moduleName = null ) { if ( $ moduleName ) return public_path ( ) . '/' . $ this -> getConfig ( 'assets' ) . '/' . $ moduleName ; return public_path ( ) . '/' . $ this -> getConfig ( 'assets' ) . '/' ; }
|
Get assets path of speciic module
|
13,352
|
public function make ( ) { return new Request ( $ this -> method , $ this -> target , $ this -> server , $ this -> cookies , $ this -> data , $ this -> files , $ this -> queries , $ this -> attributes , $ this -> uri , $ this -> headers , $ this -> stream , $ this -> version ) ; }
|
Creates the request instance .
|
13,353
|
protected function flush ( $ message ) { switch ( $ this -> output ) { case self :: PRINT_AS_OUTPUT : IO :: out ( $ message ) ; break ; case self :: PRINT_AS_MESSAGE : IO :: err ( $ message ) ; break ; } }
|
Print message to STDOUT or STDERR
|
13,354
|
public function setOrderBy ( $ field , $ direction = null ) { if ( empty ( $ field ) ) return $ this ; if ( count ( $ order = explode ( ' ' , $ field ) ) == 2 ) { $ field = $ order [ 0 ] ; $ direction = $ order [ 1 ] ; } $ this -> orderBy [ $ field ] = empty ( $ direction ) ? 'ASC' : $ direction ; return $ this ; }
|
Sets the specified orderBy
|
13,355
|
public function getOrderBy ( $ field ) { return array_key_exists ( $ field , $ this -> orderBy ) ? $ this -> orderBy [ $ field ] : null ; }
|
Returns the OrderBy direction for the field specified
|
13,356
|
public function setOffset ( $ offset ) { if ( $ offset >= PHP_INT_MAX ) { $ offset = false ; } $ this -> offset = $ offset ; return $ this ; }
|
Sets the offset
|
13,357
|
public function getResultsAsObjects ( $ classname ) { $ new = array ( ) ; foreach ( ( array ) $ this -> results as $ result ) { if ( is_array ( $ result ) ) $ new [ ] = new $ classname ( $ result ) ; else $ new [ ] = $ result ; } return $ new ; }
|
Returns all the results as objects of the class specified
|
13,358
|
public function getResultsAsArray ( ) { $ new = array ( ) ; foreach ( ( array ) $ this -> results as $ result ) { if ( $ result instanceof Object ) $ new [ ] = $ result -> toArray ( ) ; else if ( is_array ( $ result ) ) return $ this -> results ; else throw new Exception ( 'Cannot convert to array: ' . ClassUtils :: getQualifiedType ( $ result ) ) ; } return $ new ; }
|
Returns all results as an array
|
13,359
|
public function getColumnOfResults ( $ col ) { $ new = array ( ) ; foreach ( ( array ) $ this -> results as $ result ) { if ( $ result instanceof Object ) $ new [ ] = $ result -> $ col ; else if ( is_array ( $ result ) ) $ new [ ] = $ result [ $ col ] ; } return $ new ; }
|
Returns an array containing the value stored in the column specifed for each result
|
13,360
|
public function isRetrieveAsObjects ( $ val = null ) { if ( ! is_null ( $ val ) ) { $ this -> retrieveAsObjects = $ val ; return $ this ; } return $ this -> retrieveAsObjects == true ; }
|
Determines if the DTO will retrieve the results as objects . Also acts as a setter for retrieve as objects
|
13,361
|
public function isRetrieveTotalRecords ( $ val = null ) { if ( ! is_null ( $ val ) ) { $ this -> retrieveTotalRecords = $ val ; return $ this ; } return $ this -> retrieveTotalRecords ; }
|
Determines if the DTO will retrieve a count of total records for the results Also acts as a setter for retrieve total records
|
13,362
|
protected function extractAuthParameters ( $ pattern , $ channel , $ callback ) { $ callbackParameters = ( new ReflectionFunction ( $ callback ) ) -> getParameters ( ) ; return collect ( $ this -> extractChannelKeys ( $ pattern , $ channel ) ) -> reject ( function ( $ value , $ key ) { return is_numeric ( $ key ) ; } ) -> map ( function ( $ value , $ key ) use ( $ callbackParameters ) { return $ this -> resolveBinding ( $ key , $ value , $ callbackParameters ) ; } ) -> values ( ) -> all ( ) ; }
|
Extract the parameters from the given pattern and channel .
|
13,363
|
public function bootPermissions ( ) { foreach ( $ this -> permissions as $ token => $ permission ) { $ this -> permissions [ $ token ] = sprintf ( $ permission , Str :: kebab ( $ this -> getManager ( ) -> getName ( ) ) , Str :: kebab ( $ this -> getName ( ) ) ) ; } }
|
Boot permissions .
|
13,364
|
public function newException ( string $ code , $ value ) : Exception { $ exception = $ this -> getException ( $ code ) ; return new $ exception ( strtoupper ( Str :: kebab ( $ this -> getManager ( ) -> getName ( ) ) ) , strtoupper ( Str :: kebab ( $ this -> getName ( ) ) ) , $ value ) ; }
|
Create a new instance of exception .
|
13,365
|
private function createRootFolders ( OutputInterface $ output ) { $ em = $ this -> container -> get ( 'doctrine.orm.default_entity_manager' ) ; $ repository = $ this -> container -> get ( 'ekyna_media.folder.repository' ) ; $ name = FolderInterface :: ROOT ; $ output -> write ( sprintf ( '- <comment>%s</comment> %s ' , ucfirst ( $ name ) , str_pad ( '.' , 44 - mb_strlen ( $ name ) , '.' , STR_PAD_LEFT ) ) ) ; if ( null !== $ folder = $ repository -> findRoot ( ) ) { $ output -> writeln ( 'already exists.' ) ; } else { $ folder = new Folder ( ) ; $ folder -> setName ( $ name ) ; $ em -> persist ( $ folder ) ; $ em -> flush ( ) ; $ output -> writeln ( 'created.' ) ; } }
|
Creates root folders .
|
13,366
|
public function addVariety ( \ Librinfo \ VarietiesBundle \ Entity \ Variety $ variety ) { $ this -> varieties [ ] = $ variety ; return $ this ; }
|
Add variety .
|
13,367
|
public function removeVariety ( \ Librinfo \ VarietiesBundle \ Entity \ Variety $ variety ) { return $ this -> varieties -> removeElement ( $ variety ) ; }
|
Remove variety .
|
13,368
|
public function addSpecies ( \ Librinfo \ VarietiesBundle \ Entity \ Species $ species ) { $ this -> species [ ] = $ species ; return $ this ; }
|
Add species .
|
13,369
|
function synchronize ( ) { $ tCounter = 0 ; if ( $ this -> changed ) { $ tFile = fopen ( $ this -> fileName , 'a' ) ; while ( ! flock ( $ tFile , LOCK_EX ) ) { usleep ( 5 ) ; $ tCounter ++ ; if ( $ tCounter == 100 ) { return false ; } } $ tContent = serialize ( $ this -> elements ) ; ftruncate ( $ tFile , 0 ) ; if ( $ this -> useZip ) { $ tContent = gzcompress ( $ tContent ) ; } fputs ( $ tFile , $ tContent ) ; flock ( $ tFile , LOCK_UN ) ; fclose ( $ tFile ) ; return true ; } return true ; }
|
Synchronize cache with file
|
13,370
|
function check ( CacheKey $ key ) { if ( isset ( $ this -> elements [ $ key -> getModule ( ) ] [ $ key -> getProperty ( ) ] ) ) { return true ; } else { return false ; } }
|
Check is cache entry is set
|
13,371
|
public function get ( CacheKey $ key ) { if ( ! empty ( $ this -> elements [ $ key -> getModule ( ) ] [ $ key -> getProperty ( ) ] ) ) { $ tValue = $ this -> elements [ $ key -> getModule ( ) ] [ $ key -> getProperty ( ) ] -> getValue ( ) ; return $ tValue ; } else { return false ; } }
|
Get value from cache or null when not set
|
13,372
|
public function clear ( CacheKey $ key ) { if ( isset ( $ this -> elements [ $ key -> getModule ( ) ] [ $ key -> getProperty ( ) ] ) ) { unset ( $ this -> elements [ $ key -> getModule ( ) ] [ $ key -> getProperty ( ) ] ) ; $ this -> changed = true ; } }
|
Unset cache value
|
13,373
|
function clearModule ( CacheKey $ key ) { if ( isset ( $ this -> elements [ $ key -> getModule ( ) ] ) ) { unset ( $ this -> elements [ $ key -> getModule ( ) ] ) ; $ this -> changed = true ; } }
|
Clear whole module and all it s properties
|
13,374
|
public function process ( $ data ) { $ featuredImageProcessing = [ ] ; $ useFeaturedImageUrl = $ this -> isFieldValueBlank ( $ data [ 'featured_image_url' ] ) ; if ( ( $ useFeaturedImageUrl ) && ( $ this -> validateFeaturedImageUrl ( $ data [ 'featured_image_url' ] ) != "passed" ) ) { $ featuredImageProcessing [ 'validationMessage' ] = $ this -> validateFeaturedImageUrl ( $ data [ 'featured_image_url' ] ) ; return $ featuredImageProcessing ; } if ( $ useFeaturedImageUrl ) { $ featuredImageProcessing [ 'validationMessage' ] = "passed" ; $ featuredImageProcessing [ 'featured_image' ] = $ data [ 'featured_image_url' ] ; return $ featuredImageProcessing ; } $ useFeaturedImageUpload = $ this -> isFieldValueBlank ( $ data [ 'featured_image_upload' ] ) ; if ( ( $ useFeaturedImageUpload ) && ( $ this -> validateFeaturedImageUpload ( $ data [ 'featured_image_upload' ] ) != "passed" ) ) { $ featuredImageProcessing [ 'validationMessage' ] = $ this -> validateFeaturedImageUpload ( $ data [ 'featured_image_upload' ] ) ; return $ featuredImageProcessing ; } if ( $ useFeaturedImageUpload ) { $ this -> moveFile ( $ data [ 'featured_image_upload' ] ) ; $ featuredImageProcessing [ 'validationMessage' ] = "passed" ; $ featuredImageProcessing [ 'featured_image' ] = $ data [ 'featured_image_upload' ] ; return $ featuredImageProcessing ; } if ( $ this -> validateFeaturedImageServer ( $ data [ 'featured_image_server' ] ) != "passed" ) { $ featuredImageProcessing [ 'validationMessage' ] = $ this -> validateFeaturedImageServer ( $ data [ 'featured_image_server' ] ) ; return $ featuredImageProcessing ; } $ featuredImageProcessing [ 'validationMessage' ] = "passed" ; $ featuredImageProcessing [ 'featured_image' ] = $ data [ 'featured_image_server' ] ; return $ featuredImageProcessing ; }
|
Main featured image processing
|
13,375
|
public function validateFeaturedImageUpload ( $ featuredImageUpload ) { if ( ! $ this -> isImageFileExtensionKosher ( $ featuredImageUpload ) ) { return "Your uploaded image file, " . $ featuredImageUpload . ", is not an accepted image file type." ; } if ( $ this -> doesImageFileExistOnServer ( $ featuredImageUpload ) ) { return "Your uploaded image file, " . $ featuredImageUpload . ", already exists on the server." ; } if ( ! \ Input :: file ( 'featured_image_upload' ) -> isValid ( ) ) { return "There were problems uploading your image file, " . $ featuredImageUpload . "." ; } return "passed" ; }
|
Validate the featured_image_upload field s data
|
13,376
|
public function validateFeaturedImageServer ( $ featuredImageServer ) { if ( ( ! $ featuredImageServer ) || ( $ featuredImageServer == "" ) ) { return "passed" ; } if ( ! $ this -> isImageFileExtensionKosher ( $ featuredImageServer ) ) { return "The image file you selected on your server, " . $ featuredImageServer . ", is not an accepted image file type." ; } if ( ! $ this -> doesImageFileExistOnServer ( $ featuredImageServer ) ) { return "The image file you selected on your server, " . $ featuredImageServer . ", does NOT actually exist on the server." ; } return "passed" ; }
|
Validate the featured_image_server field s data
|
13,377
|
public function isImageFileExtensionKosher ( $ filename ) { $ imageFileExtension = $ this -> ImagesHelper -> filenameWithExtensionOnly ( $ filename ) ; $ haystack = Config :: get ( 'lasallecmsfrontend.acceptable_image_extensions_for_uploading' ) ; if ( in_array ( strtolower ( $ imageFileExtension ) , $ haystack ) ) { return true ; } return false ; }
|
Is the image s extension allowed?
|
13,378
|
public function doesImageFileExistOnServer ( $ filename ) { if ( \ File :: exists ( $ this -> ImagesHelper -> pathOfImagesUploadParentFolder ( ) . "/" . Config :: get ( 'lasallecmsfrontend.images_folder_uploaded' ) . '/' . $ filename ) ) { return true ; } return false ; }
|
Does the iamge file exist already on the server?
|
13,379
|
public function moveFile ( $ filename ) { $ destinationPath = $ this -> ImagesHelper -> pathOfImagesUploadParentFolder ( ) . "/" . Config :: get ( 'lasallecmsfrontend.images_folder_uploaded' ) ; \ Input :: file ( 'featured_image_upload' ) -> move ( $ destinationPath , $ filename ) ; }
|
Move the uploaded file from the tmp folder to its proper destination folder
|
13,380
|
public function where ( $ table , $ column , $ keyword ) { $ connection = Connection :: connect ( ) ; $ selectValue = $ connection -> prepare ( 'select * from ' . $ table . ' where ' . $ column . ' = \'' . $ keyword . '\'' ) ; $ selectValue -> execute ( ) ; return $ selectValue -> fetch ( PDO :: FETCH_ASSOC ) ; }
|
Return details where a column is matched by the given keyword
|
13,381
|
protected static function selectAll ( $ model , $ tableName ) { $ connection = Connection :: connect ( ) ; $ getAll = $ connection -> prepare ( 'select * from ' . $ tableName ) ; $ getAll -> execute ( ) ; while ( $ allRows = $ getAll -> fetch ( PDO :: FETCH_ASSOC ) ) { array_push ( $ model -> resultRows , $ allRows ) ; } return $ model ; }
|
Search database for all rows
|
13,382
|
protected static function selectOne ( $ model , $ tableName , $ id ) { $ connection = Connection :: connect ( ) ; $ getAll = $ connection -> prepare ( 'select * from ' . $ tableName . ' where id=' . $ id ) ; $ getAll -> execute ( ) ; $ row = $ getAll -> fetch ( PDO :: FETCH_ASSOC ) ; array_push ( $ model -> resultRows , $ row ) ; return $ model ; }
|
Search database for one row
|
13,383
|
protected function updateRow ( ) { $ tableName = $ this -> getTableName ( $ this -> className ) ; $ assignedValues = $ this -> getAssignedValues ( ) ; $ updateDetails = [ ] ; for ( $ i = 0 ; $ i < count ( $ assignedValues [ 'columns' ] ) ; $ i ++ ) { array_push ( $ updateDetails , $ assignedValues [ 'columns' ] [ $ i ] . ' =\'' . $ assignedValues [ 'values' ] [ $ i ] . '\'' ) ; } $ connection = Connection :: connect ( ) ; $ allUpdates = implode ( ', ' , $ updateDetails ) ; $ update = $ connection -> prepare ( 'update ' . $ tableName . ' set ' . $ allUpdates . ' where id=' . $ this -> resultRows [ 0 ] [ 'id' ] ) ; if ( $ update -> execute ( ) ) { return 'Row updated' ; } else { throw new Exception ( "Unable to update row" ) ; } }
|
Edit an existing row
|
13,384
|
public static function destroy ( $ id ) { if ( self :: confirmIdExists ( $ id ) ) { return self :: doDelete ( $ id ) ; } else { throw new Exception ( 'Now rows found with ID ' . $ id . ' in the database, it may have been already deleted' ) ; } }
|
Call doDelete function if the specified id exists
|
13,385
|
protected static function doDelete ( $ id ) { $ model = self :: createModelInstance ( ) ; $ tableName = $ model -> getTableName ( $ model -> className ) ; $ connection = Connection :: connect ( ) ; $ delete = $ connection -> prepare ( 'delete from ' . $ tableName . ' where id =' . $ id ) ; return $ delete -> execute ( ) ? 'deleted successfully' : 'Row not deleted' ; }
|
Delete an existing row from the database
|
13,386
|
public function generate ( $ actionManager ) { if ( $ actionManager instanceof ActionManagerInterface ) { $ this -> actionManager = $ actionManager ; $ this -> actionManagerClass = get_class ( $ this -> actionManager ) ; } if ( is_string ( $ actionManager ) && class_exists ( $ actionManager ) ) { $ this -> actionManager = new $ actionManager ( ) ; $ this -> actionManagerClass = $ actionManager ; } }
|
Generates the ActionManager object
|
13,387
|
public static function load ( $ file ) { if ( file_exists ( $ file ) ) { $ env = \ M1 \ Env \ Parser :: parse ( file_get_contents ( $ file ) ) ; foreach ( $ env as $ key => $ value ) { putenv ( "{$key}={$value}" ) ; } } }
|
Load file containing environment variables and setup environment with these variables
|
13,388
|
function addForeignKey ( $ table , $ pkname , $ tables ) { if ( is_string ( $ tables ) ) $ tables = array ( $ tables ) ; $ this -> _foreignKeys [ $ table ] = array ( 'primaryKey' => $ pkname , 'tables' => $ tables ) ; }
|
Add some config data for a new foreign key
|
13,389
|
function pdo_query_select ( $ query , $ values = NULL ) { if ( ! is_null ( $ values ) && ! is_array ( $ values ) ) $ values = array ( $ values ) ; $ st = $ this -> prepare ( $ query ) ; $ st -> execute ( $ values ) ; return $ st ; }
|
Helper query method for a SQL SELECT request
|
13,390
|
public function paginate ( ) { $ this -> total = $ this -> dataSource -> getTotal ( $ this -> source ) ; if ( ( $ this -> getPagesCount ( ) > 0 && $ this -> getPage ( ) > $ this -> getPagesCount ( ) ) || $ this -> getPage ( ) <= 0 ) { $ this -> handler -> wrongPageCallback ( ) ; } $ this -> data = $ this -> dataSource -> applyLimit ( $ this -> source , $ this -> getPage ( ) , $ this -> getPageSize ( ) ) ; return $ this -> data ; }
|
Apply limits to source .
|
13,391
|
public function initialize ( $ routepath ) { $ this -> routepath = $ routepath ; Template :: addPath ( __DIR__ . '/templates/' , 'CatLab/Accounts/' ) ; Text :: getInstance ( ) -> addPath ( 'catlab.accounts' , __DIR__ . '/locales/' ) ; Application :: getInstance ( ) -> on ( 'dispatch:before' , array ( $ this , 'setRequestUser' ) ) ; Application :: getInstance ( ) -> on ( 'dispatch:first' , array ( $ this , 'setUserMapper' ) ) ; $ helper = new LoginForm ( $ this ) ; Template :: addHelper ( 'CatLab.Accounts.LoginForm' , $ helper ) ; }
|
Set template paths config vars etc
|
13,392
|
public function setRequestUser ( Request $ request ) { $ request -> addUserCallback ( 'accounts' , function ( Request $ request ) { $ userid = $ request -> getSession ( ) -> get ( 'catlab-user-id' ) ; if ( $ userid ) { $ user = MapperFactory :: getUserMapper ( ) -> getFromId ( $ userid ) ; if ( $ user ) return $ user ; } return null ; } ) ; }
|
Set user from session
|
13,393
|
public function login ( Request $ request , User $ user , $ registration = false ) { if ( $ this -> requiresEmailValidation ( ) ) { if ( ! $ user -> isEmailVerified ( ) ) { $ request -> getSession ( ) -> set ( 'catlab-non-verified-user-id' , $ user -> getId ( ) ) ; return Response :: redirect ( URLBuilder :: getURL ( $ this -> routepath . '/notverified' ) ) ; } } $ request -> getSession ( ) -> set ( 'catlab-user-id' , $ user -> getId ( ) ) ; return $ this -> postLogin ( $ request , $ user , $ registration ) ; }
|
Login a specific user
|
13,394
|
public function postLogin ( Request $ request , \ Neuron \ Interfaces \ Models \ User $ user , $ registered = false ) { $ parameters = array ( ) ; if ( $ registered ) { $ parameters [ 'registered' ] = 1 ; } $ request -> getSession ( ) -> set ( 'userJustRegistered' , $ registered ) ; $ this -> trigger ( 'user:login' , [ 'request' => $ request , 'user' => $ user , 'registered' => $ registered ] ) ; if ( $ request -> getSession ( ) -> get ( 'skip-welcome-redirect' ) ) { $ redirectUrl = $ this -> getAndClearPostLoginRedirect ( $ request ) ; return Response :: redirect ( $ redirectUrl ) ; } return $ this -> redirectToWelcome ( [ ] ) ; }
|
Called right after a user is logged in . Should be a redirect .
|
13,395
|
public function postLogout ( Request $ request ) { if ( $ redirect = $ request -> getSession ( ) -> get ( 'post-login-redirect' ) ) { $ request -> getSession ( ) -> set ( 'post-login-redirect' , null ) ; $ request -> getSession ( ) -> set ( 'cancel-login-redirect' , null ) ; return Response :: redirect ( $ redirect ) ; } return Response :: redirect ( URLBuilder :: getURL ( '/' ) ) ; }
|
Called after a redirect
|
13,396
|
public function setRoutes ( Router $ router ) { $ router -> addFilter ( 'authenticated' , array ( $ this , 'routerVerifier' ) ) ; $ router -> match ( 'GET|POST' , $ this -> routepath . '/login/{authenticator}' , '\CatLab\Accounts\Controllers\LoginController@authenticator' ) ; $ router -> match ( 'GET' , $ this -> routepath . '/login' , '\CatLab\Accounts\Controllers\LoginController@login' ) ; $ router -> match ( 'GET' , $ this -> routepath . '/welcome' , '\CatLab\Accounts\Controllers\LoginController@welcome' ) -> filter ( 'authenticated' ) ; $ router -> match ( 'GET|POST' , $ this -> routepath . '/notverified' , '\CatLab\Accounts\Controllers\LoginController@requiresVerification' ) ; $ router -> match ( 'GET' , $ this -> routepath . '/logout' , '\CatLab\Accounts\Controllers\LoginController@logout' ) ; $ router -> match ( 'GET' , $ this -> routepath . '/cancel' , '\CatLab\Accounts\Controllers\LoginController@cancel' ) ; $ router -> match ( 'GET|POST' , $ this -> routepath . '/register/{authenticator}' , '\CatLab\Accounts\Controllers\RegistrationController@authenticator' ) ; $ router -> match ( 'GET|POST' , $ this -> routepath . '/register' , '\CatLab\Accounts\Controllers\RegistrationController@register' ) ; $ router -> get ( $ this -> routepath . '/verify/{id}' , '\CatLab\Accounts\Controllers\LoginController@verify' ) ; }
|
Register the routes required for this module .
|
13,397
|
public static function asciiRand ( $ length , $ subset = self :: ASCII_ALL ) { switch ( $ subset ) { case self :: ASCII_ALPHANUM : $ subset = self :: $ asciiAlphanum ; break ; case self :: ASCII_NONALPHANUM : $ subset = self :: $ asciNonAlphanum ; break ; default : $ subset = array_merge ( self :: $ asciiAlphanum , self :: $ asciNonAlphanum ) ; } $ count = count ( $ subset ) - 1 ; $ r = '' ; for ( $ i = 0 ; $ i < $ length ; $ i ++ ) { $ r .= $ subset [ mt_rand ( 0 , $ count ) ] ; } return $ r ; }
|
Generates a string of random ASCII characters
|
13,398
|
public static function getUniqid ( $ hash = 'sha256' , $ prefix = '' , $ entropy = 10000 , $ rawOutput = false ) { $ str = mt_rand ( ~ PHP_INT_MAX , PHP_INT_MAX ) . json_encode ( [ $ _COOKIE , $ _REQUEST , $ _FILES , $ _ENV , $ _GET , $ _POST , $ _SERVER ] ) . uniqid ( $ prefix , true ) . self :: asciiRand ( $ entropy , self :: ASCII_ALL ) ; if ( function_exists ( '\openssl_random_pseudo_bytes' ) ) { $ algoStrong = null ; $ str .= \ openssl_random_pseudo_bytes ( $ entropy , $ algoStrong ) ; if ( $ algoStrong !== true ) { trigger_error ( 'Please update your openssl & PHP libraries. openssl_random_pseudo_bytes was unable' . ' to locate a cryptographically strong algorithm.' , E_USER_WARNING ) ; } } else { trigger_error ( 'The openssl extension is not enabled, therefore the unique ID is not ' . 'cryptographically secure.' , E_USER_WARNING ) ; } return hash ( $ hash , $ str , $ rawOutput ) ; }
|
Generates a unique identifier
|
13,399
|
public static function getFingerprint ( $ hashAlgo = 'sha256' ) { return hash ( $ hashAlgo , '#QramRAN7*s%6n%@x*53jVVPsnrz@5MY$49o^mhJ8HqY%3a09yJnSWg9lBl$O4CKUb&&S%EgYBjhUZEbhquw$keCjR6I%zMcA!Qr' . self :: get ( $ _SERVER [ 'HTTP_USER_AGENT' ] ) . 'OE2%fWaZh4jfZPiNXKmHfUw6ok6Z0s#PInaFa8&o#xh#nVyaFaXHPUcv^2y579PnYr5AOs6Zqb!QTAZCgRR968*%QxKc^XNuYYM8' . self :: get ( $ _SERVER [ 'HTTP_DNT' ] ) . '%CwyJJ^GAooDl&o0mc%7zbWlD^6tWoNSN&m3cKxWLP8kiBqO!j2PM5wACzyOoa^t7AEJ#FlDT!BMtD$luy%2iZejMVzktaiftpg*' . self :: get ( $ _SERVER [ 'HTTP_ACCEPT_LANGUAGE' ] ) . 'tep!uTwVXk1CedJq0osEI7p&XCxnC3ipGDWEpTXULEg8J!K1NJSxe4GPor$R3OOb**ZjzPN$$SOHe4ZDcQWQULdtT&XxP2!YYxZy' ) ; }
|
Returns a hashed browser fingerprint
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.