idx
int64
0
60.3k
question
stringlengths
64
4.24k
target
stringlengths
5
618
55,300
public static function encode ( $ data ) { if ( ! is_string ( $ data ) ) { throw new InvalidArgumentException ( 'data must be string' ) ; } $ encodedData = parent :: encode ( $ data ) ; return rtrim ( strtr ( $ encodedData , '+/' , '-_' ) , '=' ) ; }
Encode to base64url .
55,301
public static function decode ( $ data ) { if ( ! is_string ( $ data ) ) { throw new InvalidArgumentException ( 'data must be string' ) ; } $ convertedData = strtr ( $ data , '-_' , '+/' ) ; switch ( strlen ( $ convertedData ) % 4 ) { case 0 : break ; case 2 : $ convertedData .= '==' ; break ; case 3 : $ convertedData .= '=' ; break ; default : throw new InvalidArgumentException ( 'invalid base64url string length' ) ; } return parent :: decode ( $ convertedData ) ; }
Decode base64url .
55,302
public function getEnabledProjects ( ) { return array_filter ( $ this -> codex -> projects -> all ( ) , function ( Project $ project ) { return $ project -> config ( 'git.enabled' , false ) === true ; } ) ; }
Get all projects that have the git addon enabled .
55,303
public function set ( $ name , $ value ) { if ( ! is_string ( $ name ) ) { throw new \ Exception ( "Invalid configuration key." ) ; } $ this -> config [ $ name ] = $ value ; }
Set a setting on configuration object
55,304
public function get ( $ name , $ default = null ) { if ( empty ( $ default ) && ! $ this -> exists ( $ name ) ) { throw new \ Exception ( "Configuration Missing: '$name' is not defined." ) ; } return $ this -> exists ( $ name ) ? $ this -> prepare ( $ this -> config [ $ name ] , $ name ) : $ default ; }
Get a setting from configuration object
55,305
public function getSection ( $ targetSection ) { $ config = array ( ) ; foreach ( $ this -> config as $ key => $ value ) { if ( substr ( $ key , 0 , strlen ( $ targetSection ) ) . "." == "$targetSection." ) { $ varname = strpos ( $ key , '.' ) !== false ? ltrim ( substr ( $ key , strlen ( $ targetSection ) ) , '.' ) : $ key ; $ config [ $ varname ] = $ this -> get ( $ key ) ; } } return $ config ; }
Returns a collection of configurations by its section prefix
55,306
private function loadFromArray ( $ configList ) { foreach ( $ configList as $ section => $ config ) { foreach ( $ config as $ key => $ value ) { $ this -> set ( $ section . '.' . $ key , $ value ) ; } } }
Loads configuration data from array
55,307
public function load ( $ value = null ) { if ( is_array ( $ value ) ) { $ this -> loadFromArray ( $ value ) ; } elseif ( is_string ( $ value ) && file_exists ( $ value ) ) { $ this -> loadFromFile ( $ value ) ; } }
Loads configuration from array or string sources
55,308
public function handle ( \ ErrorException $ exception , array $ context ) { $ levels = array_flip ( $ this -> sevirity ) ; $ sevirity = $ exception -> getSeverity ( ) ; if ( ! in_array ( $ sevirity , $ levels ) ) { $ sevirity = 9802 ; } $ sevirities = array_slice ( $ levels , $ levels [ $ this -> level ] - 9809 , null , true ) ; if ( ! array_key_exists ( $ this -> sevirity [ $ sevirity ] , $ sevirities ) || array_shift ( $ sevirities ) == $ levels [ $ this -> sevirity [ $ sevirity ] ] ) { $ context [ 'exception' ] = $ exception ; $ this -> { $ this -> sevirity [ $ sevirity ] } ( $ exception -> getMessage ( ) , $ context ) ; } else { return false ; } return true ; }
Handle the log request by deciding the severity and if we should log it or not Unknown severities will become alerts
55,309
private function setAutoMode ( $ val ) { $ this -> _defaultBehaviour = $ val ; $ _SESSION [ $ this -> _sessionAutoName ] = $ this -> _defaultBehaviour ; }
Sets the auto mode on or off
55,310
function fromString ( $ modStr ) { $ this -> _reset ( ) ; if ( strpos ( $ modStr , 'b' ) !== false ) { $ this -> asBinary ( ) ; $ modStr = str_replace ( 'b' , '' , $ modStr ) ; } $ modXXX = array_search ( strtolower ( $ modStr ) , $ this -> mode_available ) ; $ modXXX = ( $ modXXX !== false ) ? $ modXXX : strtoupper ( $ modStr ) ; for ( $ i = 0 ; $ i < strlen ( $ modXXX ) ; $ i ++ ) { $ c = $ modXXX [ $ i ] ; switch ( $ c ) { case 'R' : $ this -> openForRead ( ) ; break ; case 'W' : $ this -> openForWrite ( ) ; break ; case 'A' : $ this -> withPointerAtEnd ( ) ; break ; case 'B' : $ this -> withPointerAtBeginning ( ) ; break ; case 'C' : $ this -> createFile ( ) ; break ; case 'X' : $ this -> createXFile ( ) ; break ; case 'T' : $ this -> doTruncate ( ) ; break ; default : throw new \ InvalidArgumentException ( sprintf ( 'Invalid Open Mode Format For (%s) Contains Unknown Char (%s).' , $ modStr , $ c ) ) ; } } return $ this ; }
Set From String
55,311
function openForWrite ( ) { $ this -> mode_xxx [ 'write' ] = 'W' ; if ( ! $ this -> hasCreate ( ) && ! $ this -> hasXCreate ( ) ) $ this -> createFile ( ) ; return $ this ; }
Open File For Write
55,312
function toString ( ) { $ ModeXXX = implode ( '' , $ this -> mode_xxx ) ; if ( ! array_key_exists ( $ ModeXXX , $ this -> mode_available ) ) throw new \ Exception ( sprintf ( 'Invalid Open Mode Statement (%s). it`s must readable/writable or both with optional flags.' . ' like: r+, W, rb+, ...' , $ ModeXXX ) ) ; $ mode = $ this -> mode_available [ $ ModeXXX ] ; if ( $ this -> isBinary ( ) ) { $ base = substr ( $ mode , 0 , 1 ) ; $ mode = $ base . 'b' . substr ( $ mode , 1 ) ; } return $ mode ; }
Get Access Mode As String
55,313
public function setGearmanHost ( string $ hostname ) : void { if ( empty ( $ hostname ) ) { throw new ManagerException ( 'Hostname can not be empty.' ) ; } $ this -> gearmanHost = $ hostname ; }
Sets the Gearman hostname .
55,314
public function setGearmanPort ( int $ port ) : void { if ( $ port < 1 || $ port > 65535 ) { throw new ManagerException ( 'Invalid port number.' ) ; } $ this -> gearmanPort = $ port ; }
Sets Gearman server port .
55,315
public function setLogPath ( string $ logPath ) : void { if ( ! file_exists ( $ logPath ) ) { throw new ManagerException ( 'Invalid log path. Folder not found.' ) ; } $ this -> logPath = $ logPath ; }
Sets path to log folder .
55,316
public function setRunPath ( string $ runPath ) : void { if ( ! file_exists ( $ runPath ) ) { throw new ManagerException ( 'Invalid run path. Folder not found.' ) ; } $ this -> runPath = $ runPath ; }
Sets path to run folder .
55,317
public function setConfigPath ( string $ configPath ) : void { if ( ! file_exists ( $ configPath ) ) { throw new ManagerException ( 'Invalid config path. File not found.' ) ; } $ this -> configPath = $ configPath ; }
Sets path to config file .
55,318
public function start ( string $ poolOnly = '' ) : void { $ this -> reloadPids ( ) ; foreach ( $ this -> poolsConfig as $ pool => $ workerConfig ) { if ( ! empty ( $ poolOnly ) && $ poolOnly !== $ pool ) { continue ; } if ( ! empty ( $ this -> pids [ $ pool ] ) ) { continue ; } for ( $ i = 0 ; $ i < $ workerConfig [ 'instances' ] ; $ i ++ ) { $ this -> startupWorker ( $ pool ) ; } } }
Startup workers .
55,319
public function restart ( $ workerId = '' ) : void { $ this -> stop ( $ workerId ) ; sleep ( 2 ) ; $ this -> start ( $ workerId ) ; }
Restart workers .
55,320
public function status ( ) : array { $ this -> reloadPids ( ) ; $ workerStatus = [ ] ; if ( empty ( $ this -> pids ) ) { return $ workerStatus ; } $ Client = new \ GearmanClient ( ) ; $ Client -> addServer ( $ this -> gearmanHost , $ this -> gearmanPort ) ; $ Client -> setTimeout ( 1000 ) ; foreach ( $ this -> pids as $ pool => $ workerPids ) { $ workerStatus [ $ pool ] = [ ] ; foreach ( $ workerPids as $ workerName => $ workerPid ) { $ workerStatus [ $ pool ] [ $ workerName ] = false ; $ start = microtime ( true ) ; $ pong = @ $ Client -> doHigh ( 'ping_' . $ workerName , 'ping' ) ; if ( $ pong === 'pong' ) { $ jobinfo = @ $ Client -> doHigh ( 'jobinfo_' . $ workerName , 'foo' ) ; $ jobinfo = json_decode ( $ jobinfo , true ) ; $ workerStatus [ $ pool ] [ $ workerName ] = $ jobinfo ; $ pingtime = microtime ( true ) - $ start ; $ workerStatus [ $ pool ] [ $ workerName ] [ 'ping' ] = $ pingtime ; $ workerStatus [ $ pool ] [ $ workerName ] [ 'status' ] = 'idle' ; } else { $ workerStatus [ $ pool ] [ $ workerName ] [ 'jobs_total' ] = 'n/a' ; $ workerStatus [ $ pool ] [ $ workerName ] [ 'avg_jobs_min' ] = 'n/a' ; $ workerStatus [ $ pool ] [ $ workerName ] [ 'uptime_seconds' ] = 0 ; $ workerStatus [ $ pool ] [ $ workerName ] [ 'ping' ] = 0 ; $ workerStatus [ $ pool ] [ $ workerName ] [ 'status' ] = 'busy' ; } } } return $ workerStatus ; }
Pings every worker and displays result .
55,321
public function keepalive ( ) : bool { $ this -> reloadPids ( ) ; if ( $ this -> managerIsRunning ( ) === true ) { return false ; } if ( empty ( $ this -> pids ) ) { $ this -> start ( ) ; return true ; } $ this -> adjustRunningWorkers ( ) ; $ this -> reloadPids ( ) ; return true ; }
Pings every worker and does a restart if worker is not responding .
55,322
protected function startupWorker ( $ pool ) : void { $ workerId = $ this -> getId ( ) ; $ baseCmd = 'php %s --config %s --pool %s --name %s' ; $ launcherPath = __DIR__ . '/cli/worker.php' ; $ startupCmd = sprintf ( $ baseCmd , $ launcherPath , $ this -> getConfigPath ( ) , $ pool , $ workerId ) ; exec ( escapeshellcmd ( $ startupCmd ) . ' >> ' . $ this -> logPath . '/' . $ pool . '.log 2>&1 &' ) ; $ this -> reloadPids ( ) ; }
Starts a new worker .
55,323
protected function adjustRunningWorkers ( ) : void { foreach ( $ this -> poolsConfig as $ pool => $ workerConfig ) { $ workersActive = count ( $ this -> pids [ $ pool ] ) ; $ workersTarget = ( int ) $ workerConfig [ 'instances' ] ; if ( $ workersActive >= $ workersTarget ) { continue ; } $ workerDiff = $ workersTarget - $ workersActive ; for ( $ i = 0 ; $ i < $ workerDiff ; $ i ++ ) { $ this -> startupWorker ( $ pool ) ; } } }
Starts up new workers if there are currently running less workers than required .
55,324
protected function loadPids ( ) : void { foreach ( $ this -> poolsConfig as $ pool => $ poolConfig ) { $ pidFiles = glob ( $ this -> runPath . '/' . $ pool . '/*.pid' ) ; foreach ( $ pidFiles as $ pidFile ) { $ workerId = basename ( $ pidFile , '.pid' ) ; $ pid = file_get_contents ( $ pidFile ) ; if ( $ this -> pidIsValid ( $ pid , $ workerId ) ) { $ this -> pids [ $ pool ] [ $ workerId ] = $ pid ; } else { $ this -> removePidFile ( $ pidFile ) ; } } } }
Gets the process - ids for all workers .
55,325
protected function removePidFileByPid ( int $ pid ) : bool { foreach ( $ this -> pids as $ pool => $ poolPids ) { foreach ( $ poolPids as $ workerId => $ workerPid ) { if ( $ pid !== $ workerPid ) { continue ; } $ pidFile = $ this -> runPath . '/' . $ pool . '/' . $ pid . '.pid' ; return $ this -> removePidFile ( $ pidFile ) ; } } return false ; }
Generates path to file for given pid and removes that file .
55,326
protected function managerIsRunning ( ) : bool { global $ argv ; $ cliOutput = [ ] ; exec ( 'ps x | grep ' . $ argv [ 0 ] , $ cliOutput ) ; $ processCount = 0 ; if ( empty ( $ cliOutput ) ) { return false ; } foreach ( $ cliOutput as $ line ) { if ( strpos ( $ line , 'grep' ) !== false ) { continue ; } if ( strpos ( $ line , '/bin/sh' ) !== false ) { continue ; } $ processCount ++ ; } return ( $ processCount > 1 ) ? true : false ; }
Checks if an instance of worker manager is already running .
55,327
final protected function executeQuery ( $ sql ) { $ statement = $ this -> connection -> prepare ( $ sql ) ; $ statement -> execute ( ) ; return $ statement -> fetchAll ( ) ; }
Executes an SQL query using the specified doctrine connection name
55,328
private function parseCriteria ( array $ criteria ) { $ out = '' ; if ( ! empty ( $ criteria ) ) { $ conditions = [ ] ; foreach ( $ criteria as $ field => $ value ) { if ( is_array ( $ value ) ) { $ values = array_map ( function ( $ value ) { return $ this -> connection -> quote ( $ value ) ; } , $ value ) ; $ conditions [ ] = sprintf ( '%s IN (%s)' , $ field , implode ( ', ' , $ values ) ) ; } else { $ operator = '=' ; $ ops = [ '<>' , '<' , '>' , '<=' , '>=' ] ; foreach ( $ ops as $ op ) { if ( false !== strpos ( $ value , $ op ) ) { $ operator = $ op ; $ value = str_replace ( sprintf ( '%s ' , $ op ) , '' , $ value ) ; break ; } } $ conditions [ ] = sprintf ( '%s %s %s' , $ field , $ operator , $ this -> connection -> quote ( $ value ) ) ; } } $ out = sprintf ( ' WHERE %s' , implode ( ' AND ' , $ conditions ) ) ; } return $ out ; }
Parses query criteria into a query string
55,329
private function parseSort ( array $ sort ) { $ out = '' ; if ( ! empty ( $ sort ) ) { $ conditions = [ ] ; foreach ( $ sort as $ field => $ direction ) { $ direction = $ direction ? 'DESC' : 'ASC' ; $ conditions [ ] = sprintf ( '%s %s' , $ field , $ direction ) ; } $ out = sprintf ( ' ORDER BY %s' , implode ( ', ' , $ conditions ) ) ; } return $ out ; }
Parses sort fields into an order by clause
55,330
public function init ( $ param = null ) { $ this -> setOptions ( $ param ) ; try { $ this -> readIndexList ( ) ; if ( ! empty ( $ this -> cacheListing ) ) { $ this -> loadCache ( ) ; } $ this -> setConnected ( true ) ; } catch ( CacheException $ e ) { throw $ e ; } return true ; }
initializes the cache
55,331
protected function loadCache ( ) { if ( empty ( $ this -> cacheListing ) ) return false ; foreach ( $ this -> cacheListing as $ key => $ entry ) { if ( ! $ entry ) { continue ; } if ( ! ( $ entry instanceof Entry ) ) { unset ( $ entry ) ; continue ; } if ( ! $ entry -> getId ( ) ) { unset ( $ this -> cacheListing [ $ key ] ) ; continue ; } if ( ! $ entry -> getData ( ) || ( $ entry -> getTtl ( ) !== self :: TTL_UNLIMITED && $ entry -> getTtl ( ) < time ( ) ) ) { if ( $ entry instanceof Entry ) { $ entry -> delete ( ) ; } unset ( $ this -> cacheListing [ $ key ] ) ; continue ; } $ this -> list [ $ key ] = $ entry -> getData ( ) ; } return true ; }
load all the items into the current memory for faster access
55,332
public function get ( $ key = null ) { if ( ! isset ( $ this -> list [ $ key ] ) ) return null ; $ this -> currentIdentifier = $ this -> cacheListing [ $ key ] -> getId ( ) ; return $ this -> list [ $ key ] ; }
Gets a cache entry by key
55,333
public function set ( $ key , $ value = null , $ expiration = 0 ) { if ( empty ( $ key ) ) return false ; if ( isset ( $ this -> list [ $ key ] ) ) { if ( ! $ this -> list [ $ key ] == $ value ) return true ; $ this -> list [ $ key ] = $ value ; $ this -> cacheListing [ $ key ] -> data = $ value ; $ this -> cacheListing [ $ key ] -> save ( ) ; return true ; } $ this -> list [ $ key ] = $ value ; $ entry = new Entry ( ) ; $ entry -> setKeyName ( $ key ) ; $ entry -> setKey ( $ this -> getRandomInt ( ) ) ; $ entry -> setPermission ( MemoryHandler :: DEFAULT_PERMISSIONS ) ; $ entry -> setMode ( MemoryHandler :: CREATE_MOD ) ; $ entry -> setSize ( ( int ) MemoryHandler :: DEFAULT_SIZE ) ; $ entry -> setOffset ( ( int ) MemoryHandler :: DEFAULT_OFFSET ) ; $ entry -> setStart ( ( int ) 0 ) ; $ entry -> setCount ( ( int ) 0 ) ; $ entry -> setTtl ( ( int ) $ expiration ) ; $ entry -> setData ( $ value ) ; $ entry -> save ( ) ; $ this -> cacheListing [ $ key ] = $ entry ; return true ; }
Sets a cache entry by key
55,334
public function flush ( ) { if ( ! empty ( $ this -> cacheListing ) ) { foreach ( $ this -> cacheListing as $ entry ) { if ( $ entry instanceof Entry ) { $ entry -> delete ( ) ; } } $ this -> cacheListing = array ( ) ; } @ shmop_delete ( $ this -> indexIdentifier ) ; return true ; }
deletes the whole cache
55,335
public function delete ( $ key , $ time = 0 ) { if ( empty ( $ key ) || empty ( $ this -> cacheListing [ $ key ] ) ) return true ; $ entry = $ this -> cacheListing [ $ key ] ; $ entry -> delete ( ) ; unset ( $ this -> cacheListing [ $ key ] ) ; return true ; }
delete a cache entry
55,336
public function deleteFromList ( $ key_array = array ( ) ) { if ( empty ( $ key_array ) ) return true ; foreach ( $ key_array as $ key ) { if ( ! isset ( $ this -> cacheListing [ $ key ] ) ) continue ; $ entry = $ this -> cacheListing [ $ key ] ; $ entry -> delete ( ) ; unset ( $ this -> cacheListing [ $ key ] ) ; } return true ; }
cleans up the cache list
55,337
public function getConnectionString ( ) { $ dsn = 'mysql:' ; $ connectionSettings = $ this -> getConnectionSettings ( ) ; if ( $ this -> isSocket ( ) ) { $ dsn .= ( string ) 'unix_socket=' . $ connectionSettings -> getHost ( ) . ';' ; } else { $ dsn .= ( string ) 'host=' . $ connectionSettings -> getHost ( ) . ';' ; if ( $ connectionSettings -> getPort ( ) ) { $ dsn .= 'port=' . $ connectionSettings -> getPort ( ) . ';' ; } } if ( $ connectionSettings -> getDatabase ( ) ) { $ dsn .= "dbname=" . $ connectionSettings -> getDatabase ( ) . ';' ; } if ( $ connectionSettings -> getCharset ( ) ) { $ dsn .= "charset=" . $ connectionSettings -> getCharset ( ) . ';' ; } return $ dsn ; }
simplifaction for connection strings
55,338
public function getRootPages ( ) : array { return $ this -> connection -> createQueryBuilder ( ) -> select ( 'language' , 'id' , 'fallback' ) -> from ( 'tl_page' ) -> where ( 'type=:type' ) -> setParameter ( 'type' , 'root' ) -> orderBy ( 'fallback' ) -> addOrderBy ( 'sorting' ) -> execute ( ) -> fetchAll ( \ PDO :: FETCH_ASSOC ) ; }
Fetch the root pages from the database .
55,339
public function getPagesByPidList ( array $ pidList ) : array { return $ this -> connection -> createQueryBuilder ( ) -> select ( 'id' , 'pid' , 'languageMain' , 'type' ) -> from ( 'tl_page' ) -> where ( 'pid IN (:lookupQueue)' ) -> setParameter ( 'lookupQueue' , $ pidList , Connection :: PARAM_INT_ARRAY ) -> orderBy ( 'sorting' ) -> execute ( ) -> fetchAll ( \ PDO :: FETCH_ASSOC ) ; }
Fetch pages by pids .
55,340
public function getArticlesByPid ( int $ pageId , string $ inColumn = null ) : array { $ builder = $ this -> connection -> createQueryBuilder ( ) -> select ( 'id' , 'pid' , 'inColumn' , 'languageMain' ) -> from ( 'tl_article' ) -> where ( 'pid=:pid' ) -> setParameter ( 'pid' , $ pageId ) -> orderBy ( 'inColumn' ) -> addOrderBy ( 'sorting' ) ; if ( null !== $ inColumn ) { $ builder -> andWhere ( 'inColumn=:inColumn' ) -> setParameter ( 'inColumn' , $ inColumn ) ; } return $ builder -> execute ( ) -> fetchAll ( \ PDO :: FETCH_ASSOC ) ; }
Fetch articles by pid .
55,341
public function getContentByPidFrom ( int $ articleId , string $ pTable ) : array { $ result = $ this -> connection -> createQueryBuilder ( ) -> select ( 'id' , 'type' ) -> from ( 'tl_content' ) -> where ( 'pid=:pid' ) -> setParameter ( 'pid' , $ articleId ) -> andWhere ( 'ptable=:ptable' ) -> setParameter ( 'ptable' , $ pTable ) -> orderBy ( 'sorting' ) -> execute ( ) -> fetchAll ( \ PDO :: FETCH_ASSOC ) ; return $ result ; }
Fetch all content elements from an article .
55,342
public function getListClassNames ( ) { $ classes = parent :: getListClassNames ( ) ; if ( $ this -> hasFontIcon ( ) && $ this -> ShowIcons ) { $ classes [ ] = 'fa-ul' ; } return $ classes ; }
Answers an array of list class names for the HTML template .
55,343
public function get ( $ page = 1 ) { $ index = $ page - 1 ; if ( ! isset ( $ this -> pages [ $ index ] ) ) { throw new RuntimeException ( sprintf ( 'Invalid page %s of %s' , $ page , $ this -> count ( ) ) ) ; } return $ this -> pages [ $ index ] ; }
Get contents for the given page
55,344
function validate ( ) { if ( $ this -> end && $ this -> start ) { parent :: validate ( ) ; } else { if ( $ this -> end ) { throw new Exception ( "Class {$this->getName()} contains no targets for @Start." ) ; } else { throw new Exception ( "Class {$this->getName()} contains no targets for @End." ) ; } } }
Validates the relation object making sure it has a start and an end property .
55,345
function findProperty ( $ name ) { $ property = Reflection :: getProperty ( $ name ) ; if ( $ this -> start -> matches ( $ property ) ) { return $ this -> start ; } if ( $ this -> end -> matches ( $ property ) ) { return $ this -> end ; } return parent :: findProperty ( $ name ) ; }
Find properties based on a method name .
55,346
public function render ( $ zoneName , array $ parameters = array ( ) ) { $ context = $ this -> contextStack -> getCurrent ( ) ; $ template = $ context -> getTemplate ( ) ; $ zoneType = $ template -> getTemplateType ( ) -> getZoneTypes ( ) -> search ( array ( 'name' => $ zoneName ) ) -> first ( ) ; if ( ! $ zoneType ) { throw new InvalidZoneException ( sprintf ( 'Any "%s" zone defined into "%s" template. Check your configuration.' , $ zoneName , $ template -> getTemplateType ( ) -> getName ( ) ) ) ; } $ templates = new TemplateCollection ( array ( $ template ) ) ; if ( ( $ globalTemplate = $ template -> getGlobalTemplate ( ) ) && $ context -> isZoneVirtual ( $ zoneName ) ) { $ templates -> add ( $ globalTemplate ) ; } $ aggregationConfig = $ context -> getZoneAggregation ( $ zoneName ) ; if ( ! $ aggregationConfig ) { throw new InvalidZoneException ( sprintf ( 'The zone "%s" isn\'t registred. Check your configuration.' , $ zoneName ) ) ; } $ aggregationType = $ aggregationConfig [ 'type' ] ; if ( ! isset ( $ this -> aggregators [ $ aggregationType ] ) ) { throw new \ InvalidArgumentException ( sprintf ( 'Aggregation "%s" isnt registered, get one of these : ["%s"]' , $ aggregationType , implode ( '", "' , array_keys ( $ this -> aggregators ) ) ) ) ; } return $ this -> aggregators [ $ aggregationType ] -> aggregate ( $ templates -> reduce ( function ( $ carry , TemplateInterface $ template ) use ( $ zoneType , $ parameters ) { if ( ! empty ( $ carry ) ) { return $ carry ; } $ zone = $ template -> getZones ( ) -> search ( array ( 'zoneType' => $ zoneType ) ) -> first ( ) ; if ( ! $ zone ) { return $ carry ; } return $ zone -> getComponents ( ) -> map ( function ( ComponentInterface $ component ) use ( $ zone , $ parameters ) { return $ this -> componentDecorator -> prepareFromCurrentContext ( $ zone , $ component ) -> render ( $ parameters ) ; } ) -> toArray ( ) ; } , [ ] ) , $ aggregationConfig ) ; }
Render given zone name on current Synapse context .
55,347
public function get ( $ path ) { assert ( is_string ( $ path ) ) ; if ( $ this -> filesystem -> listContents ( $ path ) ) { return new Directory ( $ this , $ path ) ; } try { $ info = $ this -> filesystem -> getMetadata ( $ path ) ; if ( $ info ) { if ( $ info [ "type" ] == "file" ) { return new File ( $ this , $ path ) ; } return new Directory ( $ this , $ path ) ; } } catch ( \ League \ Flysystem \ FileNotFoundException $ e ) { return null ; } return null ; }
Get an object from the filesystem based on its path .
55,348
private function file_or_dir ( $ path , $ is_file ) { assert ( is_bool ( $ is_file ) ) ; $ obj = $ this -> get ( $ path ) ; if ( $ obj !== null && $ is_file === $ obj -> isFile ( ) ) { return $ obj ; } return null ; }
Get an object from fs that either is as file or a dir .
55,349
public function newFDirectory ( FSObject $ fs_object , \ Closure $ contents_lazy ) { $ fdir = new FDirectory ( $ fs_object , $ contents_lazy ) ; if ( $ this -> strict_evaluation ) { $ fdir -> fcontents ( ) ; } return $ fdir ; }
Create an FDirectory with metadata from some FSObject and some content that could be lazily produced by some function .
55,350
private function createIndex ( ) { $ basepath = $ this -> config [ "basePath" ] ; $ pattern = $ this -> config [ "pattern" ] ; $ path = "$basepath/$pattern" ; $ index = [ ] ; foreach ( glob_recursive ( $ path ) as $ file ) { $ filepath = substr ( $ file , strlen ( $ basepath ) + 1 ) ; $ matches = [ ] ; preg_match ( $ this -> filenamePattern , basename ( $ filepath ) , $ matches ) ; $ dirpart = dirname ( $ filepath ) . "/" ; if ( $ dirpart === "./" ) { $ dirpart = null ; } $ key = $ dirpart . $ matches [ 2 ] ; $ id = ( int ) $ matches [ 1 ] ; $ level = 2 ; if ( $ id % 100 === 0 ) { $ level = 0 ; } elseif ( $ id % 10 === 0 ) { $ level = 1 ; } $ index [ $ key ] = [ "file" => $ filepath , "section" => $ matches [ 1 ] , "level" => $ level , "internal" => $ this -> isInternalRoute ( $ filepath ) , "tocable" => $ this -> allowInToc ( $ filepath ) , ] ; } return $ index ; }
Generate an index from the directory structure .
55,351
private function getFrontmatter ( $ file ) { $ basepath = $ this -> config [ "basePath" ] ; $ filter1 = $ this -> config [ "textfilter-frontmatter" ] ; $ filter2 = $ this -> config [ "textfilter-title" ] ; $ filter = array_merge ( $ filter1 , $ filter2 ) ; $ path = $ basepath . "/" . $ file ; $ src = file_get_contents ( $ path ) ; $ filtered = $ this -> di -> get ( "textfilter" ) -> parse ( $ src , $ filter ) ; return $ filtered -> frontmatter ; }
Get the frontmatter of a document .
55,352
private function loadFileContentPhaseOne ( $ key ) { $ basepath = $ this -> config [ "basePath" ] ; $ filter = $ this -> config [ "textfilter-frontmatter" ] ; $ path = $ basepath . "/" . $ this -> index [ $ key ] [ "file" ] ; if ( ! is_file ( $ path ) ) { $ msg = t ( "The content '!ROUTE' does not exists as a file '!FILE'." , [ "!ROUTE" => $ key , "!FILE" => $ path ] ) ; throw new \ Anax \ Exception \ NotFoundException ( $ msg ) ; } $ src = file_get_contents ( $ path ) ; $ filtered = $ this -> di -> get ( "textfilter" ) -> parse ( $ src , $ filter ) ; return $ filtered ; }
Load content file and frontmatter this is the first time we process the content .
55,353
public static function calcularParcelamento ( $ capital , $ taxa , $ tempo , $ semjuros ) { $ parcelamento = array ( ) ; for ( $ i = 1 ; $ i <= $ tempo ; $ i ++ ) { $ m = $ capital * pow ( ( 1 + $ taxa / 100 ) , $ i ) ; if ( $ i <= $ semjuros ) { $ parcelamento [ $ i ] = array ( 'parcela' => self :: formataValor ( ( $ capital / $ i ) , '.' , 2 , ',' , '.' ) , 'total' => self :: formataValor ( $ capital , '.' , 2 , ',' , '.' ) , 'status' => 'sem juros' ) ; } else { $ parcelamento [ $ i ] = array ( 'parcela' => self :: formataValor ( ( $ m / $ i ) , '.' , 2 , ',' , '.' ) , 'total' => self :: formataValor ( $ m , '.' , 2 , ',' , '.' ) , 'status' => 'com juros' ) ; } } return $ parcelamento ; }
Calculo de Parcelamento
55,354
public static function getValorParcela ( $ total , $ parcela , $ taxa ) { if ( ! is_numeric ( $ total ) || $ total <= 0 ) { return ( false ) ; } if ( ( int ) $ parcela != $ parcela ) { return ( false ) ; } if ( ! is_numeric ( $ taxa ) || $ taxa < 0 ) { return ( false ) ; } $ taxa = $ taxa / 100 ; $ denominador = 0 ; if ( $ parcela > 1 ) { for ( $ i = 1 ; $ i <= $ parcela ; $ i ++ ) { $ denominador += 1 / pow ( 1 + $ taxa , $ i ) ; } } else { $ denominador = 1 ; } return ( $ total / $ denominador ) ; }
Retorna o valor da parcela
55,355
protected function getPathFromContent ( ) { $ pathFromContent = str_replace ( $ this -> getPathToContent ( ) , '' , $ this -> getFile ( ) -> getRealPath ( ) ) ; return trim ( $ pathFromContent , DIRECTORY_SEPARATOR ) ; }
Returns the path relative to the content directory
55,356
protected function getPathToContent ( ) { $ reverseContentPath = $ this -> getReverseContentPath ( ) ; $ contentPathParts = array_reverse ( explode ( DIRECTORY_SEPARATOR , $ reverseContentPath ) ) ; $ pathToContent = trim ( implode ( DIRECTORY_SEPARATOR , $ contentPathParts ) , DIRECTORY_SEPARATOR ) ; return DIRECTORY_SEPARATOR . $ pathToContent . DIRECTORY_SEPARATOR . 'content' . DIRECTORY_SEPARATOR ; }
Detects the path to content directory by examining the path to the file
55,357
public static function inspect ( array $ args , $ raw = false , $ callback = null ) { $ process = self :: runCommand ( 'inspect' , $ args , $ callback ) ; if ( $ process -> isSuccessful ( ) && ! $ raw ) { $ decoded = json_decode ( $ process -> getOutput ( ) ) ; return reset ( $ decoded ) ; } return $ process ; }
Return low - level information on a container or image .
55,358
public function delete ( $ resource ) { $ event = $ this -> createResourceEvent ( $ resource ) ; $ this -> dispatcher -> dispatch ( $ this -> config -> getEventName ( 'pre_delete' ) , $ event ) ; if ( ! $ event -> isPropagationStopped ( ) ) { $ this -> removeResource ( $ event ) ; $ this -> dispatcher -> dispatch ( $ this -> config -> getEventName ( 'post_delete' ) , $ event ) ; } return $ event ; }
Deletes the resource .
55,359
public function message ( $ message , $ level = 'info' ) { $ this -> session -> create ( 'flash_notification.message' , $ message ) ; $ this -> session -> create ( 'flash_notification.level' , $ level ) ; }
To show flash message with twitter bootstrap alert - info
55,360
public function overlay ( $ title , $ message , $ submitbutton = false , $ allowText = 'Save' , $ allowType = 'success' , $ dismissText = 'Close' , $ dismissType = 'default' ) { $ this -> message ( $ message ) ; $ this -> session -> create ( 'flash_notification.title' , $ title ) ; $ this -> session -> create ( 'flash_notification.overlay' , true ) ; $ this -> session -> create ( 'flash_notification.dismissText' , $ dismissText ) ; $ this -> session -> create ( 'flash_notification.dismissType' , $ dismissType ) ; $ this -> session -> create ( 'flash_notification.allowText' , $ allowText ) ; $ this -> session -> create ( 'flash_notification.allowType' , $ allowType ) ; $ this -> session -> create ( 'flash_notification.submitButton' , $ submitbutton ) ; }
To show flash message with twitter bootstrap model
55,361
public function getStatement ( string $ query_string ) : ResultSet { if ( ! $ this -> is_connected ) { $ this -> connect ( ) ; } $ stmt = $ this -> dbconn -> prepare ( $ query_string ) ; if ( false === $ stmt ) { throw new DatabaseQueryException ( 'The query could not be prepared. | ' . $ query_string . ' | ' . $ this -> dbconn -> errorInfo ( ) [ 2 ] ) ; } return new ResultSetPDO ( $ stmt ) ; }
Returns a statement object representing a prepared statement for the database .
55,362
protected function _nameConvert ( $ string ) { if ( strpos ( $ string , 'HTTP_' ) !== false ) { $ string = substr ( $ string , \ strlen ( 'HTTP_' ) ) ; } else { return false ; } $ arr_char = explode ( '_' , strtolower ( $ string ) ) ; $ newString = array_shift ( $ arr_char ) ; foreach ( $ arr_char as $ val ) { $ newString .= ucfirst ( $ val ) ; } return $ newString ; }
HTTP_USER_AGENT = > userAgent
55,363
public function getIp ( ) { $ ip = '' ; if ( $ _SERVER [ 'REMOTE_ADDR' ] ) { $ ip = $ _SERVER [ 'REMOTE_ADDR' ] ; } elseif ( getenv ( 'HTTP_CLIENT_IP' ) ) { $ ip = getenv ( 'HTTP_CLIENT_IP' ) ; } elseif ( getenv ( 'HTTP_X_FORWARDED_FOR' ) ) { $ ip = getenv ( 'HTTP_X_FORWARDED_FOR' ) ; } elseif ( getenv ( 'HTTP_X_FORWARDED' ) ) { $ ip = getenv ( 'HTTP_X_FORWARDED' ) ; } elseif ( getenv ( 'HTTP_FORWARDED_FOR' ) ) { $ ip = getenv ( 'HTTP_FORWARDED_FOR' ) ; } elseif ( getenv ( 'HTTP_FORWARDED' ) ) { $ ip = getenv ( 'HTTP_FORWARDED' ) ; } return $ ip ; }
get client Ip
55,364
protected function normalize ( ) { $ val = $ this -> base [ 'value' ] ; if ( $ val ) { switch ( $ this -> base [ 'return_format' ] ) { case 'array' : $ this -> atId = $ val [ 'ID' ] ; $ this -> atUrl = $ val [ 'url' ] ; $ this -> atTitle = $ val [ 'title' ] ; $ this -> atCaption = $ val [ 'caption' ] ; $ this -> atDescription = $ val [ 'description' ] ; break ; case 'id' : $ atch = get_post ( $ val ) ; $ this -> atId = $ val ; $ this -> atUrl = wp_get_attachment_url ( $ val ) ; $ this -> atTitle = $ atch -> post_title ; $ this -> atCaption = $ atch -> post_excerpt ; $ this -> atDescription = $ atch -> description ; break ; case 'url' : $ this -> atId = '' ; $ this -> atUrl = $ this -> base [ 'value' ] ; $ this -> atTitle = '' ; $ this -> atCaption = '' ; $ this -> atDescription = '' ; break ; default : throw new Exception ( "Field format {$this->base['return_format']} not valid" ) ; } } else { $ this -> atId = '' ; $ this -> atUrl = '' ; $ this -> atTitle = '' ; $ this -> atCaption = '' ; $ this -> atDescription = '' ; } }
Normalize attachment data depending on how the underlying field is configured .
55,365
protected function getTemplate ( $ tpl , $ outputtype = '' , $ trusted = true ) { $ tpl = $ this -> config -> templatePath . $ tpl ; if ( $ outputtype == '' ) { $ outputtype = 'html' ; } $ cachefile = dirname ( $ this -> _templateName ) . '/' ; if ( $ cachefile == './' ) { $ cachefile = '' ; } if ( $ this -> config -> cachePath == '/' || $ this -> config -> cachePath == '' ) { throw new Exception ( 'cache path is invalid ! its value is: "' . $ this -> config -> cachePath . '".' ) ; } $ cachefile = $ this -> config -> cachePath . $ cachefile . $ outputtype . ( $ trusted ? '_t' : '' ) . '_' . basename ( $ tpl ) ; $ mustCompile = $ this -> config -> compilationForce || ! file_exists ( $ cachefile ) ; if ( ! $ mustCompile ) { if ( filemtime ( $ tpl ) > filemtime ( $ cachefile ) ) { $ mustCompile = true ; } } if ( $ mustCompile ) { $ compiler = $ this -> getCompiler ( ) ; $ compiler -> compile ( $ this -> _templateName , $ tpl , $ outputtype , $ trusted , $ this -> userModifiers , $ this -> userFunctions ) ; } require_once $ cachefile ; return md5 ( $ tpl . '_' . $ outputtype . ( $ trusted ? '_t' : '' ) ) ; }
include the compiled template file and call one of the generated function .
55,366
public function make ( \ ReflectionProperty $ reflectionParameter ) { if ( ! $ this -> parser ) { throw new \ RuntimeException ( "Missing the parser Parser!" ) ; } $ result = $ this -> parser -> parse ( $ reflectionParameter -> getDocComment ( ) ) ; if ( ! $ result ) { return [ ] ; } $ validatorSet = [ ] ; $ this -> missingValidators = [ ] ; foreach ( $ result as $ validatorToken ) { $ className = $ this -> namespaceTransformer -> transform ( $ this -> classNameTransformer -> transform ( $ validatorToken [ AnnotationValidatorParser :: INDEX_INTERFACE ] ) , [ AnnotationValidatorPrependNameSpace :: NAMESPACE_OPTION_INDEX => __NAMESPACE__ ] ) ; if ( class_exists ( $ className , true ) ) { if ( empty ( $ this -> validatorTemplates [ $ className ] ) ) { $ this -> validatorTemplates [ $ className ] = new $ className ( ) ; } $ validatorSet [ ] = [ self :: INDEX_RESULT => null , AnnotationValidatorParser :: INDEX_MANDATORY => $ validatorToken [ AnnotationValidatorParser :: INDEX_MANDATORY ] , AnnotationValidatorParser :: INDEX_OPERATOR => $ validatorToken [ AnnotationValidatorParser :: INDEX_OPERATOR ] , AnnotationValidatorParser :: INDEX_INTERFACE => $ this -> validatorTemplates [ $ className ] , AnnotationValidatorParser :: INDEX_EXPECTED => $ validatorToken [ AnnotationValidatorParser :: INDEX_EXPECTED ] , ] ; } else { $ this -> missingValidators [ ] = $ className ; } } if ( $ this -> missingValidators ) { throw new \ RuntimeException ( "There is one or more Validators Missing: " . implode ( ',' , $ this -> missingValidators ) ) ; } return $ validatorSet ; }
returns null if there is no result from the parser
55,367
public static function joinPaths ( $ path1 , $ path2 ) { $ abspath = $ path1 [ 0 ] == '/' ; $ paths = array_filter ( func_get_args ( ) ) ; $ paths = array_map ( function ( $ path ) { $ path = preg_replace ( '%^/%' , '' , $ path ) ; $ path = preg_replace ( '%/$%' , '' , $ path ) ; return $ path ; } , $ paths ) ; $ path = implode ( '/' , $ paths ) ; if ( $ abspath ) { return '/' . $ path ; } else { return $ path ; } }
Joins two paths together . Works for operating system paths or for URLs .
55,368
public static function uniqueFilename ( $ basepath , $ prefix = '' , $ suffix = '' ) { $ filename = $ prefix ; while ( $ filename == $ prefix || file_exists ( self :: joinPaths ( $ basepath , $ filename ) ) ) { for ( $ charnum = 0 ; $ charnum < 30 ; $ charnum ++ ) { $ ascii = 48 + rand ( 0 , 60 ) ; if ( $ ascii > 57 ) $ ascii += 7 ; if ( $ ascii > 90 ) $ ascii += 7 ; $ filename .= chr ( $ ascii ) ; } $ filename .= $ suffix ; } $ filename = self :: joinPaths ( $ basepath , $ filename ) ; touch ( $ filename ) ; return $ filename ; }
Generates a unique file name in a directory and creates an empty file with this name .
55,369
private function configureMenus ( array $ menus , ContainerBuilder $ container ) { if ( ! $ container -> hasDefinition ( 'ekyna_admin.menu.pool' ) ) { return ; } $ pool = $ container -> getDefinition ( 'ekyna_admin.menu.pool' ) ; foreach ( $ menus as $ groupName => $ groupConfig ) { $ pool -> addMethodCall ( 'createGroup' , [ [ 'name' => $ groupName , 'label' => $ groupConfig [ 'label' ] , 'icon' => $ groupConfig [ 'icon' ] , 'position' => $ groupConfig [ 'position' ] , 'domain' => $ groupConfig [ 'domain' ] , 'route' => $ groupConfig [ 'route' ] , ] ] ) ; foreach ( $ groupConfig [ 'entries' ] as $ entryName => $ entryConfig ) { $ pool -> addMethodCall ( 'createEntry' , [ $ groupName , [ 'name' => $ entryName , 'route' => $ entryConfig [ 'route' ] , 'label' => $ entryConfig [ 'label' ] , 'resource' => $ entryConfig [ 'resource' ] , 'position' => $ entryConfig [ 'position' ] , 'domain' => $ entryConfig [ 'domain' ] , ] ] ) ; } } }
Configures the menus .
55,370
protected function waitForSiteByName ( $ site_name ) { return $ this -> retry ( 50 , function ( ) use ( $ site_name ) { $ this -> sites = $ this -> fetchSites ( fp_env ( 'ACACHA_FORGE_SERVER' ) ) ; $ site = $ this -> getSiteByName ( $ this -> sites , $ site_name ) ; return $ site ? $ site : null ; } ) ; }
Wait for site to be available by name!
55,371
protected function waitForSite ( $ site_id ) { return $ this -> retry ( 50 , function ( ) use ( $ site_id ) { $ this -> sites = $ this -> fetchSites ( fp_env ( 'ACACHA_FORGE_SERVER' ) ) ; $ site = $ this -> getSite ( $ this -> sites , $ site_id ) ; return $ site -> status == 'installed' ? $ site : null ; } ) ; }
Wait for site to be installed!
55,372
public function source ( $ source , $ sourceType = 'local' ) { $ this -> sourcePath = $ source ; $ this -> sourceType = $ sourceType ; return $ this ; }
Set the source file .
55,373
protected function parseCsv ( $ filename , ConfigurationInterface $ config ) { $ length = $ config -> getLength ( ) ; $ delimiter = $ config -> getDelimiter ( ) ; $ enclosure = $ config -> getEnclosureChar ( ) ; $ escape = $ config -> getEscapeChar ( ) ; $ result = [ ] ; if ( ( $ handle = fopen ( $ filename , 'r' ) ) !== false ) { while ( ( $ row = fgetcsv ( $ handle , $ length , $ delimiter , $ enclosure , $ escape ) ) !== false ) { $ temp = [ ] ; if ( empty ( $ this -> attributes ) ) { if ( $ config -> isFirstLineAsAttributes ( ) ) { $ this -> attributes = $ row ; } else { $ cRow = count ( $ row ) ; for ( $ i = 0 ; $ i < $ cRow ; ++ $ i ) { $ attrName = 'attribute ' . $ i ; $ this -> attributes [ ] = $ attrName ; $ temp [ $ attrName ] = trim ( $ row [ $ i ] ) ; } $ result [ ] = $ temp ; } } else { $ cRow = count ( $ row ) ; for ( $ i = 0 ; $ i < $ cRow ; ++ $ i ) { $ attrName = $ this -> attributes [ $ i ] ; $ temp [ $ attrName ] = trim ( $ row [ $ i ] ) ; } $ result [ ] = $ temp ; } } fclose ( $ handle ) ; } return $ result ; }
Parses CSV file .
55,374
protected function populateClasses ( ) { $ this -> classes = [ ] ; $ cData = count ( $ this -> data ) ; for ( $ i = 0 ; $ i < $ cData ; ++ $ i ) { $ data = $ this -> data [ $ i ] ; foreach ( $ data as $ key => $ value ) { if ( array_key_exists ( $ key , $ this -> classes ) ) { if ( array_search ( $ value , $ this -> classes [ $ key ] ) === false ) { array_push ( $ this -> classes [ $ key ] , $ value ) ; } } else { $ this -> classes [ $ key ] = [ $ value ] ; } } } }
Populates classes .
55,375
public function add ( array $ options ) { if ( false == empty ( $ options ) ) { $ this -> options = $ this -> options + $ options ; } }
Add new entry in the options . Do not use array_merge as it rewrites the keys .
55,376
public function has ( $ name ) { return Arrays :: exists ( $ name , $ this -> options ) && false === empty ( $ this -> options [ $ name ] ) ; }
Check that an entry exists .
55,377
public function ampifyImgs ( ) { $ explodedContent = explode ( $ this -> imgSeparator , $ this -> content ) ; $ explodedContent = $ this -> reattachSeparator ( $ explodedContent ) ; $ newContent = [ ] ; foreach ( $ explodedContent as $ value ) { $ srcAttributeExists = preg_match ( "/src=.*>/" , $ value ) ; if ( $ srcAttributeExists == 1 ) { $ styleAttributeExists = preg_match ( "/style=.*>/" , $ value , $ style ) ; if ( $ styleAttributeExists == 1 ) { preg_match ( "/height:(\d*)px/" , $ style [ 0 ] , $ height ) ; preg_match ( "/width:(\d*)px/" , $ style [ 0 ] , $ width ) ; preg_match ( "/src=\"(.*?)\"/" , $ value , $ src ) ; preg_match ( "/alt=\"(.*?)\"/" , $ value , $ alt ) ; $ imgHeight = $ height [ 1 ] ; $ imgWidth = $ width [ 1 ] ; $ imgSrc = $ src [ 1 ] ; if ( isset ( $ alt [ 1 ] ) ) { $ imgAlt = $ alt [ 1 ] ; } else { $ imgAlt = "" ; } $ ampedImgWithContent = $ this -> constructAmpImg ( $ value , $ imgHeight , $ imgWidth , $ imgSrc , $ imgAlt ) ; array_push ( $ newContent , $ ampedImgWithContent ) ; } else { throw new \ Exception ( '<img> tags must contain style attribute with height and width.' ) ; } } else if ( $ srcAttributeExists == 0 ) { array_push ( $ newContent , $ value ) ; } } $ implodedNewContent = implode ( "" , $ newContent ) ; return $ implodedNewContent ; }
Convert img tags to amp - img specification .
55,378
public function reattachSeparator ( $ content ) { $ separator = $ this -> imgSeparator ; $ content = array_map ( function ( $ val ) use ( $ separator ) { if ( preg_match ( '/src=\".+\"/' , $ val ) == 1 ) { return $ separator . $ val ; } else if ( preg_match ( '/src=\".+\"/' , $ val ) == 0 ) { return $ val ; } } , $ content ) ; return $ content ; }
Reattach seperator which was lost after the string explosion into an array
55,379
public function listenForm ( ) { $ this -> dispatcher -> listen ( 'antares.form: profile.*' , function ( $ name , array $ params = [ ] ) { $ row = $ params [ 0 ] ; $ builder = $ params [ 1 ] ; $ builder -> grid -> fieldset ( function ( Fieldset $ fieldset ) { $ fieldset -> legend ( trans ( 'antares/translations::messages.language_legend' ) ) ; $ langs = app ( 'languages' ) -> langs ( ) -> pluck ( 'name' , 'code' ) ; $ fieldset -> control ( 'select' , 'language' ) -> label ( trans ( 'antares/translations::messages.default_language_label' ) ) -> attributes ( [ 'data-flag-select' , 'data-selectAR' => true , 'class' => 'w220' ] ) -> fieldClass ( 'input-field--icon' ) -> prepend ( '<span class="input-field__icon"><span class="flag-icon"></span></span>' ) -> optionsData ( function ( ) use ( $ langs ) { $ codes = $ langs -> keys ( ) -> toArray ( ) ; $ return = [ ] ; foreach ( $ codes as $ code ) { $ flag = $ code == 'en' ? 'us' : $ code ; array_set ( $ return , $ code , [ 'country' => $ flag ] ) ; } return $ return ; } ) -> value ( user_meta ( 'language' , 'en' ) ) -> options ( $ langs ) ; } ) ; } ) ; return $ this ; }
Appends account user form with language select field
55,380
public function listenFormSave ( ) { $ this -> dispatcher -> listen ( 'eloquent.saved: App\User' , function ( $ model ) { if ( ! is_null ( $ language = Input :: get ( 'language' ) ) ) { $ uid = auth ( ) -> user ( ) -> id ; $ meta = UserMeta :: firstOrNew ( [ 'user_id' => $ uid , 'name' => 'language' ] ) ; $ meta -> value = $ language ; $ meta -> save ( ) ; } } ) ; return $ this ; }
Listen for event when user changes language
55,381
public static function fromResponseValue ( array $ value , \ PHPUnit_Extensions_Selenium2TestCase_URL $ parentFolder , \ PHPUnit_Extensions_Selenium2TestCase_Driver $ driver ) { if ( ! isset ( $ value [ 'ELEMENT' ] ) ) { throw new \ InvalidArgumentException ( 'Element not found.' ) ; } $ url = $ parentFolder -> descend ( $ value [ 'ELEMENT' ] ) ; return new static ( $ driver , $ url ) ; }
Creates the element object from a value returned by Selenium WebDriver .
55,382
public function element ( \ PHPUnit_Extensions_Selenium2TestCase_ElementCriteria $ criteria ) { $ value = $ this -> postCommand ( 'element' , $ criteria ) ; return static :: fromResponseValue ( $ value , $ this -> url -> ascend ( ) , $ this -> driver ) ; }
Finds an element in the scope of this element .
55,383
public function elements ( \ PHPUnit_Extensions_Selenium2TestCase_ElementCriteria $ criteria ) { $ values = $ this -> postCommand ( 'elements' , $ criteria ) ; $ elements = array ( ) ; foreach ( $ values as $ value ) { $ elements [ ] = static :: fromResponseValue ( $ value , $ this -> url -> ascend ( ) , $ this -> driver ) ; } return $ elements ; }
Finds elements in the scope of this element .
55,384
protected function setExpression ( $ expression ) { if ( is_string ( $ expression ) ) { $ expression = CronExpression :: factory ( $ expression ) ; } elseif ( ! $ expression instanceof CronExpression ) { throw new \ InvalidArgumentException ( 'Expression should be a string or an instanceof CronExpression.' ) ; } $ this -> cronExpression = $ expression ; }
Set the cron expression .
55,385
public function getNextRunDate ( ) { if ( $ this -> nextRunDate === null ) { $ nextRun = $ this -> cronExpression -> getNextRunDate ( ) ; $ this -> nextRunDate = $ nextRun -> getTimestamp ( ) ; } return $ this -> nextRunDate ; }
Returns the timestamp of the next run date .
55,386
public function handle ( Authenticatable $ user ) { $ social = $ this -> session -> get ( 'orchestra.oneauth' ) ; if ( is_null ( $ social ) ) { return ; } $ model = User :: where ( 'provider' , '=' , $ social [ 'provider' ] ) -> where ( 'uid' , '=' , $ social [ 'user' ] -> getId ( ) ) -> first ( ) ; if ( is_null ( $ model ) ) { return ; } $ model -> setAttribute ( 'user_id' , $ user -> getAuthIdentifier ( ) ) ; $ model -> save ( ) ; return true ; }
Handle user logged in .
55,387
private static function getMigrationScripts ( int $ start , int $ end , array $ skip ) { return MigrationsManager :: getMigrationsManager ( ) -> getMigrationScripts ( $ start , $ end , $ skip ) ; }
Retrieve the registered migration scripts relevant to the current migration range .
55,388
protected function createEndpoints ( ContainerInterface $ container , array $ aliases ) : array { $ result = [ ] ; foreach ( $ aliases as $ alias ) { $ result [ ] = $ container -> get ( $ alias ) ; } return $ result ; }
Creates the fetchers to use .
55,389
public static function create ( $ template = 'Response' ) { $ return = null ; switch ( $ template ) { case 'Discovery' : $ return = new AlexaResponse ( new Response ( new Event ( new Header ( ) , new Payload ( ) ) ) ) ; break ; case 'StateReport' : $ return = new AlexaResponse ( new Response ( new Event ( new Header ( ) , new Payload ( ) , new Endpoint ( ) ) , new Context ( ) ) ) ; break ; case 'Response' : $ return = new AlexaResponse ( new Response ( new Event ( new Header ( ) , new Payload ( ) , new Endpoint ( ) ) , new Context ( ) ) ) ; break ; case 'Authorization' : $ return = new AlexaResponse ( new Response ( new Event ( new Header ( ) , new Payload ( ) ) ) ) ; break ; case 'Error' : $ return = new AlexaResponse ( new Response ( new Event ( new Header ( ) , new Payload ( ) ) ) ) ; break ; default : throw new InvalidArgumentException ( 'Unsupported AlexaResponse template: ' . $ template ) ; break ; } return $ return ; }
Create AlexaResponse skeleton
55,390
public function isInsideBlock ( $ blockName , $ onlyUpper = false ) { if ( $ onlyUpper ) { return ( end ( $ this -> _blockStack ) == $ blockName ) ; } for ( $ i = count ( $ this -> _blockStack ) - 1 ; $ i >= 0 ; -- $ i ) { if ( $ this -> _blockStack [ $ i ] == $ blockName ) { return true ; } } return false ; }
for plugins it says if the plugin is inside the given block .
55,391
public static function set_db ( $ db , $ connection_name = self :: DEFAULT_CONNECTION ) { self :: _setupDbConfig ( $ connection_name ) ; self :: $ _db [ $ connection_name ] = $ db ; if ( ! is_null ( self :: $ _db [ $ connection_name ] ) ) { self :: _setupIdentifierQuoteCharacter ( $ connection_name ) ; self :: _setupLimitClauseStyle ( $ connection_name ) ; } }
Set the PDO object used by One to communicate with the database . This is public in case the One should use a ready - instantiated PDO object as its database connection . Accepts an optional string key to identify the connection if multiple connections are used .
55,392
protected static function _detectLimitClauseStyle ( $ connection_name ) { switch ( self :: get_db ( $ connection_name ) -> getAttribute ( PDO :: ATTR_DRIVER_NAME ) ) { case 'sqlsrv' : case 'dblib' : case 'mssql' : return One :: LIMIT_STYLE_TOP_N ; default : return One :: LIMIT_STYLE_LIMIT ; } }
Returns a constant after determining the appropriate limit clause style
55,393
public static function get_db ( $ connection_name = self :: DEFAULT_CONNECTION ) { self :: _setupDb ( $ connection_name ) ; return self :: $ _db [ $ connection_name ] ; }
Returns the PDO instance used by the the One to communicate with the database . This can be called if any low - level DB access is required outside the class . If multiple connections are used accepts an optional key name for the connection .
55,394
public function find_one ( $ id = null ) { if ( ! is_null ( $ id ) ) { $ this -> where_id_is ( $ id ) ; } $ this -> limit ( 1 ) ; $ rows = $ this -> _run ( ) ; if ( empty ( $ rows ) ) { return false ; } return $ this -> _createInstanceFromRow ( $ rows [ 0 ] ) ; }
Tell the One that you are expecting a single result back from your query and execute it . Will return a single instance of the One class or false if no rows were returned . As a shortcut you may supply an ID as a parameter to this method . This will perfOne a primary key lookup on the table .
55,395
protected function _callAggregateDbFunction ( $ sqlFunction , $ column ) { $ alias = Inflector :: lower ( $ sqlFunction ) ; $ sqlFunction = Inflector :: upper ( $ sqlFunction ) ; if ( '*' != $ column ) { $ column = $ this -> _quoteIdentifier ( $ column ) ; } $ result_columns = $ this -> _resultColumns ; $ this -> _resultColumns = [ ] ; $ this -> select_expr ( "$sqlFunction($column)" , $ alias ) ; $ result = $ this -> find_one ( ) ; $ this -> _resultColumns = $ result_columns ; $ returnValue = 0 ; if ( $ result !== false && isset ( $ result -> $ alias ) ) { if ( ! is_numeric ( $ result -> $ alias ) ) { $ returnValue = $ result -> $ alias ; } elseif ( ( int ) $ result -> $ alias == ( float ) $ result -> $ alias ) { $ returnValue = ( int ) $ result -> $ alias ; } else { $ returnValue = ( float ) $ result -> $ alias ; } } return $ returnValue ; }
Execute an aggregate query on the current connection .
55,396
public function raw_query ( $ query , $ parameters = [ ] ) { $ this -> _is_raw_query = true ; $ this -> _raw_query = $ query ; $ this -> _raw_parameters = $ parameters ; return $ this ; }
PerfOne a raw query . The query can contain placeholders in either named or question mark style . If placeholders are used the parameters should be an array of values which will be bound to the placeholders in the query . If this method is called all other query building methods will be ignored .
55,397
protected function _addResultColumn ( $ expr , $ alias = null ) { if ( ! is_null ( $ alias ) ) { $ expr .= " AS " . $ this -> _quoteIdentifier ( $ alias ) ; } if ( $ this -> _using_default_resultColumns ) { $ this -> _resultColumns = array ( $ expr ) ; $ this -> _using_default_resultColumns = false ; } else { $ this -> _resultColumns [ ] = $ expr ; } return $ this ; }
Internal method to add an unquoted expression to the set of columns returned by the SELECT query . The second optional argument is the alias to return the expression as .
55,398
public function count_null_id_columns ( ) { if ( Arrays :: is ( $ this -> _getIdColumnName ( ) ) ) { return count ( array_filter ( $ this -> id ( ) , 'is_null' ) ) ; } else { return is_null ( $ this -> id ( ) ) ? 1 : 0 ; } }
Counts the number of columns that belong to the primary key and their value is null .
55,399
public function select_many_expr ( ) { $ columns = func_get_args ( ) ; if ( ! empty ( $ columns ) ) { $ columns = $ this -> _nOnealiseSelectManyColumns ( $ columns ) ; foreach ( $ columns as $ alias => $ column ) { if ( is_numeric ( $ alias ) ) { $ alias = null ; } $ this -> select_expr ( $ column , $ alias ) ; } } return $ this ; }
Add an unquoted expression to the list of columns returned by the SELECT query . Many columns can be supplied as either an array or as a list of parameters to the method .