idx
int64 0
60.3k
| question
stringlengths 64
4.24k
| target
stringlengths 5
618
|
|---|---|---|
15,800
|
public function first ( ) { $ this -> getIterator ( ) -> rewind ( ) ; return $ this -> getIterator ( ) -> count ( ) ? $ this -> getIterator ( ) -> current ( ) : false ; }
|
Gets the first item from the collection .
|
15,801
|
public function getPhotoEmail ( ) { $ email = false ; $ emailType = Yii :: $ app -> collectors [ 'types' ] -> getOne ( 'EmailAddress' ) ; if ( empty ( $ emailType -> object ) ) { return false ; } foreach ( $ this -> children ( $ emailType -> object -> primaryModel , [ 'where' => [ 'primary_child' => 1 ] ] ) as $ child ) { $ email = $ child -> email_address ; break ; } if ( ! empty ( $ email ) && substr ( $ email , - 6 ) !== ".local" ) { return $ email ; } return false ; }
|
Get photo email .
|
15,802
|
public static function loadSimpleXML ( $ xml_file , $ verify_dtd = true ) { $ options = ( $ verify_dtd ? LIBXML_DTDVALID : null ) ; libxml_clear_errors ( ) ; $ SimpleXML = @ simplexml_load_file ( $ xml_file , null , $ options ) ; $ LibXMLError = libxml_get_last_error ( ) ; if ( $ SimpleXML === false || $ LibXMLError instanceof \ LibXMLError ) { if ( $ LibXMLError instanceof \ LibXMLError ) { $ xml_base = basename ( $ LibXMLError -> file ) ; throw new XMLException ( "{$LibXMLError->message} in $xml_base on line {$LibXMLError->line}" ) ; } else { $ xml_base = basename ( $ xml_file ) ; throw new XMLException ( "SimpleXML failed to load $xml_base, unknown error" ) ; } } return $ SimpleXML ; }
|
Load and verify an XML - file using SimpleXML .
|
15,803
|
public static function Gst00a ( $ uta , $ utb , $ tta , $ ttb ) { $ gmst00 ; $ ee00a ; $ gst ; $ gmst00 = IAU :: Gmst00 ( $ uta , $ utb , $ tta , $ ttb ) ; $ ee00a = IAU :: Ee00a ( $ tta , $ ttb ) ; $ gst = IAU :: Anp ( $ gmst00 + $ ee00a ) ; return $ gst ; }
|
- - - - - - - - - - i a u G s t 0 0 a - - - - - - - - - -
|
15,804
|
public function addPermission ( $ permission ) { if ( is_array ( $ permission ) || $ permission instanceof \ Traversable ) return $ this -> addMultiplePermissions ( $ permission ) ; else return $ this -> addSinglePermission ( $ permission ) ; }
|
Add a permission to the role . The argument can be the permission name ID Permission object or an array of the previous
|
15,805
|
public function addSinglePermission ( $ permission ) { if ( is_string ( $ permission ) ) return $ this -> addPermissionByName ( $ permission ) ; elseif ( is_numeric ( $ permission ) ) return $ this -> addPermissionById ( $ permission ) ; elseif ( $ permission instanceof BridgePermission ) return $ this -> addPermissionByObject ( $ permission ) ; else throw new \ InvalidArgumentException ( 'Permission must be a name, ID, or Permission object.' ) ; }
|
Add a single permission . The argument is a string integer or instance of BridgePermission
|
15,806
|
public function addPermissionByName ( $ permission_name ) { $ permission = static :: $ app [ 'db' ] -> connection ( ) -> table ( 'permissions' ) -> where ( 'name' , '=' , $ permission_name ) -> first ( ) ; if ( ! $ permission ) return new \ RuntimeException ( 'No permission with that name found.' ) ; if ( is_array ( $ permission ) ) return $ this -> addPermissionById ( $ permission [ 'id' ] ) ; elseif ( is_object ( $ permission ) ) return $ this -> addPermissionById ( $ permission -> id ) ; else throw new \ UnexpectedValueException ( 'Value returned not array or instance of BridgePermission.' ) ; }
|
Add a single permission to the role by name
|
15,807
|
public function addPermissionByObject ( BridgePermission $ permission_obj ) { if ( ! $ permission_obj -> exists ) $ permission_obj -> save ( ) ; $ permission_id = $ permission_obj -> getKey ( ) ; return $ this -> addPermissionById ( $ permission_id ) ; }
|
Add a single permission to the role by using the Permission object
|
15,808
|
public function hasPermission ( $ permission ) { $ permissions = $ this -> permissions ; foreach ( $ permissions as $ permission_obj ) if ( $ this -> checkPermission ( $ permission , $ permission_obj ) ) return true ; return false ; }
|
Checks to see if a role has a certain permission
|
15,809
|
public function checkPermission ( $ check , BridgePermission $ has ) { if ( is_string ( $ check ) ) return $ this -> checkPermissionByName ( $ check , $ has ) ; elseif ( is_numeric ( $ check ) ) return $ this -> checkPermissionById ( $ check , $ has ) ; elseif ( $ check instanceof BridgePermission ) return $ this -> checkPermissionByObject ( $ check , $ has ) ; else throw new \ InvalidArgumentException ( 'Permission to check must be a name, ID, or Permission object.' ) ; }
|
Checks to see if a given permission is equal to a permission the user already has
|
15,810
|
public function checkPermissionByObject ( BridgePermission $ check , BridgePermission $ has ) { return $ this -> checkPermissionById ( $ check -> id , $ has ) ; }
|
Check to see if the Permission provided is the same as the BridgePermission object passed in
|
15,811
|
public function query ( $ statement , $ fetchMode = null , $ modeArg = null , array $ ctorArgs = array ( ) ) { $ stmt = $ this -> prepare ( $ statement ) ; $ stmt -> execute ( ) ; if ( $ fetchMode ) { $ stmt -> setFetchMode ( $ fetchMode , $ modeArg , $ ctorArgs ) ; } return $ stmt ; }
|
Executes an SQL statement returning the results as a Vincent \ Pdo \ Oci8 \ Statement object .
|
15,812
|
public function constructInnerJoinSql ( Table $ fromTable , $ usingThrough = false , $ alias = null ) { if ( $ usingThrough ) { $ joinTable = $ fromTable ; $ joinTableName = $ fromTable -> getFullyQualifiedTableName ( ) ; $ fromTableName = Table :: load ( $ this -> className ) -> getFullyQualifiedTableName ( ) ; } else { $ joinTable = Table :: load ( $ this -> className ) ; $ joinTableName = $ joinTable -> getFullyQualifiedTableName ( ) ; $ fromTableName = $ fromTable -> getFullyQualifiedTableName ( ) ; } if ( $ this instanceof HasMany || $ this instanceof HasOne ) { $ this -> setKeys ( $ fromTable -> class -> getName ( ) ) ; if ( $ usingThrough ) { $ foreignKey = $ this -> primaryKey [ 0 ] ; $ joinPrimaryKey = $ this -> foreignKey [ 0 ] ; } else { $ joinPrimaryKey = $ this -> foreignKey [ 0 ] ; $ foreignKey = $ this -> primaryKey [ 0 ] ; } } else { $ foreignKey = $ this -> foreignKey [ 0 ] ; $ joinPrimaryKey = $ this -> primaryKey [ 0 ] ; } if ( ! is_null ( $ alias ) ) { $ aliasedJoinTableName = $ alias = $ this -> getTable ( ) -> conn -> quoteName ( $ alias ) ; $ alias .= ' ' ; } else $ aliasedJoinTableName = $ joinTableName ; return "INNER JOIN $joinTableName {$alias}ON($fromTableName.$foreignKey = $aliasedJoinTableName.$joinPrimaryKey)" ; }
|
Creates INNER JOIN SQL for associations .
|
15,813
|
private function getForeignKeyForNewAssociation ( Model $ model ) { $ this -> setKeys ( $ model ) ; $ primaryKey = Inflector :: instance ( ) -> variablize ( $ this -> foreignKey [ 0 ] ) ; return array ( $ primaryKey => $ model -> id , ) ; }
|
Get an array containing the key and value of the foreign key for the association
|
15,814
|
private function getInstance ( ) { if ( is_null ( $ this -> instance ) ) { $ this -> instance = \ RegexGuard \ Factory :: getGuard ( ) ; } return $ this -> instance ; }
|
Returns an instance of the library
|
15,815
|
public function match ( $ pattern , $ subject ) { if ( ! $ this -> validate ( $ pattern ) ) { return false ; } return $ this -> getInstance ( ) -> match ( $ pattern , $ subject ) ; }
|
Matches a regular expression
|
15,816
|
private function getWords ( string $ template ) : array { $ flags = PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY ; return ( array ) preg_split ( self :: WORD_DELIMITER , $ template , - 1 , $ flags ) ; }
|
Devuelve una lista con las palabras que componen la linea
|
15,817
|
private function getTokens ( string $ word ) : array { $ flags = PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY ; return ( array ) preg_split ( self :: TOKEN_DELIMITER , $ word , - 1 , $ flags ) ; }
|
Devuelve los tokens que componen una palabra
|
15,818
|
public function parse ( callable $ callback , int $ width ) : string { $ tokens = [ ] ; foreach ( $ this as $ token ) { $ token -> setLineWidth ( $ width ) ; $ tokens [ ] = call_user_func ( $ callback , $ token ) ; } return implode ( '' , $ tokens ) ; }
|
Devuelve esta linea en forma de string usando un callback para resolver cada token
|
15,819
|
public function getWidth ( ) : int { $ total = 0 ; foreach ( $ this as $ token ) { $ total += $ token -> width ( ) ; } return $ total ; }
|
Devuelve el ancho del linea
|
15,820
|
public function handle ( UploadedFile $ uploadedFile , $ folderId , $ userId ) { $ uploadFileSource = new UploadedFileSource ( $ uploadedFile ) ; $ volume = $ this -> volumeManager -> getByFolderId ( $ folderId ) ; $ folder = $ volume -> findFolder ( $ folderId ) ; $ file = $ volume -> findFileByPath ( $ folder -> getPath ( ) . '/' . $ uploadFileSource -> getName ( ) ) ; $ originalFileId = null ; if ( $ file ) { $ originalFileId = $ file -> getId ( ) ; } $ useWizard = $ this -> useWizard ( $ uploadFileSource ) ; if ( $ originalFileId || $ useWizard ) { return $ this -> tempStorage -> store ( $ uploadFileSource , $ folderId , $ userId , $ originalFileId , $ useWizard ) ; } $ file = $ volume -> createFile ( $ folder , $ uploadFileSource , array ( ) , $ userId ) ; return $ file ; }
|
Handle upload .
|
15,821
|
public function getVisits ( $ items ) { $ result = [ ] ; foreach ( $ items as $ item ) { $ result [ ] = new Visit ( $ item ) ; } return $ result ; }
|
Returns array of visits .
|
15,822
|
protected function loadModule ( ) : void { $ fqn = $ this -> getFullyQualifiedClass ( $ this -> response -> getModule ( ) , $ this -> response -> getController ( ) ) ; $ the_module = new $ fqn ( ) ; call_user_func_array ( array ( $ the_module , $ this -> getActionMethodName ( $ this -> response -> getAction ( ) ) ) , [ $ this -> response -> getVariables ( ) ] ) ; }
|
Load a module as requested and mapped by the router .
|
15,823
|
protected function loadErrorModule ( ) : void { $ fqn = $ this -> getFullyQualifiedClass ( 'index' , 'index' ) ; $ the_module = new $ fqn ( ) ; $ action = $ this -> getActionMethodName ( ( string ) $ this -> response -> getStatusCode ( ) ) ; if ( method_exists ( $ fqn , $ action ) ) { call_user_func_array ( array ( $ the_module , $ action ) , [ $ this -> response -> getVariables ( ) ] ) ; } else { call_user_func_array ( array ( $ the_module , $ this -> getActionMethodName ( 'index' ) ) , [ ] ) ; } }
|
Load an error module based on the error code .
|
15,824
|
protected function getFullyQualifiedClass ( string $ module_name , string $ controller_class ) : string { return 'Application\\Module\\' . $ this -> getModuleName ( $ module_name ) . '\\Controller\\' . $ this -> getControllerName ( $ controller_class ) ; }
|
Get the fully qualified class name of the controller .
|
15,825
|
protected function getConnection ( $ nameDB = NULL ) { if ( self :: $ config_db == NULL ) { self :: $ config_db = $ this -> context -> readConfigurationFile ( $ this -> configFile ) ; } if ( $ nameDB == NULL ) $ nameDB = self :: $ config_db [ 'actual-db' ] ; $ cbd = self :: $ config_db [ $ nameDB ] ; $ this -> currentDB = $ nameDB ; $ this -> currentConfiguration = & self :: $ config_db [ $ nameDB ] ; try { $ dsn = $ cbd [ 'driverbd' ] . ':' ; if ( $ cbd [ 'driverbd' ] == "sqlite" ) { $ dsn .= $ cbd [ 'database' ] ; $ gbd = new \ PDO ( $ dsn ) ; } else { $ dsn .= 'host=' . $ cbd [ 'hostname' ] . ';port=' . $ cbd [ 'port' ] ; if ( isset ( $ cbd [ 'database' ] ) ) { $ dsn .= ';dbname=' . $ cbd [ 'database' ] ; } if ( $ cbd [ 'user' ] == "" ) { $ cbd [ 'user' ] = NULL ; $ cbd [ 'pass' ] = NULL ; } $ gbd = new \ PDO ( $ dsn , $ cbd [ 'user' ] , $ cbd [ 'pass' ] , array ( \ PDO :: ATTR_PERSISTENT => $ cbd [ 'persistent' ] ) ) ; $ gbd -> exec ( "SET NAMES '" . $ cbd [ 'charset' ] . "'" ) ; } if ( $ this -> context -> getEnvironment ( ) == 'development' ) { $ gbd -> setAttribute ( \ PDO :: ATTR_ERRMODE , \ PDO :: ERRMODE_EXCEPTION ) ; } else { $ gbd -> setAttribute ( \ PDO :: ATTR_ERRMODE , \ PDO :: ERRMODE_SILENT ) ; } return $ gbd ; } catch ( \ PDOException $ e ) { throw $ e ; } }
|
Abre una conexion en base a la configuracion de la BD
|
15,826
|
protected function catchError ( $ error ) { if ( $ this -> connection -> inTransaction ( ) ) { $ this -> errorTran [ ] = $ error ; $ this -> stateTran = FALSE ; } $ this -> lastError = $ error ; }
|
Almacena los errores
|
15,827
|
public function connect ( $ nameDB = NULL , $ configFile = NULL ) { if ( $ configFile != NULL ) { $ this -> configFile = $ configFile ; self :: $ config_db = NULL ; } $ this -> connection = $ this -> getConnection ( $ nameDB ) ; }
|
Realiza la conexion a la base indicada o por defecto
|
15,828
|
public function select ( $ select , $ distinct = FALSE ) { if ( $ distinct ) { $ this -> select = 'DISTINCT ' ; } else { $ this -> select = '' ; } $ this -> select .= $ select ; }
|
Arma el Select de la consulta
|
15,829
|
public function where ( $ conditions , array $ values ) { if ( $ this -> where != '' ) { $ this -> where .= 'AND ' ; } $ this -> where .= $ conditions . ' ' ; $ this -> where_values = array_merge ( $ this -> where_values , $ values ) ; }
|
Arma el where de la consulta
|
15,830
|
public function where_like ( $ field , $ match , $ joker = 'both' , $ not = FALSE ) { if ( $ this -> where != '' ) { $ this -> where .= 'AND ' ; } $ this -> like ( $ field , $ match , $ joker , $ not ) ; }
|
Arma el where like de la consutla
|
15,831
|
protected function like ( $ field , $ match , $ joker = 'both' , $ not = FALSE ) { $ this -> where .= $ field . ' ' ; if ( $ not ) { $ this -> where .= 'NOT ' ; } $ this -> where .= 'LIKE ' ; switch ( $ joker ) { case 'both' : $ this -> where .= "'%$match%' " ; break ; case 'after' : $ this -> where .= "'$match%' " ; break ; case 'before' : $ this -> where .= "'%$match' " ; break ; } }
|
Arma el Like para el where and o or
|
15,832
|
public function where_in ( $ field , array $ values , $ not = FALSE ) { if ( $ this -> where != '' ) { $ this -> where .= 'AND ' ; } $ this -> in ( $ field , $ values , $ not ) ; }
|
Arma el where in de la consulta
|
15,833
|
public function or_where_in ( $ field , array $ values , $ not = FALSE ) { if ( $ this -> where != '' ) { $ this -> where .= 'OR ' ; } $ this -> in ( $ field , $ values , $ not ) ; }
|
Arma el where in con or de la consulta
|
15,834
|
protected function in ( $ field , array $ values , $ not = FALSE ) { $ this -> where .= $ field . ' ' ; if ( $ not ) { $ this -> where .= 'NOT ' ; } $ this -> where .= 'IN (' ; foreach ( $ values as $ value ) { $ this -> where .= "'$value'," ; } $ this -> where = rtrim ( $ this -> where , ',' ) ; $ this -> where .= ') ' ; }
|
Arma el in para el where and o or
|
15,835
|
public function group ( $ group ) { if ( is_array ( $ group ) ) { $ this -> group = 'GROUP BY ' ; foreach ( $ group as $ value ) { $ this -> group .= $ value . ',' ; } $ this -> group = rtrim ( $ this -> group , ',' ) ; $ this -> group .= ' ' ; } else { $ this -> group = 'GROUP BY ' . $ group . ' ' ; } }
|
Arma el group de la consulta
|
15,836
|
public function having ( $ conditions , array $ values ) { if ( $ this -> having != '' ) { $ this -> having .= 'AND ' ; } $ this -> having .= $ conditions . ' ' ; $ this -> where_values = array_merge ( $ this -> where_values , $ values ) ; }
|
Arma el having de la consulta
|
15,837
|
public function get ( ) { $ res = FALSE ; try { $ query = $ this -> prepareSelect ( $ this -> select , $ this -> from , $ this -> where , $ this -> group , $ this -> having , $ this -> order , $ this -> limit ) ; $ query -> execute ( $ this -> where_values ) ; if ( $ this -> isOk ( $ query ) ) { $ res = $ query ; } $ this -> cleanVars ( ) ; } catch ( \ PDOException $ e ) { $ this -> cleanVars ( ) ; throw $ e ; } return $ res ; }
|
Devuelve el resultado de la consulta armada de forma ActiveRecord
|
15,838
|
public function getFromWhere ( $ from , $ where = NULL , $ where_values = array ( ) , $ order = NULL , $ limit = NULL , $ offset = NULL ) { $ res = FALSE ; try { if ( $ order != NULL ) { $ order = " ORDER BY " . $ order ; } if ( $ limit != NULL ) { $ limit = " LIMIT " . $ limit ; if ( $ offset != NULL ) { $ limit .= ' OFFSET ' . $ offset ; } } $ query = $ this -> prepareSelect ( $ this -> select , $ from , $ where , '' , '' , $ order , $ limit ) ; $ query -> execute ( $ where_values ) ; if ( $ this -> isOk ( $ query ) ) { $ res = $ query ; } $ this -> cleanVars ( ) ; } catch ( \ PDOException $ e ) { $ this -> cleanVars ( ) ; throw $ e ; } return $ res ; }
|
Devuelve el resultado de la consulta armada en base a los parametros
|
15,839
|
public function insert ( $ table , array $ values ) { try { $ query = $ this -> prepareInsert ( $ table , $ values ) ; $ query -> execute ( $ values ) ; return $ this -> isOk ( $ query ) ; } catch ( \ PDOException $ e ) { throw $ e ; } }
|
Inserta en una tabla los valores indicados
|
15,840
|
public function insertMany ( $ table , array $ manyValues ) { try { reset ( $ manyValues ) ; if ( current ( $ manyValues ) != FALSE ) { $ query = $ this -> prepareInsert ( $ table , $ manyValues [ 0 ] ) ; } $ ok = true ; while ( current ( $ manyValues ) != FALSE && $ ok ) { $ query -> execute ( current ( $ manyValues ) ) ; $ ok = $ this -> isOk ( $ query ) ; next ( $ manyValues ) ; } return $ ok ; } catch ( \ PDOException $ e ) { throw $ e ; } }
|
Inserta en una tabla un conjunto de valores indicados . Cada elemento del vector guardado debe tener la misma estructura
|
15,841
|
public function update ( $ table , array $ values ) { $ res = FALSE ; try { $ query = $ this -> prepareUpdate ( $ table , $ values , $ this -> where ) ; $ values = array_merge ( $ values , $ this -> where_values ) ; $ query -> execute ( $ values ) ; $ res = $ this -> isOk ( $ query ) ; $ this -> cleanVars ( ) ; } catch ( \ PDOException $ e ) { $ this -> cleanVars ( ) ; throw $ e ; } return $ res ; }
|
Actualiza una tabla en base a los datos indicados y la consulta armada al estilo Active Record
|
15,842
|
public function delete ( $ table ) { $ res = FALSE ; try { $ query = $ this -> prepareDelete ( $ table , $ this -> where ) ; $ query -> execute ( $ this -> where_values ) ; $ res = $ this -> isOk ( $ query ) ; $ this -> cleanVars ( ) ; } catch ( \ PDOException $ e ) { $ this -> cleanVars ( ) ; throw $ e ; } return $ res ; }
|
Elimina tuplas de una tabla en base a la consulta armada de la forma Active Record
|
15,843
|
protected function isOk ( \ PDOStatement $ query ) { $ error = $ query -> errorInfo ( ) ; if ( $ error [ 0 ] == '00000' ) { return TRUE ; } else { $ this -> catchError ( $ error ) ; return FALSE ; } }
|
Retorna si la consulta se realizao con exito si no ocurrio ningun error .
|
15,844
|
protected function cleanVars ( ) { $ this -> select = "*" ; $ this -> from = '' ; $ this -> where = '' ; $ this -> where_values = array ( ) ; $ this -> group = '' ; $ this -> having = '' ; $ this -> order = '' ; $ this -> limit = '' ; }
|
Limpia las variables de instancia del ActiveRecord
|
15,845
|
protected function prepareSelect ( $ select , $ from , $ where = '' , $ group = '' , $ having = '' , $ order = '' , $ limit = '' ) { $ sql = "SELECT " . $ select ; $ sql .= " FROM " . $ from ; if ( $ where != '' && $ where != NULL ) { $ sql .= " WHERE " . $ where ; } $ sql .= $ group ; if ( $ having != '' && $ having != NULL ) { $ sql .= " HAVING " . $ having ; } $ sql .= $ order ; $ sql .= $ limit ; return $ this -> connection -> prepare ( $ sql ) ; }
|
Retorna un PDOStatement SELECT armado en base a los parametros pasados
|
15,846
|
protected function prepareInsert ( $ table , $ values ) { $ sql = 'INSERT INTO ' . $ table . ' (' ; $ value = 'values(' ; foreach ( $ values as $ key => $ val ) { $ sql .= $ key . ',' ; $ value .= ':' . $ key . ',' ; } $ sql = trim ( $ sql , ',' ) ; $ value = trim ( $ value , ',' ) ; $ sql .= ') ' . $ value . ')' ; return $ this -> connection -> prepare ( $ sql ) ; }
|
Retorna un PDOStatement INSERT armado en base a los parametros pasados
|
15,847
|
protected function prepareUpdate ( $ table , $ values , $ where ) { $ sql = 'UPDATE ' . $ table . ' SET ' ; foreach ( $ values as $ key => $ value ) { $ sql .= $ key . '=:' . $ key . ',' ; } $ sql = trim ( $ sql , ',' ) ; if ( $ where != '' ) { $ sql .= " WHERE " . $ where ; } return $ this -> connection -> prepare ( $ sql ) ; }
|
Retorna un PDOStatement UPDATE armado en base a los parametros pasados
|
15,848
|
protected function prepareDelete ( $ table , $ where ) { $ sql = 'DELETE FROM ' . $ table . ' ' ; if ( $ where != '' ) { $ sql .= " WHERE " . $ where ; } return $ this -> connection -> prepare ( $ sql ) ; }
|
Retorna un PDOStatement DELETE armado en base a los parametros pasados
|
15,849
|
public function set ( int $ id ) : bool { if ( ! $ this -> isAllowed ( ) ) { return false ; } $ hash = $ this -> hasher -> hash ( $ id ) ; $ uniqid = uniqid ( ) ; $ this -> session -> setExpiration ( '5 minutes' ) ; $ this -> session -> $ uniqid = $ hash ; $ this -> id = $ uniqid ; $ this -> presenter -> redirect ( $ this -> redirect ) ; return true ; }
|
Nastavi testovaci ucet a presmeruje
|
15,850
|
protected function validateIndex ( $ index , $ indexType ) { if ( is_null ( $ this -> resultMap ) ) { if ( ! array_key_exists ( $ index , $ this -> columnTypes ) ) { if ( is_numeric ( $ index ) && array_key_exists ( intval ( $ index ) , $ this -> columnTypes ) ) $ index = intval ( $ index ) ; else throw new \ UnexpectedValueException ( "Index column '$index' not found" ) ; } $ indexColumn = $ index ; $ indexType = is_null ( $ indexType ) ? $ this -> columnTypes [ $ index ] : $ indexType ; $ indexTypeHandler = $ this -> typeManager -> getTypeHandler ( $ indexType ) ; if ( $ indexTypeHandler === false ) throw new \ UnexpectedValueException ( "Unknown type '$indexType' defined for index '$index'" ) ; } else { if ( ! array_key_exists ( $ index , $ this -> properties ) ) throw new \ UnexpectedValueException ( "Index property '$index' was not found in result map" ) ; $ indexColumn = $ this -> properties [ $ index ] -> getColumn ( ) ; $ indexTypeHandler = $ this -> typeHandlers [ $ index ] ; } return [ $ indexColumn , $ indexTypeHandler ] ; }
|
Validates a user defined index againts current result
|
15,851
|
protected function validateGroup ( $ group , $ groupType ) { if ( is_null ( $ this -> resultMap ) ) { if ( ! array_key_exists ( $ group , $ this -> columnTypes ) ) { if ( is_numeric ( $ group ) && array_key_exists ( intval ( $ group ) , $ this -> columnTypes ) ) $ group = intval ( $ group ) ; else throw new \ UnexpectedValueException ( "Group column '$group' not found" ) ; } $ groupType = is_null ( $ groupType ) ? $ this -> columnTypes [ $ group ] : $ groupType ; $ groupColumn = $ group ; $ groupTypeHandler = $ this -> typeManager -> getTypeHandler ( $ groupType ) ; if ( $ groupTypeHandler === false ) throw new \ UnexpectedValueException ( "Unknown type '$groupType' defined for group '$group'" ) ; } else { if ( ! array_key_exists ( $ group , $ this -> properties ) ) throw new \ UnexpectedValueException ( "Group property '$group' was not found in result map" ) ; $ groupColumn = $ this -> properties [ $ group ] -> getColumn ( ) ; $ groupTypeHandler = $ this -> typeHandlers [ $ group ] ; } return [ $ groupColumn , $ groupTypeHandler ] ; }
|
Validates a user defined group against current result
|
15,852
|
protected function buildTypeHandlerList ( ) { foreach ( $ this -> properties as $ name => $ propertyProfile ) { $ column = $ propertyProfile -> getColumn ( ) ; if ( ! array_key_exists ( $ column , $ this -> columnTypes ) ) continue ; $ this -> availableColumns [ $ name ] = $ column ; $ type = $ propertyProfile -> getType ( ) ; if ( isset ( $ type ) ) { $ typeHandler = $ this -> typeManager -> getTypeHandler ( $ type ) ; if ( $ typeHandler == false ) throw new \ UnexpectedValueException ( "No typehandler assigned to type '$type' defined at property $name" ) ; $ this -> typeHandlers [ $ name ] = $ typeHandler ; } else { $ type = $ this -> columnTypes [ $ column ] ; $ this -> typeHandlers [ $ name ] = $ this -> typeManager -> getTypeHandler ( $ type ) ; } } }
|
Builds a list of type handlers for the available columns
|
15,853
|
public function processResponse ( ResponseInterface $ response , SystemEvent $ event ) { if ( $ event -> getName ( ) === SystemEvent :: FINISH ) { $ event -> stopPropagation ( true ) ; $ server = $ this -> getServer ( ) ; $ emitter = $ server -> getEmitter ( ) ; $ emitter -> emit ( $ response ) ; return ; } $ events = $ this -> getEvents ( ) ; $ event -> setResult ( SystemEvent :: FINISH , $ response ) ; $ events -> trigger ( $ event ( SystemEvent :: FINISH ) ) ; }
|
Processes the response .
|
15,854
|
public static function add ( $ objectType , $ objectId = null , $ action = null , $ fieldName = null , $ oldValue = null , $ newValue = null , $ userId = 0 , $ content = '' ) { global $ PPHP ; $ db = $ PPHP [ 'db' ] ; $ ip = '127.0.0.1' ; $ req = grab ( 'request' ) ; if ( isset ( $ req [ 'remote_addr' ] ) ) { $ ip = $ req [ 'remote_addr' ] ; } ; if ( is_array ( $ objectType ) ) { if ( isset ( $ objectType [ 'objectId' ] ) ) $ objectId = $ objectType [ 'objectId' ] ; if ( isset ( $ objectType [ 'action' ] ) ) $ action = $ objectType [ 'action' ] ; if ( isset ( $ objectType [ 'fieldName' ] ) ) $ fieldName = $ objectType [ 'fieldName' ] ; if ( isset ( $ objectType [ 'oldValue' ] ) ) $ oldValue = $ objectType [ 'oldValue' ] ; if ( isset ( $ objectType [ 'newValue' ] ) ) $ newValue = $ objectType [ 'newValue' ] ; if ( isset ( $ objectType [ 'userId' ] ) ) $ userId = $ objectType [ 'userId' ] ; if ( isset ( $ objectType [ 'content' ] ) ) $ content = $ objectType [ 'content' ] ; if ( isset ( $ objectType [ 'objectType' ] ) ) { $ objectType = $ objectType [ 'objectType' ] ; } else { $ objectType = null ; } ; } ; if ( $ objectType === null && $ objectId === null && $ PPHP [ 'contextType' ] !== null && $ PPHP [ 'contextId' ] !== null ) { $ objectType = $ PPHP [ 'contextType' ] ; $ objectId = $ PPHP [ 'contextId' ] ; } ; if ( isset ( $ _SESSION [ 'user' ] [ 'id' ] ) ) { $ actingUserId = $ _SESSION [ 'user' ] [ 'id' ] ; if ( $ userId === 0 ) { $ userId = $ actingUserId ; } ; } ; $ oldValue = substr ( $ oldValue , 0 , 250 ) ; $ newValue = substr ( $ newValue , 0 , 250 ) ; $ db -> exec ( " INSERT INTO transactions (actingUserId, userId, ip, objectType, objectId, action, fieldName, oldValue, newValue, content) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?) " , array ( $ actingUserId , $ userId , $ ip , $ objectType , $ objectId , $ action , $ fieldName , $ oldValue , $ newValue , $ content ) ) ; }
|
Add a new transaction to the audit trail
|
15,855
|
public static function getLastLogin ( $ userId ) { global $ PPHP ; $ db = $ PPHP [ 'db' ] ; $ last = $ db -> selectSingleArray ( " SELECT timestamp, ip, datetime(timestamp, 'localtime') AS localtimestamp FROM transactions WHERE objectType='user' AND objectId=? AND action='login' ORDER BY id DESC LIMIT 1 " , array ( $ userId ) ) ; return $ last !== false ? $ last : array ( 'timestamp' => null , 'ip' => null ) ; }
|
Get user s last login details
|
15,856
|
public static function getObjectIds ( $ objectType , $ begin = null , $ end = null ) { global $ PPHP ; $ db = $ PPHP [ 'db' ] ; $ q = $ db -> query ( "SELECT DISTINCT(objectId) FROM transactions WHERE objectType=?" , $ objectType ) ; if ( $ begin !== null && $ end !== null ) { $ q -> and ( "timestamp BETWEEN date(?) AND date(?, '+1 day')" , array ( $ begin , $ end ) ) ; } elseif ( $ begin !== null ) { $ q -> and ( "timestamp >= date(?)" , $ begin ) ; } elseif ( $ end !== null ) { $ q -> and ( "timestamp <= date(?, '+1 day')" , $ end ) ; } ; $ q -> order_by ( 'objectId ASC' ) ; return $ db -> selectList ( $ q ) ; }
|
Get IDs with activity present
|
15,857
|
public function prepareForTransport ( ) { foreach ( $ this as $ k => $ v ) { if ( $ v instanceof FortifiApiResponse ) { $ v -> prepareForTransport ( ) ; } else if ( is_array ( $ v ) ) { foreach ( $ v as $ vi => $ vv ) { if ( $ vv instanceof FortifiApiResponse ) { $ vv -> prepareForTransport ( ) ; } } } } }
|
Executed before sending the response
|
15,858
|
public function setSetting ( $ name , $ value ) { $ old = isset ( $ this -> settings [ $ name ] ) ? $ this -> settings [ $ name ] : null ; if ( $ old instanceof self || $ value instanceof self ) { if ( $ old instanceof self && $ value instanceof self ) { $ old -> setSettings ( $ value -> settings ) ; } else if ( $ old instanceof self ) { if ( $ value instanceof Traversable ) { $ value = ArrayUtils :: iteratorToArray ( $ value ) ; } $ old -> setSettings ( ( array ) $ value ) ; } else { $ this -> settings [ $ name ] = $ value ; } } else { $ method = array ( $ this , 'update' . ucfirst ( $ name ) ) ; if ( is_callable ( $ method ) && ( ( isset ( $ value ) && isset ( $ this -> settings [ $ name ] ) && $ value != $ this -> settings [ $ name ] ) || ( isset ( $ value ) && ! isset ( $ this -> settings [ $ name ] ) ) || ( ! isset ( $ value ) && isset ( $ this -> settings [ $ name ] ) ) ) ) { $ value = $ method ( $ value , $ old ) ; } if ( null === $ value ) { unset ( $ this -> settings [ $ name ] ) ; } else { $ this -> settings [ $ name ] = $ value ; } } return $ this ; }
|
Set a setting by name
|
15,859
|
public static function capture ( $ files = null ) { $ files = $ files ?? $ _FILES ; if ( ! is_array ( $ files ) ) { return null ; } $ keys = array_keys ( $ files ) ; sort ( $ keys ) ; $ multi = $ keys !== [ 'error' , 'name' , 'size' , 'tmp_name' , 'type' ] ; if ( ! $ multi && is_array ( $ files [ 'name' ] ) ) { $ multi = true ; $ files = array_map ( function ( $ index ) use ( $ files ) { return array_combine ( array_keys ( $ files ) , array_column ( $ files , $ index ) ) ; } , array_keys ( $ files [ 'name' ] ) ) ; } if ( $ multi ) { return array_filter ( array_map ( [ static :: class , 'capture' ] , $ files ) ) ; } return new static ( $ files [ 'tmp_name' ] , $ files [ 'name' ] , $ files [ 'type' ] , $ files [ 'error' ] ) ; }
|
Capture uploaded files
|
15,860
|
public function generateKeyURI ( $ type , $ secret , $ account , $ issuer = '' , $ counter = 0 , $ algorithm = '' , $ digits = '' , $ period = '' ) { $ this -> validateType ( $ type ) ; $ this -> validateAlgorithm ( $ algorithm ) ; $ this -> formatLabel ( $ issuer , 'issuer' ) ; $ this -> formatLabel ( $ account , 'account' ) ; $ this -> setCounter ( $ type , $ counter ) ; $ this -> setParameter ( $ algorithm , 'algorithm' ) ; $ this -> setParameter ( $ digits , 'digits' ) ; $ this -> setParameter ( $ period , 'period' ) ; return 'otpauth://' . $ type . '/' . $ this -> label . '?secret=' . $ secret . $ this -> issuer . $ this -> parameters ; }
|
Generate OTP key URI
|
15,861
|
protected function formatLabel ( $ string , $ part ) { $ string = trim ( $ string ) ; if ( $ part === 'account' ) { $ this -> setAccount ( $ string ) ; } else if ( $ part === 'issuer' ) { $ this -> setIssuer ( $ string ) ; } }
|
Format label string according to expected urlencoded standards .
|
15,862
|
protected function setAccount ( $ account ) { if ( empty ( $ account ) ) { throw new \ InvalidArgumentException ( "Label can't contain empty strings" ) ; } $ this -> label .= str_replace ( '%40' , '@' , rawurlencode ( $ account ) ) ; }
|
Format and and set account name
|
15,863
|
protected function setIssuer ( $ issuer ) { if ( ! empty ( $ issuer ) ) { $ this -> label = rawurlencode ( $ issuer ) . ':' ; $ this -> issuer = '&issuer=' . rawurlencode ( $ issuer ) ; } }
|
Format and set issuer
|
15,864
|
protected function setCounter ( $ type , $ counter ) { if ( $ type === 'hotp' ) { if ( $ counter !== 0 && empty ( $ counter ) ) { throw new \ InvalidArgumentException ( "Counter can't be empty if HOTP is being used" ) ; } $ this -> parameters .= "&counter=$counter" ; } }
|
Set counter value if hotp is being used
|
15,865
|
public static function full ( $ object ) : string { if ( is_string ( $ object ) ) { return str_replace ( '.' , '\\' , $ object ) ; } if ( is_object ( $ object ) ) { return trim ( get_class ( $ object ) , '\\' ) ; } $ message = sprintf ( '%s expects $object to be an object or string; received (%s) %s' , __METHOD__ , gettype ( $ object ) , VarPrinter :: toString ( $ object ) ) ; throw new TypeException ( $ message ) ; }
|
Retrieves the fully qualified class name of an object
|
15,866
|
public function addAnnotationController ( $ bundle , $ controller ) { $ current = '' ; if ( file_exists ( $ this -> file ) ) { $ current = file_get_contents ( $ this -> file ) ; } elseif ( ! is_dir ( $ dir = dirname ( $ this -> file ) ) ) { mkdir ( $ dir , 0777 , true ) ; } $ code = sprintf ( "%s:\n" , Container :: underscore ( substr ( $ bundle , 0 , - 6 ) ) . '_' . Container :: underscore ( $ controller ) ) ; if ( $ this -> controllerFolder ) { $ controller = $ this -> controllerFolder . '/' . $ controller ; } $ code .= sprintf ( " resource: \"@%s/Controller/%sController.php\"\n type: annotation\n" , $ bundle , $ controller ) ; $ code .= "\n" ; $ code .= $ current ; return false !== file_put_contents ( $ this -> file , $ code ) ; }
|
Add an annotation controller resource .
|
15,867
|
protected function createProgressBar ( OutputInterface $ output , $ length = 10 ) { $ progress = $ this -> getHelper ( 'progress' ) ; $ progress -> setBarCharacter ( '<info>|</info>' ) ; $ progress -> setEmptyBarCharacter ( ' ' ) ; $ progress -> setProgressCharacter ( '|' ) ; $ progress -> start ( $ output , $ length ) ; return $ progress ; }
|
Create progress bar
|
15,868
|
private function validateTemplate ( $ template , $ templateList ) { if ( empty ( $ template ) ) { throw new \ Exception ( 'The template name is required.' ) ; } if ( ! in_array ( $ template , $ templateList ) ) { throw new \ InvalidArgumentException ( sprintf ( 'The template "%s" does not exist, use: %s' , $ template , implode ( ', ' , $ templateList ) ) ) ; } }
|
Validate template name
|
15,869
|
public function setCallable ( $ callableExpression ) { if ( strpos ( "@" , $ callableExpression ) === false ) { $ callableExpression .= "@indexAction" ; } list ( $ controllerName , $ action ) = explode ( "@" , $ callableExpression ) ; $ controller = $ this -> pimple [ $ controllerName ] ; $ callable = array ( $ controller , $ action ) ; if ( ! is_callable ( $ callable ) ) { $ message = "The callable you have provided is not callable, if you did not provide a action then " ; $ message .= "indexAction will be called on your given controller" ; throw new \ InvalidArgumentException ( $ message ) ; } $ this -> callable = $ callable ; }
|
Sets the controller and action
|
15,870
|
public function addConditionsFromArray ( array $ conditions ) { foreach ( $ conditions as $ condition ) { if ( ! is_callable ( $ condition ) ) { $ message = "One or more of the conditions you provided are not callable, " ; $ message .= "please pass an array of callable functions." ; throw new \ InvalidArgumentException ( $ message ) ; } $ this -> conditions -> enqueue ( $ condition ) ; } }
|
Adds conditions to the route from the given array
|
15,871
|
public function run ( ) { if ( ! isset ( $ this -> conditions ) || ! isset ( $ this -> callable ) ) { $ message = "You have called the run function but have not provided both a array of conditions" ; $ message .= " and a callable function, which will be called if all the given conditions are met." ; throw new \ RuntimeException ( $ message ) ; } $ this -> conditions -> rewind ( ) ; while ( $ this -> conditions -> valid ( ) ) { $ condition = $ this -> conditions -> current ( ) ; if ( ! call_user_func ( $ condition ) ) { return false ; } $ this -> conditions -> next ( ) ; } call_user_func ( $ this -> callable , $ this -> request ) ; return true ; }
|
Runs through all the callable functions provided if all are met call the given callable
|
15,872
|
protected function generateBody ( $ modelName , array $ properties ) { $ linesProperties = array ( "" ) ; $ linesMethods = array ( "" ) ; foreach ( $ properties as $ field ) { foreach ( $ field as $ property ) { $ linesProperties [ ] = " /**" ; $ linesProperties [ ] = " * " . $ property [ 'columnName' ] ; $ linesProperties [ ] = " * " ; $ linesProperties [ ] = " * @var $property[type] $$property[fieldName]" ; $ linesProperties [ ] = " */" ; $ linesProperties [ ] = " protected $$property[fieldName];" ; $ linesProperties [ ] = "" ; $ linesMethods [ ] = str_replace ( array ( '<description>' , '<fieldName>' , '<variableType>' , '<methodName>' , '<spaces>' ) , array ( 'Get ' . $ property [ 'columnName' ] , $ property [ 'fieldName' ] , $ property [ 'type' ] , 'get' . ucwords ( $ property [ 'fieldName' ] ) , " " ) , self :: $ getMethodTemplate ) ; $ linesMethods [ ] = "" ; $ linesMethods [ ] = str_replace ( array ( '<description>' , '<fieldName>' , '<variableType>' , '<variableName>' , '<modelClass>' , '<methodName>' , '<spaces>' ) , array ( 'Set ' . $ property [ 'columnName' ] , $ property [ 'fieldName' ] , $ property [ 'type' ] , $ property [ 'fieldName' ] , $ modelName , 'set' . ucwords ( $ property [ 'fieldName' ] ) , " " ) , self :: $ setMethodTemplate ) ; $ linesMethods [ ] = "" ; } } return implode ( "\n" , $ linesProperties ) . implode ( "\n" , $ linesMethods ) ; }
|
Generate array properties getters and setters
|
15,873
|
public function panelHeader ( $ title , $ h = 'h1' ) { $ panelTitle = parent :: tag ( $ h , $ title , [ 'class' => 'panel-title' ] ) ; return parent :: tag ( "div" , $ panelTitle , [ 'class' => 'panel-heading' ] ) ; }
|
Returns a panel header
|
15,874
|
public function modalHeader ( $ title , $ h = 'h4' ) { $ modalTitle = parent :: tag ( $ h , $ title , [ 'class' => 'modal-title' ] ) ; return parent :: tag ( "div" , $ modalTitle , [ "class" => 'modal-header' ] ) ; }
|
Returns a modal header
|
15,875
|
public function descriptionList ( $ data , $ options = [ ] , $ dtOpts = [ ] , $ ddOpts = [ ] ) { if ( empty ( $ data ) || ! is_array ( $ data ) ) { return false ; } $ out = [ ] ; $ dtOptions = parent :: _parseAttributes ( $ dtOpts ) ; $ ddOptions = parent :: _parseAttributes ( $ ddOpts ) ; foreach ( $ data as $ descr => $ value ) { $ out [ ] = sprintf ( $ this -> _tags [ 'dt' ] , $ dtOptions , $ descr ) ; $ out [ ] = sprintf ( $ this -> _tags [ 'dd' ] , $ ddOptions , $ value ) ; } $ dl = sprintf ( $ this -> _tags [ 'dl' ] , parent :: _parseAttributes ( $ options ) , implode ( "\n" , $ out ) ) ; return $ dl ; }
|
returns a dl element
|
15,876
|
public function well ( $ text , $ size = null , $ options = [ ] ) { $ options = [ 'class' => 'well' ] ; if ( ! empty ( $ size ) ) { switch ( $ size ) { case 'lg' : case 'large' : $ options = parent :: addClass ( $ options , 'well-lg' ) ; break ; case 'sm' : case 'small' : $ options = parent :: addClass ( $ options , 'well-sm' ) ; break ; } } return parent :: tag ( 'div' , $ text , $ options ) ; }
|
creates a div with well properties
|
15,877
|
public function lead ( $ content , $ options = [ ] ) { $ options = array_merge ( [ 'class' => 'lead' ] , $ options ) ; return parent :: tag ( 'p' , $ content , $ options ) ; }
|
Creates a paragraph with lead class
|
15,878
|
protected function _generateListGroupText ( $ title ) { if ( is_array ( $ title ) ) { $ text = '' ; if ( ! empty ( $ title [ 'header' ] ) ) { $ text .= $ this -> tag ( 'h4' , $ title [ 'header' ] , [ 'class' => 'list-group-item-heading' ] ) ; } if ( ! empty ( $ title [ 'text' ] ) ) { $ text .= $ this -> para ( 'list-group-item-text' , $ title [ 'text' ] ) ; } } else { $ text = $ title ; } return $ text ; }
|
_generateListGroupText Generates the text for the list group item
|
15,879
|
public function badge ( $ text , $ options = [ ] ) { $ defaults = array_merge ( [ 'class' => 'badge' ] , $ options ) ; return parent :: tag ( 'span' , $ text , $ defaults ) ; }
|
return a badge
|
15,880
|
public function status ( $ value , $ url = [ ] ) { $ icon = $ value == true ? 'check' : 'times' ; $ contextual = $ value == true ? 'success' : 'danger' ; return $ this -> label ( '' , $ contextual , [ 'icon' => $ icon ] ) ; }
|
Returns a well formatted check . Used special for booleans
|
15,881
|
public function icon ( $ type , $ text = '' , array $ options = [ ] ) { $ icon = $ this -> iconPrefix ; $ class = "$icon $icon-$type" ; if ( isset ( $ options [ 'class' ] ) && ! empty ( $ class ) ) { $ options [ 'class' ] = $ class . ' ' . $ options [ 'class' ] ; } else { $ options [ 'class' ] = $ class ; } $ tag = parent :: tag ( 'i' , '' , $ options ) ; return trim ( $ tag . ' ' . $ text ) ; }
|
Returns an icon element followed by a text
|
15,882
|
protected function _icon ( $ title , array $ options = [ ] ) { if ( empty ( $ options ) || ! isset ( $ options [ 'icon' ] ) ) { return $ title ; } $ options = $ options [ 'icon' ] ; if ( is_array ( $ options ) ) { if ( ! isset ( $ options [ 'class' ] ) || empty ( $ options [ 'class' ] ) ) { return $ title ; } } if ( is_string ( $ options ) ) { if ( empty ( $ options ) ) { return $ title ; } $ icon = $ this -> iconPrefix ; $ options = [ "class" => "$icon $icon-$options" ] ; } $ tag = parent :: tag ( 'i' , '' , $ options ) ; return trim ( $ tag . ' ' . $ title ) ; }
|
Returns an icon element followed by a text . This function is used for generating an icon for internal functions inside this helper .
|
15,883
|
protected function insertRow ( AbstractEntity $ entity ) { $ values = $ entity -> getDbValues ( ) ; $ columns = array_keys ( $ values ) ; if ( $ this -> autoIncrementColumn && ! array_key_exists ( $ this -> autoIncrementColumn , $ values ) ) { throw new LogicException ( 'auto_increment column ' . $ this -> autoIncrementColumn . ' not found' ) ; } $ query = $ this -> getSqlObject ( ) -> insert ( ) -> columns ( $ columns ) -> values ( $ values ) ; $ statement = $ this -> getSqlObject ( ) -> prepareStatementForSqlObject ( $ query ) ; $ result = $ statement -> execute ( ) ; if ( $ this -> autoIncrementColumn && ! $ values [ $ this -> autoIncrementColumn ] ) { $ entity -> exchangeArray ( [ $ this -> autoIncrementColumn => $ result -> getGeneratedValue ( ) ] ) ; } }
|
Insert an entity s DB row using the given values . Set the ID on the entity from the query result .
|
15,884
|
public function compile ( CompilerConfig $ config ) : Compiler { $ cache_dir = $ config -> getCacheDir ( ) ; if ( ! $ cache_dir ) { throw new CacheDirectoryConfigurationException ( $ cache_dir ) ; } $ cache_dir = new File ( $ cache_dir ) ; if ( ! $ cache_dir -> exists ( ) || ! $ cache_dir -> isDirectory ( ) ) { throw new CacheDirectoryNotFoundException ( $ cache_dir ) ; } if ( ! $ cache_dir -> canWrite ( ) ) { throw new CacheDirectoryNotWritableException ( $ cache_dir ) ; } $ cache_filename = $ config -> getCacheFilename ( ) ; $ bootstrap_file = new File ( $ cache_filename . '.php' , $ cache_dir ) ; if ( ! $ bootstrap_file -> exists ( ) ) { $ contents = $ this -> generateBootstrapCode ( $ config ) ; $ bootstrap_file -> putContents ( $ contents ) ; } return $ this ; }
|
Compile setup code
|
15,885
|
private function constructor ( string $ class_name , array $ params = null ) { $ this -> state -> category = CompilerState :: CATEGORY_CONSTRUCTOR ; $ this -> state -> name = '' ; $ params_str = '' ; if ( is_array ( $ params ) ) { $ params_str = $ this -> decorateParamsForMethodCall ( $ params ) ; } return $ class_name . '(' . $ params_str . ')' ; }
|
Make constructor code
|
15,886
|
private function methodCallList ( array $ method_injections ) { $ this -> state -> category = CompilerState :: CATEGORY_METHOD ; $ ret = '' ; foreach ( $ method_injections as $ injection ) { $ method_name = $ injection [ 'method' ] ?? null ; $ params = $ injection [ 'params' ] ?? null ; $ this -> state -> name = $ method_name ; $ params_str = '' ; if ( is_array ( $ params ) ) { $ params_str = $ this -> decorateParamsForMethodCall ( $ params ) ; } $ ret .= " \$component->{$method_name}(" . $ params_str . ");\n" ; } return $ ret ; }
|
Make method call code
|
15,887
|
private function propertySetList ( array $ property_injections ) { $ this -> state -> category = CompilerState :: CATEGORY_PROPERTY ; $ ret = '' ; foreach ( $ property_injections as $ injection ) { $ property_name = $ injection [ 'property' ] ?? null ; $ value = $ injection [ 'value' ] ?? null ; $ this -> state -> name = $ property_name ; if ( is_null ( $ value ) ) { $ value = 'null' ; } elseif ( is_string ( $ value ) ) { $ value = $ this -> decorateStringValue ( $ value ) ; } elseif ( is_array ( $ value ) ) { $ value = $ this -> decorateArrayValue ( $ value ) ; } $ ret .= " \$component->{$property_name} = {$value};\n" ; } return $ ret ; }
|
Make property set code
|
15,888
|
private function findPropertyInjections ( array $ injections ) { $ ret = [ ] ; if ( is_array ( $ injections ) ) { foreach ( $ injections as $ injection ) { if ( ! isset ( $ injection [ 'property' ] ) ) { continue ; } $ ret [ ] = $ injection ; } } return $ ret ; }
|
find property injection
|
15,889
|
private function decorateParamsForMethodCall ( array $ params ) : string { $ params_out = [ ] ; foreach ( $ params as $ param ) { $ params_out [ ] = $ this -> decorateValue ( $ param ) ; } return implode ( ',' , $ params_out ) ; }
|
Modify param array for method call
|
15,890
|
private function decorateValue ( $ value ) : string { $ ret = 'null' ; switch ( gettype ( $ value ) ) { case 'string' : $ ret = $ this -> decorateStringValue ( $ value ) ; break ; case 'integer' : case 'double' : $ ret = $ value ; break ; case 'boolean' : $ ret = $ value ? 'true' : 'false' ; break ; case 'array' : $ ret = $ this -> decorateArrayValue ( $ value ) ; break ; } return $ ret ; }
|
Modify value for function call or setting property
|
15,891
|
private function decorateStringValue ( string $ value ) : string { if ( $ value === '@this' ) { return "\$c" ; } if ( preg_match ( '/^@id:(.*)$/s' , $ value , $ matches ) ) { $ id = trim ( $ matches [ 1 ] ) ; return "\$c['" . self :: escapeSingleQuote ( $ id ) . "']" ; } if ( preg_match ( '/^@resolve:(.*)$/s' , $ value , $ matches ) ) { $ target = trim ( $ matches [ 1 ] ) ; return "\$c[\$c->resolve('" . self :: escapeSingleQuote ( $ target ) . "')]" ; } if ( preg_match ( '/^@func:(.*)$/s' , $ value , $ matches ) ) { $ func = trim ( $ matches [ 1 ] ) ; $ this -> validateCallable ( $ func ) ; return $ func ; } if ( preg_match ( '/^@int:(.*)$/s' , $ value , $ matches ) ) { $ value = trim ( $ matches [ 1 ] ) ; $ value = $ this -> validateInteger ( $ value ) ; return $ this -> decorateValue ( $ value ) ; } if ( preg_match ( '/^@float:(.*)$/s' , $ value , $ matches ) ) { $ value = trim ( $ matches [ 1 ] ) ; $ value = $ this -> validateFloat ( $ value ) ; return $ this -> decorateValue ( $ value ) ; } if ( preg_match ( '/^@bool:(.*)$/s' , $ value , $ matches ) ) { $ value = trim ( $ matches [ 1 ] ) ; $ value = $ this -> validateBool ( $ value ) ; return $ this -> decorateValue ( $ value ) ; } if ( preg_match ( '/^@json:(.*)$/s' , $ value , $ matches ) ) { $ value = trim ( $ matches [ 1 ] ) ; $ value = $ this -> validateJson ( $ value ) ; return $ this -> decorateValue ( $ value ) ; } if ( preg_match ( '/^@env:(.*)$/s' , $ value , $ matches ) ) { $ id = trim ( $ matches [ 1 ] ) ; return "(\$_ENV['" . self :: escapeSingleQuote ( $ id ) . "'] ?? null)" ; } return "'" . self :: escapeSingleQuote ( $ value ) . "'" ; }
|
Modify string value for function call or setting property
|
15,892
|
private function validateCallable ( string $ str ) { ob_start ( ) ; try { $ _ = @ eval ( 'return ' . $ str . ';' ) ; if ( ! is_callable ( $ _ ) ) { throw new ValidateCallableException ( $ str ) ; } } catch ( \ Throwable $ e ) { ob_end_clean ( ) ; throw new CompileErrorException ( $ e -> getMessage ( ) , $ this -> state ) ; } ob_end_clean ( ) ; }
|
Validate if expression is callable
|
15,893
|
private function validateInteger ( string $ str ) : int { $ ret = filter_var ( $ str , FILTER_VALIDATE_INT ) ; if ( $ ret === false ) { throw new CompileErrorException ( 'invalid integer value' , $ this -> state ) ; } return $ ret ; }
|
Validate if expression is integer value
|
15,894
|
private function validateJson ( string $ str ) : array { $ ret = json_decode ( $ str , true ) ; if ( $ ret === null ) { throw new CompileErrorException ( 'invalid json value:' . json_last_error_msg ( ) , $ this -> state ) ; } if ( ! is_array ( $ ret ) ) { throw new CompileErrorException ( '@json immediate must be array value.' , $ this -> state ) ; } return $ ret ; }
|
Validate if expression is json value
|
15,895
|
private function findSlotById ( string $ id , array $ slots ) { $ slot = null ; foreach ( $ slots as $ s ) { $ slot_id = $ s [ 'id' ] ?? null ; if ( $ slot_id == $ id ) { $ slot = $ s ; break ; } } return $ slot ; }
|
Find slot by id
|
15,896
|
public function toArray ( Model $ model ) { if ( method_exists ( $ model , 'withoutArrayHook' ) ) { $ model -> withoutArrayHook ( ) ; } $ result = $ model -> toArray ( ) ; $ namedExc = [ ] ; foreach ( $ this -> exclude as $ k ) { array_set ( $ namedExc , $ k , true ) ; } $ namedInc = [ ] ; foreach ( $ this -> include as $ k ) { array_set ( $ namedInc , $ k , true ) ; } $ namedExp = [ ] ; foreach ( $ this -> expand as $ k ) { array_set ( $ namedExp , $ k , true ) ; } foreach ( array_keys ( $ result ) as $ k ) { if ( isset ( $ namedExc [ $ k ] ) && ! is_array ( $ namedExc [ $ k ] ) ) { unset ( $ result [ $ k ] ) ; } } foreach ( array_keys ( $ namedInc ) as $ k ) { if ( ! isset ( $ result [ $ k ] ) && isset ( $ namedInc [ $ k ] ) ) { $ result [ $ k ] = $ model -> $ k ; if ( $ result [ $ k ] instanceof Model ) { $ subExc = array_value ( $ namedExc , $ k ) ; $ subInc = array_value ( $ namedInc , $ k ) ; $ subExp = array_value ( $ namedExp , $ k ) ; $ flatExc = is_array ( $ subExc ) ? array_keys ( array_dot ( $ subExc ) ) : [ ] ; $ flatInc = is_array ( $ subInc ) ? array_keys ( array_dot ( $ subInc ) ) : [ ] ; $ flatExp = is_array ( $ subExp ) ? array_keys ( array_dot ( $ subExp ) ) : [ ] ; $ serializer = new self ( $ this -> request ) ; $ serializer -> setExclude ( $ flatExc ) -> setInclude ( $ flatInc ) -> setExpand ( $ flatExp ) ; $ result [ $ k ] = $ serializer -> toArray ( $ result [ $ k ] ) ; } } } $ result = $ this -> expand ( $ model , $ result , $ namedExc , $ namedInc , $ namedExp ) ; if ( method_exists ( $ model , 'toArrayHook' ) ) { $ model -> toArrayHook ( $ result , $ namedExc , $ namedInc , $ namedExp ) ; } ksort ( $ result ) ; return $ result ; }
|
Serializes a model to an array .
|
15,897
|
private function expand ( Model $ model , array $ result , array $ namedExc , array $ namedInc , array $ namedExp ) { foreach ( $ namedExp as $ k => $ subExp ) { $ value = array_value ( $ result , $ k ) ; if ( ! $ this -> isExpandable ( $ model , $ k , $ value ) ) { continue ; } $ subExc = array_value ( $ namedExc , $ k ) ; $ subInc = array_value ( $ namedInc , $ k ) ; $ flatExc = is_array ( $ subExc ) ? array_keys ( array_dot ( $ subExc ) ) : [ ] ; $ flatInc = is_array ( $ subInc ) ? array_keys ( array_dot ( $ subInc ) ) : [ ] ; $ flatExp = is_array ( $ subExp ) ? array_keys ( array_dot ( $ subExp ) ) : [ ] ; $ relation = $ model -> relation ( $ k ) ; $ serializer = new self ( $ this -> request ) ; $ serializer -> setExclude ( $ flatExc ) -> setInclude ( $ flatInc ) -> setExpand ( $ flatExp ) ; if ( $ relation instanceof Model ) { $ result [ $ k ] = $ serializer -> toArray ( $ relation ) ; } else { $ result [ $ k ] = $ relation ; } } return $ result ; }
|
Expands any relational properties within a result .
|
15,898
|
private function isExpandable ( Model $ model , $ k , $ value ) { if ( ! $ value ) { return false ; } $ property = $ model :: getProperty ( $ k ) ; if ( ! $ property || ! isset ( $ property [ 'relation' ] ) ) { return false ; } return true ; }
|
Expands a model .
|
15,899
|
public static function encode ( String $ string , $ badWords = NULL , $ changeChar = '[badchars]' ) : String { if ( empty ( $ badWords ) ) { $ secnc = Properties :: $ ncEncode ; $ badWords = $ secnc [ 'badChars' ] ; $ changeChar = $ secnc [ 'changeBadChars' ] ; } $ regex = Singleton :: class ( 'ZN\Regex' ) ; if ( ! is_array ( $ badWords ) ) { return $ string = $ regex -> replace ( $ badWords , $ changeChar , $ string , 'xi' ) ; } $ ch = '' ; $ i = 0 ; foreach ( $ badWords as $ value ) { if ( ! is_array ( $ changeChar ) ) { $ ch = $ changeChar ; } else { if ( isset ( $ changeChar [ $ i ] ) ) { $ ch = $ changeChar [ $ i ] ; $ i ++ ; } } $ string = $ regex -> replace ( $ value , $ ch , $ string , 'xi' ) ; } return $ string ; }
|
Encode Nasty Code
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.