idx
int64
0
60.3k
question
stringlengths
101
6.21k
target
stringlengths
7
803
47,400
protected function getTable ( $ data = null ) { if ( is_null ( $ data ) ) { $ this -> _table = static :: $ table ; $ this -> _prifixTable = ( Config :: get ( 'database.prefixing' ) ? Config :: get ( 'database.prefixe' ) : '' ) . static :: $ table ; if ( ! $ this -> checkTable ( ) ) { throw new TableNotFoundException ( static :: $ table ) ; } return $ this -> _prifixTable ; } else { $ this -> _prifixTable = $ data [ 'prifixTable' ] ; $ this -> _table = static :: $ table ; } }
get the model table name .
47,401
protected function checkTable ( ) { $ data = Query :: from ( 'information_schema.tables' , false ) -> select ( '*' ) -> where ( 'TABLE_SCHEMA' , '=' , Config :: get ( 'database.database' ) ) -> andwhere ( 'TABLE_NAME' , '=' , $ this -> _prifixTable ) -> get ( Query :: GET_ARRAY ) ; return ( Table :: count ( $ data ) > 0 ) ? true : false ; }
Check if table exists in database .
47,402
protected function columns ( $ data = null ) { if ( is_null ( $ data ) ) { $ this -> _columns = $ this -> extruct ( Query :: from ( 'INFORMATION_SCHEMA.COLUMNS' , false ) -> select ( 'COLUMN_NAME' ) -> where ( 'TABLE_SCHEMA' , '=' , Config :: get ( 'database.database' ) ) -> andwhere ( 'TABLE_NAME' , '=' , $ this -> _prifixTable ) -> get ( Query :: GET_ARRAY ) ) ; return $ this -> _columns ; } else { $ this -> _columns = $ data [ 'columns' ] ; } }
to get and set all columns of data table .
47,403
protected function key ( $ data = null ) { if ( is_null ( $ data ) ) { $ data = $ this -> getPK ( ) ; if ( Table :: count ( $ data ) > 1 ) { throw new ManyPrimaryKeysException ( ) ; } elseif ( Table :: count ( $ data ) == 0 ) { throw new PrimaryKeyNotFoundException ( static :: $ table ) ; } $ this -> _keyName = $ data [ 0 ] [ 'Column_name' ] ; $ this -> _key [ 'name' ] = $ data [ 0 ] [ 'Column_name' ] ; } else { $ this -> _keyName = $ data [ 'key' ] ; $ this -> _key [ 'name' ] = $ data [ 'key' ] ; } }
set primary key the framework doesn t support more the column to be the primary key otherwise exception will be thrown .
47,404
protected function struct ( $ key , $ fail ) { $ data = $ this -> dig ( $ key ) ; if ( Table :: count ( $ data ) == 1 ) { if ( $ this -> _canKept && $ this -> keptAt ( $ data ) ) { $ this -> _kept = true ; } if ( $ this -> _canStashed && $ this -> stashedAt ( $ data ) ) { $ this -> _stashed = true ; } $ this -> convert ( $ data ) ; } elseif ( $ fail && Table :: count ( $ data ) == 0 ) { throw new ModelNotFoundException ( $ key , $ this -> _model ) ; } }
get data from data table according to primary key value .
47,405
protected function fill ( $ data ) { if ( $ this -> _canKept && $ this -> keptAt ( $ data [ 'values' ] ) ) { $ this -> _kept = true ; } if ( $ this -> _canStashed && $ this -> stashedAt ( $ data [ 'values' ] ) ) { $ this -> _stashed = true ; } $ this -> convert ( $ data [ 'values' ] ) ; }
fill data from array .
47,406
protected function dig ( $ key ) { return Query :: from ( static :: $ table ) -> select ( '*' ) -> where ( $ this -> _keyName , '=' , $ key ) -> get ( Query :: GET_ARRAY ) ; }
search for data by Query Class according to primary key .
47,407
protected function convert ( $ data ) { foreach ( $ data [ 0 ] as $ key => $ value ) { if ( ! $ this -> _kept && ! $ this -> _stashed ) { $ this -> $ key = $ value ; $ this -> setKey ( $ key , $ value ) ; } else { if ( $ this -> _kept ) { $ this -> _keptData [ $ key ] = $ value ; } if ( $ this -> _stashed ) { $ this -> _stashedData [ $ key ] = $ value ; } } $ this -> data [ $ key ] = $ value ; } }
make data array colmuns as property in case of hidden data property was true data will be stored in hidden data instead ofas property .
47,408
public function save ( ) { if ( $ this -> _state == CRUD :: CREATE_STAT ) { $ this -> add ( ) ; } elseif ( $ this -> _state == CRUD :: UPDATE_STAT ) { $ this -> edit ( ) ; } }
Save the opertaion makes by user either creation or editing .
47,409
private function add ( ) { $ columns = [ ] ; $ values = [ ] ; if ( $ this -> _tracked ) { $ this -> created_at = Time :: current ( ) ; } foreach ( $ this -> _columns as $ value ) { if ( $ value != $ this -> _keyName && isset ( $ this -> $ value ) && ! empty ( $ this -> $ value ) ) { $ columns [ ] = $ value ; $ values [ ] = $ this -> $ value ; } } return $ this -> insert ( $ columns , $ values ) ; }
function to add data in data table .
47,410
private function insert ( $ columns , $ values ) { return Query :: table ( static :: $ table ) -> column ( $ columns ) -> value ( $ values ) -> insert ( ) ; }
function to exexute insert data .
47,411
private function edit ( ) { $ columns = [ ] ; $ values = [ ] ; if ( $ this -> _tracked ) { $ this -> edited_at = Time :: current ( ) ; } foreach ( $ this -> _columns as $ value ) { if ( $ value != $ this -> _keyName ) { $ columns [ ] = $ value ; $ values [ ] = empty ( $ this -> $ value ) ? null : $ this -> $ value ; } } return $ this -> update ( $ columns , $ values ) ; }
function to edit data in data table .
47,412
private function update ( $ columns , $ values ) { $ query = Query :: table ( static :: $ table ) ; for ( $ i = 0 ; $ i < Table :: count ( $ columns ) ; $ i ++ ) { $ query = ! empty ( $ values [ $ i ] ) ? $ query -> set ( $ columns [ $ i ] , $ values [ $ i ] ) : $ query -> set ( $ columns [ $ i ] , 'null' , false ) ; } $ query -> where ( $ this -> _keyName , '=' , $ this -> _keyValue ) -> update ( ) ; return $ query ; }
function to exexute update data .
47,413
public function delete ( ) { if ( ! $ this -> _canKept ) { $ this -> forceDelete ( ) ; } else { Query :: table ( static :: $ table ) -> set ( 'deleted_at' , Time :: current ( ) ) -> where ( $ this -> _keyName , '=' , $ this -> _keyValue ) -> update ( ) ; } }
to delete the model from database in case of Kept deleted just hide it .
47,414
public function forceDelete ( ) { $ key = $ this -> _kept ? $ this -> _keptData [ $ this -> _keyName ] : $ this -> _keyValue ; Query :: table ( static :: $ table ) -> where ( $ this -> _keyName , '=' , $ key ) -> delete ( ) ; $ this -> reset ( ) ; }
to force delete the model from database even if the model is Kept deleted .
47,415
private function reset ( ) { $ vars = get_object_vars ( $ this ) ; foreach ( $ vars as $ key => $ value ) { unset ( $ this -> $ key ) ; } }
reset the current model if it s deleted .
47,416
public function restore ( ) { if ( $ this -> _kept ) { $ this -> bring ( ) ; Query :: table ( static :: $ table ) -> set ( 'deleted_at' , 'NULL' , false ) -> where ( $ this -> _keyName , '=' , $ this -> _keyValue ) -> update ( ) ; } }
restore the model if it s kept deleted .
47,417
private function bring ( ) { foreach ( $ this -> _keptData as $ key => $ value ) { $ this -> $ key = $ value ; } $ this -> _keyValue = $ this -> _keptData [ $ this -> _keyName ] ; $ this -> _keptData = null ; $ this -> _kept = false ; }
to extruct data from keptdata array to become properties .
47,418
public static function all ( ) { $ class = get_called_class ( ) ; $ object = new $ class ( ) ; $ table = $ object -> _table ; $ key = $ object -> _keyName ; $ data = Query :: table ( $ table ) -> select ( '*' ) -> where ( "'true'" , '=' , 'true' ) ; if ( $ object -> _canKept ) { $ data = $ data -> orGroup ( 'and' , Query :: condition ( 'deleted_at' , '>' , Time :: current ( ) ) , Query :: condition ( 'deleted_at' , 'is' , 'NULL' , false ) ) ; } if ( $ object -> _canStashed ) { $ data = $ data -> orGroup ( 'and' , Query :: condition ( 'appeared_at' , '<=' , Time :: current ( ) ) , Query :: condition ( 'appeared_at' , 'is' , 'NULL' , false ) ) ; } $ data = $ data -> get ( Query :: GET_ARRAY ) ; return self :: collect ( $ data , $ table , $ key ) ; }
get collection of all data of the model from data table .
47,419
public static function onlyTrash ( ) { $ class = get_called_class ( ) ; $ object = new $ class ( ) ; $ table = $ object -> _table ; $ key = $ object -> _keyName ; $ data = Query :: table ( $ table ) -> select ( '*' ) ; if ( $ object -> _canKept ) { $ data = $ data -> where ( 'deleted_at' , '<=' , Time :: current ( ) ) ; } $ data = $ data -> get ( Query :: GET_ARRAY ) ; return self :: collect ( $ data , $ table , $ key ) ; }
get collection of all kept data of the model from data table .
47,420
public static function where ( $ column , $ relation , $ value ) { $ self = self :: instance ( ) ; $ key = $ self -> _keyName ; $ data = \ Query :: from ( $ self -> _table ) -> select ( $ key ) -> where ( $ column , $ relation , $ value ) -> get ( ) ; $ rows = [ ] ; if ( ! is_null ( $ data ) ) { foreach ( $ data as $ item ) { $ rows [ ] = self :: instance ( $ item -> $ key ) ; } } return $ rows ; }
get data by where clause .
47,421
public static function forge ( $ file = null , $ data = null , $ auto_encode = null ) { $ class = null ; if ( $ file !== null ) { $ extension = pathinfo ( $ file , PATHINFO_EXTENSION ) ; $ class = \ Config :: get ( 'parser.extensions.' . $ extension , null ) ; } if ( $ class === null ) { $ class = get_called_class ( ) ; } if ( $ file !== null and $ file [ 0 ] !== '/' and $ file [ 1 ] !== ':' ) { $ file = $ extension ? preg_replace ( '/\.' . preg_quote ( $ extension ) . '$/i' , '' , $ file ) : $ file ; } if ( is_array ( $ class ) ) { $ class [ 'extension' ] and $ extension = $ class [ 'extension' ] ; $ class = $ class [ 'class' ] ; } foreach ( ( array ) \ Config :: get ( 'parser.' . $ class . '.include' , array ( ) ) as $ include ) { if ( ! array_key_exists ( $ include , static :: $ loaded_files ) ) { require $ include ; static :: $ loaded_files [ $ include ] = true ; } } if ( $ auto_encode === null ) { $ auto_encode = \ Config :: get ( 'parser.' . $ class . '.auto_encode' , null ) ; } $ view = new $ class ( null , $ data , $ auto_encode ) ; if ( $ file !== null ) { $ extension and $ view -> extension = $ extension ; $ view -> set_filename ( $ file ) ; } return $ view ; }
Forges a new View object based on the extension
47,422
public function setTemplateExtension ( $ extension ) { $ extension = ( string ) $ extension ; $ extension = trim ( $ extension ) ; if ( '.' == $ extension [ 0 ] ) { $ extension = substr ( $ extension , 1 ) ; } $ this -> extension = $ extension ; }
Set Template Extension file
47,423
public function setLayoutVariableName ( $ name ) { $ name = ( string ) $ name ; $ name = trim ( $ name ) ; if ( ! preg_match ( '/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*/' , $ name ) ) { throw new InvalidArgumentException ( 'Invalid variable name' ) ; } $ this -> layoutVariableName = $ name ; }
Set Layout main variable name
47,424
public function hasChildren ( ) : bool { $ children = ( ( $ this -> getRgt ( ) - $ this -> getLft ( ) ) - 1 ) / 2 ; return ( 0 === $ children ) ? false : true ; }
returns true if there are children
47,425
public function generateSearchRules ( ) { if ( ( $ table = $ this -> getTableSchema ( ) ) === false ) { return [ "[['" . implode ( "', '" , $ this -> getColumnNames ( ) ) . "'], 'safe']" ] ; } $ types = [ ] ; foreach ( $ table -> columns as $ column ) { switch ( $ column -> type ) { case Schema :: TYPE_SMALLINT : case Schema :: TYPE_INTEGER : case Schema :: TYPE_BIGINT : $ types [ 'integer' ] [ ] = $ column -> name ; break ; case Schema :: TYPE_BOOLEAN : $ types [ 'boolean' ] [ ] = $ column -> name ; break ; case Schema :: TYPE_FLOAT : case Schema :: TYPE_DECIMAL : case Schema :: TYPE_MONEY : case Schema :: TYPE_DATE : case Schema :: TYPE_TIME : case Schema :: TYPE_DATETIME : case Schema :: TYPE_TIMESTAMP : default : $ types [ 'safe' ] [ ] = $ column -> name ; break ; } } $ rules = [ ] ; foreach ( $ types as $ type => $ columns ) { $ sf = "" ; if ( $ type == "safe" ) { $ tabs = $ this -> generateRelations ( ) ; foreach ( $ tabs as $ tab ) { if ( $ tab ) { $ sf .= ( $ sf == "" ? "/*, '" : ", '" ) . $ tab . "Id'" ; } } $ sf .= ( $ sf == "" ? "" : "*/" ) ; } $ rules [ ] = "[['" . implode ( "', '" , $ columns ) . "'" . $ sf . "], '$type']" ; } return $ rules ; }
Generates validation rules for the search model .
47,426
public static function instance ( $ model_class ) { $ observer = get_called_class ( ) ; if ( empty ( static :: $ _instances [ $ observer ] [ $ model_class ] ) ) { static :: $ _instances [ $ observer ] [ $ model_class ] = new static ( $ model_class ) ; } return static :: $ _instances [ $ observer ] [ $ model_class ] ; }
Create an instance of this observer
47,427
public function compiledExists ( ) { return $ this -> cached === false ? false : file_exists ( $ this -> cachePath . '/' . $ this -> getClassName ( ) . '.php' ) ; }
Check if compiled view already exists .
47,428
public function compile ( ) { if ( $ this -> compiledExists ( ) === false ) { if ( is_file ( $ this -> filepath ) === false ) { throw new \ Exception ( 'File "' . $ this -> filepath . '" does not exists.' ) ; } $ this -> raw = file_get_contents ( $ this -> filepath ) ; if ( $ this -> options [ 'add-source-line-numbers' ] ) $ this -> prepared = $ this -> addLinesNumbers ( $ this -> raw ) ; else $ this -> prepared = $ this -> raw ; $ this -> removeComments ( ) ; $ this -> resolveExtending ( ) ; $ this -> compileRenders ( ) ; $ this -> compileEchoes ( ) ; $ this -> compileConditions ( ) ; $ this -> compileLoops ( ) ; $ this -> compileSpecialStatements ( ) ; $ this -> prepareSections ( ) ; $ this -> findSections ( ) ; $ this -> replaceSections ( ) ; } }
Compile view if compiled version doesn t exists in cache .
47,429
public function resolveExtending ( ) { preg_match_all ( '/@extends\(\'([a-zA-Z0-9\.\-]+)\'\)/' , $ this -> prepared , $ matches ) ; if ( isset ( $ matches [ 1 ] [ 0 ] ) ) { $ this -> extends = trim ( $ matches [ 1 ] [ 0 ] ) ; $ this -> prepared = trim ( str_replace ( $ matches [ 0 ] [ 0 ] , '' , $ this -> prepared ) ) ; } preg_match_all ( '/@no-extends/' , $ this -> prepared , $ matches ) ; if ( isset ( $ matches [ 0 ] [ 0 ] ) && count ( $ matches [ 0 ] [ 0 ] ) == 1 ) { $ this -> extends = false ; $ this -> prepared = trim ( str_replace ( $ matches [ 0 ] [ 0 ] , '' , $ this -> prepared ) ) ; } }
Extending view .
47,430
public function compileSpecialStatements ( ) { preg_match_all ( '/@set\s?(.*)/' , $ this -> prepared , $ matches ) ; foreach ( $ matches [ 0 ] as $ key => $ val ) { $ exploded = explode ( ' ' , $ matches [ 1 ] [ $ key ] ) ; $ varName = substr ( trim ( array_shift ( $ exploded ) ) , 1 ) ; $ value = trim ( ltrim ( trim ( implode ( ' ' , $ exploded ) ) , '=' ) ) ; $ this -> prepared = str_replace ( $ matches [ 0 ] [ $ key ] , "<?php $$varName = $value; \$this->appendData(['$varName' => $$varName]); ?>" , $ this -> prepared ) ; } }
Compile special statements .
47,431
public function createFiltersMethods ( array $ names , $ variable ) { if ( $ names === array ( ) ) { return $ variable ; } $ filter = array_shift ( $ names ) ; if ( $ filter === 'raw' ) { $ result = $ this -> createFiltersMethods ( $ names , $ variable ) ; } else { $ begin = '' ; $ end = '' ; if ( function_exists ( $ filter ) ) { $ begin = "{$filter}(" ; } else { $ begin = "\$env->filter('{$filter}', " ; } $ result = $ begin . $ this -> createFiltersMethods ( $ names , $ variable ) . ')' ; } return $ result ; }
Creates filters methods for varible .
47,432
public function get ( $ key ) { $ session = $ this -> getSessionData ( ) ; return $ this -> has ( $ key ) ? $ session [ $ key ] : null ; }
Retrieve a property from the session by its key .
47,433
protected function getSessionData ( ) { $ data = isset ( $ _SESSION [ $ this -> config [ 'key' ] ] ) ? $ _SESSION [ $ this -> config [ 'key' ] ] : [ ] ; return array_merge ( $ data , $ this -> flash ) ; }
Merge all of the notifier session data and any flashed data .
47,434
public function append ( $ url , $ formatterName = null ) { $ urlComponents = parse_url ( $ url ) ; $ parameters = array ( ) ; if ( isset ( $ urlComponents [ 'query' ] ) ) { parse_str ( $ urlComponents [ 'query' ] , $ parameters ) ; } $ trackingParameters = $ this -> persister -> getAllTrackingParameters ( ) ; if ( null !== $ formatterName ) { $ foundFormatter = $ this -> findFormatterByName ( $ formatterName ) ; if ( null === $ foundFormatter ) { throw new InvalidConfigurationException ( sprintf ( 'Unknown formatter "%s".' , $ formatterName ) ) ; } $ parameters = array_merge ( $ parameters , $ this -> formatters [ $ foundFormatter ] -> format ( $ trackingParameters ) ) ; $ parameters = $ this -> formatters [ $ foundFormatter ] -> checkFormat ( $ parameters ) ; } foreach ( $ parameters as $ parameterName => $ parameterValue ) { if ( ! is_array ( $ parameterValue ) && preg_match ( '`^{\s?(?<parameter>[a-z0-9_]+)\s?}$`i' , $ parameterValue , $ matches ) ) { $ parameters [ $ parameterName ] = $ trackingParameters -> get ( $ matches [ 'parameter' ] , null ) ; } } $ urlComponents [ 'query' ] = http_build_query ( $ parameters , null , '&' , PHP_QUERY_RFC3986 ) ; if ( true === empty ( $ urlComponents [ 'query' ] ) ) { $ urlComponents [ 'query' ] = null ; } return $ this -> buildUrl ( $ urlComponents ) ; }
Appends the query parameters depending on domain s formatters defined in configuration .
47,435
public function execute ( $ objectContext ) { if ( ! $ this -> ok ) return ; foreach ( $ this -> entries as $ entry ) { if ( ! $ this -> ok ) return ; $ entry -> execute ( $ objectContext ) ; } }
Execute call queue
47,436
protected function classMethod ( & $ class = NULL , & $ method = NULL , $ command ) { $ commandEx = explode ( ':' , $ command ) ; $ class = $ commandEx [ 0 ] ; $ method = $ commandEx [ 1 ] ?? NULL ; }
protected class method
47,437
public final function checkConfiguration ( $ deep = false ) { if ( ! file_exists ( $ this -> filename ) || ! is_readable ( $ this -> filename ) ) { throw new ConfigurationNotFoundException ( "File $this->filename does not exist or is not readable" ) ; } $ fileExtension = pathinfo ( $ this -> filename , PATHINFO_EXTENSION ) ; if ( in_array ( $ fileExtension , static :: $ supportedFileTypes ) ) { return true ; } if ( ! $ deep ) { return false ; } try { $ this -> parseAndCacheConfiguration ( ) ; return true ; } catch ( ParseException $ e ) { return false ; } }
Checks if a given file can be parsed by this configuration loader . If the file type is supported by this loader this function will return true without further checking for correct syntax of the configuration file .
47,438
public function setTarget ( $ target ) { if ( ! is_string ( $ target ) || $ target == '' ) { throw new \ InvalidArgumentException ( 'No valid URL given.' ) ; } $ this -> target = $ target ; $ this -> setContent ( sprintf ( '<!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> <meta http-equiv="refresh" content="0; url=%1$s" /> </head> <body> <p>Redirecting to <a href="%1$s">%1$s</a>. </body> </html>' , htmlspecialchars ( $ target , ENT_QUOTES , 'UTF-8' ) ) ) ; $ this -> setHeader ( 'Location' , $ target ) ; return $ this ; }
Sets the target URL where the redirections points to .
47,439
public function editFile ( ProcessBuilder $ processBuilder , $ filePath ) { $ proc = $ processBuilder -> setPrefix ( $ this -> _editorCommand ) -> setArguments ( [ $ filePath ] ) -> getProcess ( ) ; $ proc -> setTty ( true ) -> run ( ) ; return $ proc ; }
Edit the given file using the symfony process builder to build the symfony process to execute .
47,440
public function editData ( ProcessBuilder $ processBuilder , $ data ) { $ filePath = tempnam ( sys_get_temp_dir ( ) , 'sensibleEditor' ) ; file_put_contents ( $ filePath , $ data ) ; $ proc = $ this -> editFile ( $ processBuilder , $ filePath ) ; if ( $ proc -> isSuccessful ( ) ) { $ data = file_get_contents ( $ filePath ) ; } unlink ( $ filePath ) ; return $ data ; }
Edit the given data using the symfony process builder to build the symfony process to execute .
47,441
public function execute ( ) { $ repositoryResponse = [ ] ; $ arrayOfObjects = [ ] ; $ resultCount = 0 ; $ responseStatus = ResponseAbstract :: STATUS_SUCCESS ; try { $ this -> executeDataGateway ( ) ; if ( $ this -> repository != null ) { $ arrayOfObjects = $ this -> repository -> getEntitiesFromResponse ( ) ; $ repositoryResponse = $ this -> repository -> getResponse ( ) ; $ responseStatus = $ this -> repository -> isResponseStatusSuccess ( ) == true ? ResponseAbstract :: STATUS_SUCCESS : ResponseAbstract :: STATUS_FAIL ; } else { $ arrayOfObjects = [ ] ; $ repositoryResponse = [ ] ; } $ resultCount = $ this -> getTotalResultCount ( ) ; } catch ( \ Exception $ e ) { $ responseStatus = ResponseAbstract :: STATUS_FAIL ; $ this -> response -> setMessages ( [ 'No result was found' ] ) ; } $ this -> response -> setStatus ( $ responseStatus ) ; $ this -> response -> setResult ( $ arrayOfObjects ) ; $ this -> response -> setSourceResponse ( $ repositoryResponse ) ; $ this -> response -> setTotalResultCount ( $ resultCount ) ; }
Execute this use case
47,442
public function module ( string $ name , string $ icon , callable $ definitionCallback ) { $ definition = new ContentModuleDefinition ( $ name , $ icon , $ this -> config ) ; $ definitionCallback ( $ definition ) ; $ this -> customModules ( [ $ name => function ( ) use ( $ definition ) { return $ definition -> loadModule ( $ this -> iocContainer -> get ( IContentGroupRepository :: class ) , $ this -> iocContainer -> get ( IAuthSystem :: class ) , $ this -> iocContainer -> get ( IClock :: class ) ) ; } , ] ) ; }
Defines a module within the content package .
47,443
public static function value ( $ str , $ round = false ) { if ( is_string ( $ str ) ) { $ str = strtr ( $ str , '.' , '' ) ; $ str = strtr ( $ str , ',' , '.' ) ; } $ val = floatval ( $ str ) ; if ( $ round !== false ) { $ val = round ( $ val , intval ( $ round ) ) ; } return $ val ; }
Converte string em float .
47,444
public function getValue ( ) { $ type = ( string ) $ this -> element -> attributes ( ) -> type ; $ type = ( empty ( $ type ) ) ? 'string' : $ type ; $ value = ( string ) $ this -> element -> attributes ( ) -> value ; $ casterClassName = $ this -> resolveCasterClassName ( $ type ) ; $ casterObject = new $ casterClassName ( $ value ) ; return $ casterObject -> cast ( ) ; }
Post - processing the node value by additionally specified type declaration . If no type is defined values returned as string .
47,445
private function resolveCasterClassName ( $ type ) { foreach ( $ this -> casters as $ typeNames => $ casterClass ) { $ names = explode ( '|' , $ typeNames ) ; if ( ! in_array ( $ type , $ names ) ) { continue ; } return $ casterClass ; } throw CasterException :: unresolvableType ( $ type ) ; }
Resolve the correct caster class by defined type
47,446
private function addFormDeclaration ( $ formTypeName ) { $ name = strtolower ( $ this -> model ) ; $ extension = $ matches = preg_split ( '/(?=[A-Z])/' , $ this -> bundle -> getName ( ) , - 1 , PREG_SPLIT_NO_EMPTY ) ; $ bundleName = $ this -> getBundlePrefix ( ) ; array_pop ( $ extension ) ; $ path = $ this -> bundle -> getPath ( ) . '/Resources/config/forms.xml' ; if ( ! file_exists ( $ path ) ) { $ this -> renderFile ( 'form/ServicesForms.xml.twig' , $ path , array ( ) ) ; $ ref = 'protected $configFiles = array(' ; $ this -> dumpFile ( $ this -> bundle -> getPath ( ) . '/DependencyInjection/' . implode ( '' , $ extension ) . 'Extension.php' , "\n 'forms'," , $ ref ) ; die ; } $ this -> addService ( $ path , $ bundleName , $ name , $ formTypeName ) ; $ this -> addParameter ( $ path , $ bundleName , $ name ) ; }
Add service form declaration
47,447
private function addService ( $ path , $ bundleName , $ name , $ formTypeName ) { $ ref = '<services>' ; $ replaceBefore = true ; $ group = $ bundleName . '_' . $ name ; $ declaration = <<<EOF <service id="$bundleName.form.type.$name" class="%$bundleName.form.type.$name.class%"> <argument>%$bundleName.model.$name.class%</argument> <argument type="collection"> <argument>$group</argument> </argument> <tag name="form.type" alias="$formTypeName" /> </service>EOF ; if ( $ this -> refExist ( $ path , $ declaration ) ) { return ; } if ( ! $ this -> refExist ( $ path , $ ref ) ) { $ ref = '</container>' ; $ replaceBefore = false ; $ declaration = <<<EOF <services>$declaration </services>EOF ; } $ this -> dumpFile ( $ path , "\n" . $ declaration . "\n" , $ ref , $ replaceBefore ) ; }
Add service node
47,448
private function addParameter ( $ path , $ bundleName , $ name ) { $ formPath = $ this -> configuration [ 'namespace' ] . '\\' . $ this -> model . 'Type' ; $ ref = '<parameters>' ; $ replaceBefore = true ; $ declaration = <<<EOF <parameter key="$bundleName.form.type.$name.class">$formPath</parameter>EOF ; if ( $ this -> refExist ( $ path , $ declaration ) ) { return ; } if ( ! $ this -> refExist ( $ path , $ ref ) ) { $ ref = ' <services>' ; $ replaceBefore = false ; $ declaration = <<<EOF <parameters>$declaration </parameters>EOF ; } $ this -> dumpFile ( $ path , "\n" . $ declaration , $ ref , $ replaceBefore ) ; }
Add parameter node
47,449
public function start_lvl ( & $ output , $ depth = 0 , $ args = [ ] ) { $ GLOBALS [ 'comment_depth' ] = $ depth + 1 ; switch ( $ args [ 'style' ] ) { case 'div' : break ; case 'ol' : $ output .= '<ol class="children list-unstyled">' . PHP_EOL ; break ; case 'ul' : default : $ output .= '<ul class="children list-unstyled">' . PHP_EOL ; break ; } }
Start the list before the elements are added .
47,450
public function end_lvl ( & $ output , $ depth = 0 , $ args = [ ] ) { $ tab = ' ' ; $ indent = ( $ depth == 1 ) ? 8 + $ depth : 7 + ( $ depth * 2 ) ; switch ( $ args [ 'style' ] ) { case 'div' : break ; case 'ol' : case 'ul' : default : $ output .= str_repeat ( $ tab , $ indent ) ; break ; } parent :: end_lvl ( $ output , $ depth , $ args ) ; }
End the list of items after the elements are added .
47,451
public function next ( ) { $ operation = $ this -> operation ; $ this -> value = $ operation ( $ this -> value ) ; $ this -> elementsGenerated ++ ; }
generates next value
47,452
public static function create ( $ message , $ messageVariables = null , $ code = null , PhpException $ previous = null ) { $ messageFormat = [ 'message' => $ message , 'messageVariables' => $ messageVariables ] ; return new static ( $ messageFormat , $ code , $ previous ) ; }
Creates a new exception by the given arguments .
47,453
public function setCode ( $ code ) { if ( ! is_scalar ( $ code ) ) { throw new InvalidArgumentException ( sprintf ( 'Wrong parameters for %s([int|string $code]); %s given.' , __METHOD__ , is_object ( $ code ) ? get_class ( $ code ) : gettype ( $ code ) ) , E_ERROR ) ; } $ this -> code = $ code ; return $ this ; }
Sets the Exception code .
47,454
public function setMessage ( $ message ) { $ messageVariables = null ; if ( is_array ( $ message ) ) { if ( array_key_exists ( 'messageVariables' , $ message ) ) { $ messageVariables = $ message [ 'messageVariables' ] ; } if ( array_key_exists ( 'message' , $ message ) ) { $ message = $ message [ 'message' ] ; } else { $ messageVariables = $ message ; $ message = $ this -> messageTemplate ; } } if ( ! is_string ( $ message ) ) { throw new InvalidArgumentException ( sprintf ( 'Wrong parameters for %s([array|string $message]); %s given.' , __METHOD__ , is_object ( $ message ) ? get_class ( $ message ) : gettype ( $ message ) ) , E_ERROR ) ; } $ this -> message = $ this -> createMessage ( $ message , $ messageVariables ) ; return $ this ; }
Sets the Exception generated message .
47,455
protected function createMessage ( $ message , $ variables = null ) { if ( null !== $ variables && is_array ( $ variables ) ) { $ variables = array_merge ( $ this -> getMessageVariables ( ) , $ variables ) ; } else { $ variables = $ this -> getMessageVariables ( ) ; } foreach ( $ variables as $ variableKey => $ variable ) { if ( is_array ( $ variable ) || ( $ variable instanceof Traversable ) ) { $ variable = implode ( ', ' , array_values ( $ variable ) ) ; } if ( ! is_scalar ( $ variable ) ) { $ variable = $ this -> switchType ( $ variable ) ; } $ message = str_replace ( "%$variableKey%" , ( string ) $ variable , $ message ) ; } return $ message ; }
Constructs and returns a exception message with the given message key and value . Returns null if and only if the given key does not correspond to an existing template .
47,456
public function getCauseMessage ( ) { $ causes = [ ] ; $ current = [ 'class' => get_class ( $ this ) , 'message' => $ this -> getMessage ( ) , 'code' => $ this -> getCode ( ) , 'file' => $ this -> getFile ( ) , 'line' => $ this -> getLine ( ) ] ; $ causes [ ] = $ current ; $ previous = $ this -> getPrevious ( ) ; while ( $ previous !== null ) { if ( $ previous instanceof Exception ) { $ prevCauses = $ previous -> getCauseMessage ( ) ; foreach ( $ prevCauses as $ cause ) { $ causes [ ] = $ cause ; } } elseif ( $ previous instanceof PhpException ) { $ causes [ ] = [ 'class' => get_class ( $ previous ) , 'message' => $ previous -> getMessage ( ) , 'code' => $ previous -> getCode ( ) , 'file' => $ previous -> getFile ( ) , 'line' => $ previous -> getLine ( ) ] ; } $ previous = $ previous -> getPrevious ( ) ; } return $ causes ; }
Get the message of caused exceptions .
47,457
public function getTraceSaveAsString ( ) { $ traces = $ this -> getTrace ( ) ; $ messages = [ 'STACK TRACE DETAILS : ' ] ; foreach ( $ traces as $ index => $ trace ) { $ message = sprintf ( '#%d ' , $ index + 1 ) ; if ( isset ( $ trace [ 'file' ] ) ) { if ( ! is_string ( $ trace [ 'file' ] ) ) { $ message .= '[Unknown Function]: ' ; } else { $ line = 0 ; if ( isset ( $ trace [ 'line' ] ) && is_int ( $ trace [ 'line' ] ) ) { $ line = $ trace [ 'line' ] ; } $ message .= sprintf ( '%s(%d): ' , $ trace [ 'file' ] , $ line ) ; } } else { $ message .= '[Internal Function]: ' ; } if ( isset ( $ trace [ 'class' ] ) && is_string ( $ trace [ 'class' ] ) ) { $ message .= $ trace [ 'class' ] . ' ' ; } if ( isset ( $ trace [ 'type' ] ) && is_string ( $ trace [ 'type' ] ) ) { $ message .= $ trace [ 'type' ] . ' ' ; } if ( isset ( $ trace [ 'function' ] ) && is_string ( $ trace [ 'function' ] ) ) { $ message .= $ trace [ 'function' ] . '(' ; if ( isset ( $ trace [ 'args' ] ) && count ( $ trace [ 'args' ] ) > 0 ) { $ arguments = $ trace [ 'args' ] ; $ argVariables = [ ] ; foreach ( $ arguments as $ argument ) { $ argVariables [ ] = $ this -> switchType ( $ argument ) ; } $ message .= implode ( ', ' , $ argVariables ) ; } $ message .= ')' ; } $ messages [ ] = trim ( $ message ) ; } return implode ( "\n" , $ messages ) ; }
Gets the stack trace as a string .
47,458
protected function switchType ( $ argument ) { $ stringType = null ; $ type = strtolower ( gettype ( $ argument ) ) ; switch ( $ type ) { case 'boolean' : $ stringType = sprintf ( '[%s "%s"]' , ucwords ( $ type ) , ( ( int ) $ argument === 1 ) ? 'True' : 'False' ) ; break ; case 'integer' : case 'double' : case 'float' : case 'string' : $ stringType = sprintf ( '[%s "%s"]' , ucwords ( $ type ) , $ argument ) ; break ; case 'array' : $ stringType = sprintf ( '[%s {value: %s}]' , ucwords ( $ type ) , var_export ( $ argument , true ) ) ; break ; case 'object' : $ stringType = sprintf ( '[%s "%s"]' , ucwords ( $ type ) , get_class ( $ argument ) ) ; break ; case 'resource' : $ stringType = sprintf ( '[%s]' , ucwords ( $ type ) ) ; break ; case 'null' : $ stringType = '[NULL]' ; break ; default ; $ stringType = '[Unknown Type]' ; break ; } return $ stringType ; }
Convert type to string .
47,459
public function initialize ( ) { $ this -> setDialect ( new MysqlDialect ( $ this ) ) ; $ flags = $ this -> getConfig ( 'flags' ) ; if ( $ timezone = $ this -> getConfig ( 'timezone' ) ) { if ( $ timezone === 'UTC' ) { $ timezone = '+00:00' ; } $ flags [ PDO :: MYSQL_ATTR_INIT_COMMAND ] = sprintf ( 'SET time_zone = "%s";' , $ timezone ) ; } $ this -> setConfig ( 'flags' , $ flags ) ; }
Set the dialect and timezone being used .
47,460
public function listJsonAction ( ) { $ em = $ this -> getDoctrine ( ) -> getManager ( ) ; $ adminManager = $ this -> get ( 'admin_manager' ) ; $ jsonList = $ this -> get ( 'json_list' ) ; $ jsonList -> setRepository ( $ em -> getRepository ( 'EcommerceBundle:Product' ) ) ; $ user = $ this -> container -> get ( 'security.token_storage' ) -> getToken ( ) -> getUser ( ) ; if ( $ user -> isGranted ( 'ROLE_USER' ) ) { $ jsonList -> setActor ( $ user ) ; } $ response = $ jsonList -> get ( ) ; return new JsonResponse ( $ response ) ; }
Returns a list of Product entities in JSON format .
47,461
public function statsAction ( $ id , $ from , $ to ) { $ em = $ this -> getDoctrine ( ) -> getManager ( ) ; $ entity = $ em -> getRepository ( 'EcommerceBundle:Product' ) -> find ( $ id ) ; $ adminManager = $ this -> container -> get ( 'admin_manager' ) ; $ stats = $ adminManager -> getProductStats ( $ entity , $ from , $ to ) ; $ label = array ( ) ; $ visits = array ( ) ; foreach ( $ stats as $ stat ) { $ label [ ] = $ stat [ 'day' ] ; $ visits [ ] = $ stat [ 'visits' ] ; } $ returnValues = new \ stdClass ( ) ; $ returnValues -> count = count ( $ stats ) ; $ returnValues -> labels = implode ( ',' , $ label ) ; $ returnValues -> visits = implode ( ',' , $ visits ) ; return new JsonResponse ( $ returnValues ) ; }
Returns a list of Actor entities in JSON format .
47,462
public function editAction ( Request $ request , Product $ product ) { $ user = $ this -> container -> get ( 'security.token_storage' ) -> getToken ( ) -> getUser ( ) ; if ( $ user -> isGranted ( 'ROLE_USER' ) && $ product -> getActor ( ) -> getId ( ) != $ user -> getId ( ) ) { return $ this -> redirect ( $ this -> generateUrl ( 'ecommerce_product_index' ) ) ; } $ formConfig = array ( ) ; if ( $ user -> isGranted ( 'ROLE_USER' ) ) { $ formConfig [ 'actor' ] = $ user ; } $ deleteForm = $ this -> createDeleteForm ( $ product ) ; $ editForm = $ this -> createForm ( 'EcommerceBundle\Form\ProductType' , $ product , $ formConfig ) ; $ attributesForm = $ this -> createForm ( 'EcommerceBundle\Form\ProductAttributesType' , $ product , array ( 'category' => $ product -> getCategory ( ) -> getId ( ) ) ) ; $ featuresForm = $ this -> createForm ( 'EcommerceBundle\Form\ProductFeaturesType' , $ product , array ( 'category' => $ product -> getCategory ( ) -> getId ( ) ) ) ; $ relatedProductsForm = $ this -> createForm ( 'EcommerceBundle\Form\ProductRelatedType' , $ product ) ; if ( $ request -> getMethod ( 'POST' ) ) { $ redirectParams = array ( 'id' => $ product -> getId ( ) ) ; if ( $ request -> request -> has ( 'product_attributes' ) ) { $ editForm = $ attributesForm ; $ redirectParams = array_merge ( $ redirectParams , array ( 'attributes' => 1 ) ) ; } else if ( $ request -> request -> has ( 'product_features' ) ) { $ editForm = $ featuresForm ; $ redirectParams = array_merge ( $ redirectParams , array ( 'features' => 1 ) ) ; } else if ( $ request -> request -> has ( 'product_related' ) ) { $ editForm = $ relatedProductsForm ; $ redirectParams = array_merge ( $ redirectParams , array ( 'related' => 1 ) ) ; } $ editForm -> handleRequest ( $ request ) ; if ( $ editForm -> isSubmitted ( ) && $ editForm -> isValid ( ) ) { $ em = $ this -> getDoctrine ( ) -> getManager ( ) ; $ em -> persist ( $ product ) ; $ em -> flush ( ) ; $ this -> get ( 'session' ) -> getFlashBag ( ) -> add ( 'success' , 'product.edited' ) ; return $ this -> redirectToRoute ( 'ecommerce_product_show' , $ redirectParams ) ; } } return array ( 'entity' => $ product , 'edit_form' => $ editForm -> createView ( ) , 'attributes_form' => $ attributesForm -> createView ( ) , 'features_form' => $ featuresForm -> createView ( ) , 'related_form' => $ relatedProductsForm -> createView ( ) , 'delete_form' => $ deleteForm -> createView ( ) , ) ; }
Displays a form to edit an existing Product entity .
47,463
private function createDeleteForm ( Product $ product ) { return $ this -> createFormBuilder ( ) -> setAction ( $ this -> generateUrl ( 'ecommerce_product_delete' , array ( 'id' => $ product -> getId ( ) ) ) ) -> setMethod ( 'DELETE' ) -> getForm ( ) ; }
Creates a form to delete a Product entity .
47,464
public function updateImage ( Request $ request ) { $ fileName = $ request -> query -> get ( 'file' ) ; $ type = $ request -> query -> get ( 'type' ) ; $ value = $ request -> query -> get ( 'value' ) ; $ qb = $ this -> getDoctrine ( ) -> getManager ( ) -> getRepository ( 'CoreBundle:Image' ) -> createQueryBuilder ( 'i' ) ; $ image = $ qb -> where ( $ qb -> expr ( ) -> like ( 'i.path' , ':path' ) ) -> setParameter ( 'path' , '%' . $ fileName . '%' ) -> getQuery ( ) -> getOneOrNullResult ( ) ; if ( ! $ image ) { throw new NotFoundHttpException ( 'Unable to find Image entity.' ) ; } if ( $ type == 'title' ) $ image -> setTitle ( $ value ) ; if ( $ type == 'alt' ) $ image -> setAlt ( $ value ) ; $ this -> getDoctrine ( ) -> getManager ( ) -> flush ( ) ; return new JsonResponse ( array ( 'success' => true ) ) ; }
Manages a product image
47,465
public function Gdn_Dispatcher_BeforeDispatch_Handler ( $ Sender ) { $ Enabled = C ( 'Garden.Analytics.Enabled' , TRUE ) ; if ( $ Enabled && ! Gdn :: PluginManager ( ) -> HasNewMethod ( 'SettingsController' , 'Index' ) ) { Gdn :: PluginManager ( ) -> RegisterNewMethod ( 'VanillaStatsPlugin' , 'StatsDashboard' , 'SettingsController' , 'Index' ) ; } }
Override the default dashboard page with the new stats one .
47,466
public function StatsDashboard ( $ Sender ) { $ StatsUrl = $ this -> AnalyticsServer ; if ( ! StringBeginsWith ( $ StatsUrl , 'http:' ) && ! StringBeginsWith ( $ StatsUrl , 'https:' ) ) $ StatsUrl = Gdn :: Request ( ) -> Scheme ( ) . "://{$StatsUrl}" ; $ Sender -> AddDefinition ( 'VanillaStatsUrl' , $ StatsUrl ) ; $ Sender -> SetData ( 'VanillaStatsUrl' , $ StatsUrl ) ; $ Sender -> AddJsFile ( 'settings.js' ) ; $ Sender -> Title ( T ( 'Dashboard' ) ) ; $ Sender -> RequiredAdminPermissions [ ] = 'Garden.Settings.Manage' ; $ Sender -> RequiredAdminPermissions [ ] = 'Garden.Users.Add' ; $ Sender -> RequiredAdminPermissions [ ] = 'Garden.Users.Edit' ; $ Sender -> RequiredAdminPermissions [ ] = 'Garden.Users.Delete' ; $ Sender -> RequiredAdminPermissions [ ] = 'Garden.Users.Approve' ; $ Sender -> FireEvent ( 'DefineAdminPermissions' ) ; $ Sender -> Permission ( $ Sender -> RequiredAdminPermissions , '' , FALSE ) ; $ Sender -> AddSideMenu ( 'dashboard/settings' ) ; if ( ! Gdn_Statistics :: CheckIsEnabled ( ) && Gdn_Statistics :: CheckIsLocalhost ( ) ) { $ Sender -> Render ( 'dashboardlocalhost' , '' , 'plugins/VanillaStats' ) ; } else { $ Sender -> AddJsFile ( 'plugins/VanillaStats/js/vanillastats.js' ) ; $ Sender -> AddJsFile ( 'plugins/VanillaStats/js/picker.js' ) ; $ Sender -> AddCSSFile ( 'plugins/VanillaStats/design/picker.css' ) ; $ this -> ConfigureRange ( $ Sender ) ; $ VanillaID = Gdn :: InstallationID ( ) ; $ Sender -> SetData ( 'VanillaID' , $ VanillaID ) ; $ Sender -> SetData ( 'VanillaVersion' , APPLICATION_VERSION ) ; $ Sender -> SetData ( 'SecurityToken' , $ this -> SecurityToken ( ) ) ; $ Sender -> Render ( 'dashboard' , '' , 'plugins/VanillaStats' ) ; } }
Override the default index method of the settings controller in the dashboard application to render new statistics .
47,467
public function SettingsController_DashboardSummaries_Create ( $ Sender ) { $ Sender -> AddJsFile ( 'settings.js' ) ; $ Sender -> Title ( T ( 'Dashboard Summaries' ) ) ; $ Sender -> RequiredAdminPermissions [ ] = 'Garden.Settings.Manage' ; $ Sender -> RequiredAdminPermissions [ ] = 'Garden.Users.Add' ; $ Sender -> RequiredAdminPermissions [ ] = 'Garden.Users.Edit' ; $ Sender -> RequiredAdminPermissions [ ] = 'Garden.Users.Delete' ; $ Sender -> RequiredAdminPermissions [ ] = 'Garden.Users.Approve' ; $ Sender -> FireEvent ( 'DefineAdminPermissions' ) ; $ Sender -> Permission ( $ Sender -> RequiredAdminPermissions , '' , FALSE ) ; $ Sender -> AddSideMenu ( 'dashboard/settings' ) ; $ this -> ConfigureRange ( $ Sender ) ; $ UserModel = new UserModel ( ) ; $ Sender -> SetData ( 'DiscussionData' , $ UserModel -> SQL -> Select ( 'd.DiscussionID, d.Name, d.CountBookmarks, d.CountViews, d.CountComments' ) -> From ( 'Discussion d' ) -> Where ( 'd.DateLastComment >=' , $ Sender -> DateStart ) -> Where ( 'd.DateLastComment <=' , $ Sender -> DateEnd ) -> OrderBy ( 'd.CountViews' , 'desc' ) -> OrderBy ( 'd.CountComments' , 'desc' ) -> OrderBy ( 'd.CountBookmarks' , 'desc' ) -> Limit ( 10 , 0 ) -> Get ( ) ) ; $ Sender -> SetData ( 'UserData' , $ UserModel -> SQL -> Select ( 'u.UserID, u.Name' ) -> Select ( 'c.CommentID' , 'count' , 'CountComments' ) -> From ( 'User u' ) -> Join ( 'Comment c' , 'u.UserID = c.InsertUserID' , 'inner' ) -> GroupBy ( 'u.UserID, u.Name' ) -> Where ( 'c.DateInserted >=' , $ Sender -> DateStart ) -> Where ( 'c.DateInserted <=' , $ Sender -> DateEnd ) -> OrderBy ( 'CountComments' , 'desc' ) -> Limit ( 10 , 0 ) -> Get ( ) ) ; $ Sender -> Render ( 'dashboardsummaries' , '' , 'plugins/VanillaStats' ) ; }
A view containing most active discussions & users during a specific time period . This gets ajaxed into the dashboard homepage as date ranges are defined .
47,468
public function get ( ) { $ keys = $ this -> registry -> setRoot ( Registry :: HKEY_LOCAL_MACHINE ) -> setPath ( $ this -> path ) -> get ( ) ; $ software = [ ] ; foreach ( $ keys as $ key ) { $ path = $ this -> path . $ key ; $ name = $ this -> registry -> setPath ( $ path ) -> getValue ( 'DisplayName' ) ; if ( $ name ) { $ software [ ] = new Application ( [ 'name' => $ name , 'version' => $ this -> registry -> getValue ( 'DisplayVersion' ) , 'publisher' => $ this -> registry -> getValue ( 'Publisher' ) , 'install_date' => $ this -> registry -> getValue ( 'InstallDate' ) , ] ) ; } } return $ software ; }
Returns an array of software on the current computer .
47,469
protected function getResultSet ( ) { if ( ! $ this -> resultSetPrototype instanceof HydratingResultSet ) { $ resultSetPrototype = new HydratingResultSet ; $ resultSetPrototype -> setHydrator ( $ this -> getHydrator ( ) ) ; $ resultSetPrototype -> setObjectPrototype ( $ this -> getModel ( ) ) ; $ this -> resultSetPrototype = $ resultSetPrototype ; } return clone $ this -> resultSetPrototype ; }
gets the resultSet
47,470
public function getById ( $ id , $ col = null ) { $ col = ( $ col ) ? : $ this -> getPrimaryKey ( ) ; $ select = $ this -> getSelect ( ) -> where ( [ $ col => $ id ] ) ; $ resultSet = $ this -> fetchResult ( $ select ) ; if ( $ resultSet -> count ( ) > 1 ) { $ rowSet = [ ] ; foreach ( $ resultSet as $ row ) { $ rowSet [ ] = $ row ; } } elseif ( $ resultSet -> count ( ) === 1 ) { $ rowSet = $ resultSet -> current ( ) ; } else { $ rowSet = $ this -> getModel ( ) ; } return $ rowSet ; }
Gets one or more rows by its id
47,471
public function fetchAll ( $ sort = null ) { $ select = $ this -> getSelect ( ) ; $ select = $ this -> setSortOrder ( $ select , $ sort ) ; $ resultSet = $ this -> fetchResult ( $ select ) ; return $ resultSet ; }
Fetches all rows from database table .
47,472
public function search ( array $ search , $ sort , $ select = null ) { $ select = ( $ select ) ? : $ this -> getSelect ( ) ; foreach ( $ search as $ key => $ value ) { if ( ! $ value [ 'searchString' ] == '' ) { if ( substr ( $ value [ 'searchString' ] , 0 , 1 ) == '=' && $ key == 0 ) { $ id = ( int ) substr ( $ value [ 'searchString' ] , 1 ) ; $ select -> where -> equalTo ( $ this -> getPrimaryKey ( ) , $ id ) ; } else { $ where = $ select -> where -> nest ( ) ; $ c = 0 ; foreach ( $ value [ 'columns' ] as $ column ) { if ( $ c > 0 ) $ where -> or ; $ where -> like ( $ column , '%' . $ value [ 'searchString' ] . '%' ) ; $ c ++ ; } $ where -> unnest ( ) ; } } } $ select = $ this -> setSortOrder ( $ select , $ sort ) ; return $ this -> fetchResult ( $ select ) ; }
basic search on table data
47,473
public function insert ( array $ data , $ table = null ) { $ table = ( $ table ) ? : $ this -> getTable ( ) ; $ sql = $ this -> getSql ( ) ; $ insert = $ sql -> insert ( $ table ) ; $ insert -> values ( $ data ) ; $ statement = $ sql -> prepareStatementForSqlObject ( $ insert ) ; $ result = $ statement -> execute ( ) ; return $ result -> getGeneratedValue ( ) ; }
Inserts a new row into database returns insertId
47,474
public function paginate ( $ select , $ resultSet = null ) { $ resultSet = $ resultSet ? : $ this -> getResultSet ( ) ; $ adapter = new DbSelect ( $ select , $ this -> getAdapter ( ) , $ resultSet ) ; $ paginator = new Paginator ( $ adapter ) ; $ options = $ this -> getPaginatorOptions ( ) ; if ( isset ( $ options [ 'limit' ] ) ) { $ paginator -> setItemCountPerPage ( $ options [ 'limit' ] ) ; } if ( isset ( $ options [ 'page' ] ) ) { $ paginator -> setCurrentPageNumber ( $ options [ 'page' ] ) ; } $ paginator -> setPageRange ( 5 ) ; return $ paginator ; }
Paginates the result set
47,475
protected function fetchResult ( Select $ select , AbstractResultSet $ resultSet = null ) { $ resultSet = $ resultSet ? : $ this -> getResultSet ( ) ; $ resultSet -> buffer ( ) ; if ( $ this -> usePaginator ( ) ) { $ this -> setUsePaginator ( false ) ; $ resultSet = $ this -> paginate ( $ select , $ resultSet ) ; } else { $ statement = $ this -> getSql ( ) -> prepareStatementForSqlObject ( $ select ) ; $ result = $ statement -> execute ( ) ; $ resultSet -> initialize ( $ result ) ; } return $ resultSet ; }
Fetches the result of select from database
47,476
public function setSortOrder ( Select $ select , $ sort ) { if ( $ sort === '' || null === $ sort || empty ( $ sort ) ) { return $ select ; } $ select -> reset ( 'order' ) ; if ( is_string ( $ sort ) ) { $ sort = explode ( ' ' , $ sort ) ; } $ order = [ ] ; foreach ( $ sort as $ column ) { if ( strchr ( $ column , '-' ) ) { $ column = substr ( $ column , 1 , strlen ( $ column ) ) ; $ direction = Select :: ORDER_DESCENDING ; } else { $ direction = Select :: ORDER_ASCENDING ; } if ( 'sqlite' == $ this -> getAdapter ( ) -> getPlatform ( ) -> getName ( ) ) { $ direction = 'COLLATE NOCASE ' . $ direction ; } $ order [ ] = $ column . ' ' . $ direction ; } return $ select -> order ( $ order ) ; }
Sets sort order of database query
47,477
public static function run ( $ root = '../' , $ routes = true , $ session = true ) { self :: setScreen ( ) ; self :: setRoot ( $ root ) ; self :: setCaseVars ( false , false ) ; self :: callBus ( ) ; Bus :: run ( 'web' , $ session ) ; self :: setVersion ( ) ; self :: $ version -> cookie ( ) ; self :: setSHA ( ) ; self :: ini ( ) ; self :: fetcher ( $ routes ) ; return true ; }
Run the Framework .
47,478
public static function console ( $ root = '' , $ session = true ) { self :: setCaseVars ( true , false ) ; self :: consoleServerVars ( ) ; self :: setScreen ( ) ; self :: setRoot ( $ root ) ; self :: consoleBus ( ) ; Bus :: run ( 'lumos' ) ; self :: setVersion ( ) ; self :: ini ( false ) ; self :: fetcher ( false ) ; return true ; }
Run the console .
47,479
protected static function ini ( $ database = true , $ test = false ) { Alias :: ini ( self :: $ root ) ; Url :: ini ( ) ; Path :: ini ( ) ; Template :: run ( ) ; if ( Component :: isOn ( 'faker' ) ) { Faker :: ini ( ) ; } Link :: ini ( ) ; Lang :: ini ( $ test ) ; if ( $ database && Component :: isOn ( 'database' ) ) { Database :: ini ( ) ; Schema :: ini ( ) ; } Auth :: ini ( ) ; Plugins :: ini ( ) ; }
Init Framework classes .
47,480
public static function vendor ( ) { self :: checkVendor ( ) ; $ path = is_null ( self :: $ root ) ? 'vendor/autoload.php' : self :: $ root . 'vendor/autoload.php' ; include_once $ path ; }
call vendor .
47,481
private function setRoutes ( array $ routes ) { $ this -> routes = [ ] ; foreach ( $ routes as $ name => $ route ) { $ this -> add ( $ name , $ route ) ; } }
Sets the initial route collection .
47,482
public function registerRepository ( ManagedRepositoryInterface $ repository ) { $ name = $ repository -> getName ( ) ; if ( $ this -> hasRepository ( $ name ) ) { throw new \ LogicException ( sprintf ( 'Repository %s is already registered.' , $ name ) ) ; } $ event = new ManagedRepositoryEvent ( $ repository ) ; $ this -> eventDispatcher -> dispatch ( ManagedRepositoryEvent :: REGISTER , $ event ) ; $ repository = $ event -> getRepository ( ) ; $ this -> repositories [ $ name ] = $ repository ; $ this -> classMap [ $ repository -> getClassName ( ) ] = $ name ; return $ repository ; }
Register a repository
47,483
public function validate ( $ object = null ) { if ( ! isset ( $ this -> context ) ) { throw new InvalidParameter ( "You must set a context before validating or filtering." ) ; } $ result = $ this -> reduce ( $ this -> context , $ object ) ; if ( $ result ) { return true ; } else { return false ; } }
Validate a single object
47,484
public function loadEnv ( string $ path ) : Configurator { if ( is_readable ( $ path ) ) { $ this -> dotEnv -> load ( $ path ) ; } return $ this ; }
Public environment from . env file
47,485
public function readConfigDir ( string $ path ) : Configurator { if ( ! is_dir ( $ path ) ) { throw new \ InvalidArgumentException ( sprintf ( "Config dir isn't a directory! %s given." , $ path ) ) ; } $ entitiesDir = new \ DirectoryIterator ( $ path ) ; foreach ( $ entitiesDir as $ fileInfo ) { if ( ! $ fileInfo -> isFile ( ) || ( 'php' !== $ fileInfo -> getExtension ( ) ) ) { continue ; } require_once ( $ fileInfo -> getPathname ( ) ) ; } return $ this ; }
Include all php scripts in the dir
47,486
public function process ( Request $ request , FormInterface $ form ) { if ( $ request -> isMethod ( 'POST' ) ) { $ form -> submit ( $ request ) ; if ( $ form -> isValid ( ) ) { $ text = $ form -> getData ( ) ; foreach ( $ text -> getTranslations ( ) as $ translation ) { $ translation -> setText ( $ text ) ; } $ this -> textManager -> add ( $ form -> getData ( ) ) ; return true ; } } return false ; }
Process text .
47,487
protected function _init ( ) { parent :: _init ( ) ; $ this -> _rules += [ 'allowAll' => [ 'rule' => function ( ) { return true ; } ] , 'denyAll' => [ 'rule' => function ( ) { return false ; } ] , 'allowAnyUser' => [ 'message' => 'You must be logged in.' , 'rule' => function ( $ user ) { return $ user ? true : false ; } ] , 'allowIp' => [ 'message' => 'Your IP is not allowed to access this area.' , 'rule' => function ( $ user , $ request , $ options ) { $ options += [ 'ip' => false ] ; if ( is_string ( $ options [ 'ip' ] ) && strpos ( $ options [ 'ip' ] , '/' ) === 0 ) { return ( boolean ) preg_match ( $ options [ 'ip' ] , $ request -> env ( 'REMOTE_ADDR' ) ) ; } if ( is_array ( $ options [ 'ip' ] ) ) { return in_array ( $ request -> env ( 'REMOTE_ADDR' ) , $ options [ 'ip' ] ) ; } return $ request -> env ( 'REMOTE_ADDR' ) === $ options [ 'ip' ] ; } ] ] ; }
Initializes default rules to use .
47,488
public function check ( $ user , $ request , array $ options = [ ] ) { $ defaults = [ 'rules' => $ this -> _defaults , 'allowAny' => $ this -> _allowAny ] ; $ options += $ defaults ; if ( empty ( $ options [ 'rules' ] ) ) { throw new RuntimeException ( "Missing `'rules'` option." ) ; } $ rules = ( array ) $ options [ 'rules' ] ; $ this -> _error = [ ] ; $ params = array_diff_key ( $ options , $ defaults ) ; if ( ! isset ( $ user ) && is_callable ( $ this -> _user ) ) { $ user = $ this -> _user -> __invoke ( ) ; } foreach ( $ rules as $ name => $ rule ) { $ result = $ this -> _check ( $ user , $ request , $ name , $ rule , $ params ) ; if ( $ result === false && ! $ options [ 'allowAny' ] ) { return false ; } if ( $ result === true && $ options [ 'allowAny' ] ) { return true ; } } return ! $ options [ 'allowAny' ] ; }
The check method
47,489
public function realWalk ( $ oid , $ suffixAsKey = false ) { try { $ return = $ this -> _lastResult = $ this -> _session -> walk ( $ oid , $ suffixAsKey ) ; } catch ( Exception $ exc ) { $ this -> close ( ) ; throw new Exception ( "Erro '{$this->_session->getError()}' with execute WALK OID ({$oid}): " . $ exc -> getMessage ( ) ) ; } return $ return ; }
Proxy to the snmp2_real_walk command
47,490
public function realWalkToArray ( $ oid , $ suffixAsKey = false ) { $ arrayData = $ this -> realWalk ( $ oid , $ suffixAsKey ) ; foreach ( $ arrayData as $ _oid => $ value ) { $ this -> _lastResult [ $ _oid ] = $ this -> parseSnmpValue ( $ value ) ; } return $ this -> _lastResult ; }
Proxy to the snmp2_real_walk command return array
47,491
public function realWalk1d ( $ oid ) { $ arrayData = $ this -> realWalk ( $ oid ) ; $ result = array ( ) ; foreach ( $ arrayData as $ _oid => $ value ) { $ oidPrefix = substr ( $ _oid , 0 , strrpos ( $ _oid , '.' ) ) ; if ( ! isset ( $ result [ $ oidPrefix ] ) ) { $ result [ $ oidPrefix ] = Array ( ) ; } $ aIndexOid = str_replace ( $ oidPrefix . "." , "" , $ _oid ) ; $ result [ $ oidPrefix ] [ $ aIndexOid ] = $ this -> parseSnmpValue ( $ value ) ; } return $ result ; }
Get indexed Real Walk return values
47,492
public function get ( $ oid , $ preserveKeys = false ) { if ( $ this -> cache ( ) && ( $ rtn = $ this -> getCache ( ) -> load ( $ oid ) ) !== null ) { return $ rtn ; } try { $ this -> _lastResult = $ this -> _session -> get ( $ oid , $ preserveKeys ) ; } catch ( Exception $ exc ) { $ this -> close ( ) ; throw new Exception ( "Erro '{$this->_session->getError()}' with execute GET OID ({$oid}): " . $ exc -> getMessage ( ) ) ; } if ( $ this -> _lastResult === false ) { $ this -> close ( ) ; throw new Exception ( 'Could not perform walk for OID ' . $ oid ) ; } return $ this -> getCache ( ) -> save ( $ oid , $ this -> parseSnmpValue ( $ this -> _lastResult ) ) ; }
Get a single SNMP value
47,493
public function subOidWalk ( $ oid , $ position , $ elements = 1 ) { if ( $ this -> cache ( ) && ( $ rtn = $ this -> getCache ( ) -> load ( $ oid ) ) !== null ) { return $ rtn ; } $ this -> _lastResult = $ this -> realWalk ( $ oid ) ; if ( $ this -> _lastResult === false ) { $ this -> close ( ) ; throw new Exception ( 'Could not perform walk for OID ' . $ oid ) ; } $ result = array ( ) ; foreach ( $ this -> _lastResult as $ _oid => $ value ) { $ oids = explode ( '.' , $ _oid ) ; $ index = $ oids [ $ position ] ; for ( $ pos = $ position + 1 ; $ pos < sizeof ( $ oids ) && ( $ elements == - 1 || $ pos < $ position + $ elements ) ; $ pos ++ ) { $ index .= '.' . $ oids [ $ pos ] ; } $ result [ $ index ] = $ this -> parseSnmpValue ( $ value ) ; } return $ this -> getCache ( ) -> save ( $ oid , $ result ) ; }
Get indexed SNMP values where the array key is the given position of the OID
47,494
public function walkIPv4 ( $ oid ) { if ( $ this -> cache ( ) && ( $ rtn = $ this -> getCache ( ) -> load ( $ oid ) ) !== null ) { return $ rtn ; } $ this -> _lastResult = $ this -> realWalk ( $ oid ) ; if ( $ this -> _lastResult === false ) { throw new Exception ( 'Could not perform walk for OID ' . $ oid ) ; } $ result = array ( ) ; foreach ( $ this -> _lastResult as $ _oid => $ value ) { $ oids = explode ( '.' , $ _oid ) ; $ len = count ( $ oids ) ; $ result [ $ oids [ $ len - 4 ] . '.' . $ oids [ $ len - 3 ] . '.' . $ oids [ $ len - 2 ] . '.' . $ oids [ $ len - 1 ] ] = $ this -> parseSnmpValue ( $ value ) ; } return $ this -> getCache ( ) -> save ( $ oid , $ result ) ; }
Get indexed SNMP values where they are indexed by IPv4 addresses
47,495
public function parseSnmpValue ( $ v ) { if ( $ v == '""' || $ v == '' ) { return "" ; } $ type = substr ( $ v , 0 , strpos ( $ v , ':' ) ) ; $ value = trim ( substr ( $ v , strpos ( $ v , ':' ) + 1 ) ) ; switch ( $ type ) { case 'STRING' : if ( substr ( $ value , 0 , 1 ) == '"' ) { $ rtn = ( string ) trim ( substr ( substr ( $ value , 1 ) , 0 , - 1 ) ) ; } else { $ rtn = ( string ) $ value ; } break ; case 'INTEGER' : if ( ! is_numeric ( $ value ) ) { preg_match ( '/\d/' , $ value , $ m , PREG_OFFSET_CAPTURE ) ; $ rtn = ( int ) substr ( $ value , $ m [ 0 ] [ 1 ] ) ; } else { $ rtn = ( int ) $ value ; } break ; case 'Counter32' : $ rtn = ( int ) $ value ; break ; case 'Counter64' : $ rtn = ( int ) $ value ; break ; case 'Gauge32' : $ rtn = ( int ) $ value ; break ; case 'Hex-STRING' : $ rtn = ( string ) implode ( '' , explode ( ' ' , preg_replace ( '/[^A-Fa-f0-9]/' , '' , $ value ) ) ) ; break ; case 'IpAddress' : $ rtn = ( string ) $ value ; break ; case 'OID' : $ rtn = ( string ) $ value ; break ; case 'Timeticks' : $ rtn = ( int ) substr ( $ value , 1 , strrpos ( $ value , ')' ) - 1 ) ; break ; default : throw new Exception ( "ERR: Unhandled SNMP return type: $type\n" ) ; } return $ rtn ; }
Parse the result of an SNMP query into a PHP type
47,496
public function setHost ( $ h ) { $ this -> _host = $ h ; $ this -> _lastResult = null ; unset ( $ this -> _resultCache ) ; $ this -> _resultCache = array ( ) ; return $ this ; }
Sets the target host for SNMP queries .
47,497
public function getCache ( ) { if ( $ this -> _cache === null ) { $ this -> _cache = new \ Cityware \ Snmp \ Cache \ Basic ( ) ; } return $ this -> _cache ; }
Get the cache in use ( or create a Cache \ Basic instance
47,498
public function useExtension ( $ mib , $ args ) { $ mib = '\\Cityware\\Snmp\\MIBS\\' . str_replace ( '_' , '\\' , $ mib ) ; $ m = new $ mib ( ) ; $ m -> setSNMP ( $ this ) ; return $ m ; }
This is the MIB Extension magic
47,499
public function subOidWalkLong ( $ oid , $ positionS , $ positionE ) { if ( $ this -> cache ( ) && ( $ rtn = $ this -> getCache ( ) -> load ( $ oid ) ) !== null ) { return $ rtn ; } $ this -> _lastResult = $ this -> realWalk ( $ oid ) ; if ( $ this -> _lastResult === false ) { throw new Exception ( 'Could not perform walk for OID ' . $ oid ) ; } $ result = array ( ) ; foreach ( $ this -> _lastResult as $ _oid => $ value ) { $ oids = explode ( '.' , $ _oid ) ; $ oidKey = '' ; for ( $ i = $ positionS ; $ i <= $ positionE ; $ i ++ ) { $ oidKey .= $ oids [ $ i ] . '.' ; } $ result [ $ oidKey ] = $ this -> parseSnmpValue ( $ value ) ; } return $ this -> getCache ( ) -> save ( $ oid , $ result ) ; }
Get indexed SNMP values where the array key is spread over a number of OID positions