idx
int64
0
60.3k
question
stringlengths
64
4.24k
target
stringlengths
5
618
18,900
public function send ( IMail $ mail ) : void { $ emailContent = $ this -> mailService -> getContent ( $ mail ) ; $ this -> phpMailer -> SMTPDebug = 0 ; $ this -> phpMailer -> isSMTP ( ) ; $ this -> phpMailer -> Host = $ this -> host ; $ this -> phpMailer -> SMTPAuth = true ; $ this -> phpMailer -> Username = $ this -> username ; $ this -> phpMailer -> Password = $ this -> password ; $ this -> phpMailer -> SMTPSecure = $ this -> smtpSecure ; $ this -> phpMailer -> Port = $ this -> port ; $ this -> phpMailer -> CharSet = $ mail -> getCharset ( ) ; $ this -> phpMailer -> setFrom ( $ mail -> getSender ( ) -> getEmail ( ) , $ mail -> getSender ( ) -> getName ( ) ) ; $ this -> phpMailer -> addAddress ( $ mail -> getRecipient ( ) -> getEmail ( ) , $ mail -> getRecipient ( ) -> getName ( ) ) ; foreach ( $ mail -> getBccRecipients ( ) as $ bccRecipient ) { $ this -> phpMailer -> addBCC ( $ bccRecipient -> getEmail ( ) ) ; } foreach ( $ mail -> getAttachments ( ) as $ attachment ) { $ this -> phpMailer -> addAttachment ( $ attachment -> getPath ( ) . '/' . $ attachment -> getFileName ( ) ) ; } $ this -> phpMailer -> isHTML ( ) ; $ this -> phpMailer -> Subject = $ mail -> getSubject ( ) ; $ this -> phpMailer -> msgHTML ( $ emailContent ) ; $ this -> phpMailer -> send ( ) ; foreach ( $ mail -> getAttachments ( ) as $ attachment ) { if ( $ attachment -> isDeleteAfterSend ( ) ) { unlink ( $ attachment -> getPath ( ) . '/' . $ attachment -> getFileName ( ) ) ; } } }
Send created IMail entity .
18,901
public static function set ( $ pKey , $ pValue ) { if ( array_key_exists ( $ pKey , self :: $ _registry ) ) { throw new Exception ( "The registry key '$pKey' already exists" ) ; } return self :: $ _registry [ $ pKey ] = $ pValue ; }
Add an entrey to the registry .
18,902
public static function get ( $ pKey ) { if ( array_key_exists ( $ pKey , self :: $ _registry ) ) { return self :: $ _registry [ $ pKey ] ; } return NULL ; }
Get a value from the registry .
18,903
public static function remove ( $ pKey ) { if ( ! array_key_exists ( $ pKey , self :: $ _registry ) ) { throw new Exception ( "The registry key '$pKey' doesn't exist" ) ; } if ( is_object ( self :: $ _registry [ $ pKey ] ) and method_exists ( self :: $ _registry [ $ pKey ] , '__destruct' ) ) { self :: $ _registry [ $ pKey ] -> __destruct ( ) ; } unset ( self :: $ _registry [ $ pKey ] ) ; return true ; }
Remove an entry from the registry .
18,904
private function initRolesForClass ( $ access ) { $ auth = Yii :: $ app -> authManager ; $ descriptions = $ access -> descriptions ( ) ; foreach ( $ descriptions as $ permissionName => $ description ) { $ permission = $ auth -> getPermission ( $ permissionName ) ; if ( ! $ permission ) { $ permission = $ auth -> createPermission ( $ permissionName ) ; $ permission -> description = $ descriptions [ $ permissionName ] ; $ auth -> add ( $ permission ) ; } } $ rolesPermissions = $ access -> rolesPermissions ( ) ; $ rolesTitles = $ access -> rolesTitles ( ) ; foreach ( $ rolesPermissions as $ roleName => $ permissions ) { $ role = $ auth -> getRole ( $ roleName ) ; if ( ! $ role ) { $ role = $ auth -> createRole ( $ roleName ) ; $ role -> description = $ rolesTitles [ $ roleName ] ; $ auth -> add ( $ role ) ; } $ oldPermissions = $ auth -> getPermissionsByRole ( $ roleName ) ; foreach ( $ permissions as $ permissionName ) { if ( ! isset ( $ oldPermissions [ $ permissionName ] ) ) { $ permission = $ auth -> getPermission ( $ permissionName ) ; $ auth -> addChild ( $ role , $ permission ) ; } } } }
init roles for extension class
18,905
public function initRolesAndActions ( ) { $ classes = $ this -> loadClasses ( ) ; foreach ( $ classes as $ item ) { $ this -> initRolesForClass ( $ item ) ; } }
Collecting and initialising roles over all app
18,906
public function setAdminRole ( $ user ) { $ classes = $ this -> loadClasses ( ) ; $ auth = Yii :: $ app -> authManager ; $ auth -> revokeAll ( $ user -> id ) ; foreach ( $ classes as $ item ) { foreach ( $ item -> adminRoles ( ) as $ role ) { $ auth -> assign ( $ auth -> getRole ( $ role ) , $ user -> id ) ; } } }
Set admin roles to user
18,907
public function showAction ( Request $ request , $ siteId , $ nodeId , $ blockId ) { try { $ block = $ this -> get ( 'open_orchestra_model.repository.block' ) -> findById ( $ blockId ) ; $ response = $ this -> get ( 'open_orchestra_display.display_block_manager' ) -> show ( $ block ) ; $ this -> tagResponse ( $ block , $ nodeId , $ siteId , $ request -> getLocale ( ) ) ; return $ response ; } catch ( \ Exception $ e ) { throw new DisplayBlockException ( $ e -> getMessage ( ) , $ e -> getCode ( ) , $ e ) ; } }
Display the response linked to a block
18,908
public function execute ( ) { $ config = $ this -> getConfiguration ( ) ; $ code = '' ; $ code .= $ this -> generateContainerInitializationCode ( $ config ) ; $ code .= $ this -> generateFactoriesInitializationCode ( $ config ) ; return $ code ; }
Generates configuration cache code
18,909
public function getData ( ) { if ( $ this -> vars [ 'compound' ] && $ this -> vars [ 'value' ] !== null ) { return array_map ( function ( DataViewView $ view ) { return $ view -> getData ( ) ; } , $ this -> children ) ; } return $ this -> vars [ 'value' ] ; }
This is the method that will actually fetch the data off the view object
18,910
public function getMenu ( $ menuName ) { $ menu = $ this -> getMenuObject ( $ menuName ) ; if ( $ menu ) { return $ menu ; } else { return $ this -> add ( $ menuName ) ; } }
Get a menu you have created .
18,911
public function render ( $ menuName ) { $ this -> updateActive ( ) ; $ menu = $ this -> getMenuObject ( $ menuName ) ; if ( ! $ menu ) { throw new \ Exception ( "Menu {$menuName} not found." ) ; } return $ menu ; }
Update the active and order values and then return the object .
18,912
private function updateActive ( ) { $ this -> each ( function ( $ item ) { if ( isset ( $ item -> links ) ) { $ this -> makeActive ( $ item ) ; } } ) ; }
Use the active param and set the link to active
18,913
private function makeActive ( $ item , $ parent = null ) { $ item -> links -> each ( function ( $ link ) use ( $ item , $ parent ) { if ( $ link -> slug == $ this -> active ) { $ this -> makeParentActive ( $ parent ) ; $ this -> makeParentActive ( $ item ) ; $ link -> setActive ( true ) ; } if ( isset ( $ link -> links ) ) { $ this -> makeActive ( $ link , $ item ) ; } } ) ; }
Loop through the links and check for active . Sets the item and it s parents as active when told to .
18,914
private function makeParentActive ( $ parent ) { if ( ! is_null ( $ parent ) && method_exists ( $ parent , 'activeParentage' ) && $ parent -> activeParentage ( ) ) { $ parent -> setActive ( true ) ; } }
Set the parent item as active if able to do so .
18,915
public function resolve ( $ closure ) { if ( is_array ( $ closure ) ) { $ reflection = new \ ReflectionMethod ( $ closure [ 0 ] , $ closure [ 1 ] ) ; } else { $ reflection = new \ ReflectionFunction ( $ closure ) ; } $ arguments = $ reflection -> getParameters ( ) ; $ arguments = array_map ( function ( $ argument ) { return isset ( $ this -> bindMaps [ $ argument -> name ] ) ? $ this -> bindMaps [ $ argument -> name ] : null ; } , $ arguments ) ; return @ call_user_func_array ( $ closure , $ arguments ) ; }
Resolve the closure and do the magic here
18,916
public function getFullSlug ( ) : string { $ categories = Category :: with ( 'ancestors' ) -> ancestorsAndSelf ( $ this -> category -> id ) ; $ slug = "" ; foreach ( $ categories as $ category ) { $ translation = $ category -> translations -> where ( 'locale' , $ this -> locale ) -> first ( ) ; $ slug .= $ translation -> slug . '/' ; } $ slug = substr ( $ slug , 0 , - 1 ) ; return $ slug ; }
Get full slug of the category
18,917
public function getDsn ( ) : string { $ _dsn = $ this -> driver . ':host=' . $ this -> host . ';port=' . $ this -> port . ';dbname=' . $ this -> schema . ';charset=' . $ this -> charset ; $ this -> setDsn ( $ _dsn ) ; return $ this -> pdo_dsn ; }
Get DSN - Return the default formatted DSN
18,918
private function addInterfaceProvider ( $ interface , Reference $ reference ) { if ( empty ( $ this -> interfaceProviders [ $ interface ] ) ) { $ this -> interfaceProviders [ $ interface ] = [ ] ; } $ this -> interfaceProviders [ $ interface ] [ ] = $ reference ; }
Add an interface provider to the list
18,919
private function addClassProvider ( $ class , Reference $ reference ) { if ( empty ( $ this -> classProviders [ $ class ] ) ) { $ this -> classProviders [ $ class ] = [ ] ; } $ this -> classProviders [ $ class ] [ ] = $ reference ; }
Add a class provider to the list
18,920
private function getProvider ( $ identifier ) { if ( isset ( $ this -> interfaceProviders [ $ identifier ] ) ) { $ this -> assertSingleInterfaceProvider ( $ identifier ) ; return reset ( $ this -> interfaceProviders [ $ identifier ] ) ; } elseif ( isset ( $ this -> classProviders [ $ identifier ] ) ) { $ this -> assertSingleClassProvider ( $ identifier ) ; return reset ( $ this -> classProviders [ $ identifier ] ) ; } else { return false ; } }
Get a provider for an identifier using this method when there are multiple providers for an identifier will cause an exception to be thrown
18,921
private function getProviders ( $ identifier ) { if ( isset ( $ this -> interfaceProviders [ $ identifier ] ) ) { return $ this -> interfaceProviders [ $ identifier ] ; } elseif ( isset ( $ this -> classProviders [ $ identifier ] ) ) { return $ this -> classProviders [ $ identifier ] ; } else { return [ ] ; } }
Get all providers for a specified identifier
18,922
private function isMethodIncluded ( $ methodName , $ attr ) { if ( empty ( $ attr [ self :: CONFIG_INCLUDE ] ) || ! is_array ( $ attr [ self :: CONFIG_INCLUDE ] ) ) { return true ; } return in_array ( $ methodName , $ attr [ self :: CONFIG_INCLUDE ] ) ; }
Checks if a method is in the include list
18,923
private function isMethodExcluded ( $ methodName , $ attr ) { if ( empty ( $ attr [ self :: CONFIG_EXCLUDE ] ) || ! is_array ( $ attr [ self :: CONFIG_EXCLUDE ] ) ) { return false ; } return in_array ( $ methodName , $ attr [ self :: CONFIG_EXCLUDE ] ) ; }
Checks if a method is in the exclude list
18,924
private function hasConfig ( $ config , $ attr ) { return ( isset ( $ attr [ self :: CONFIG_ALL ] ) && $ attr [ self :: CONFIG_ALL ] ) || ( isset ( $ attr [ $ config ] ) && $ attr [ $ config ] ) ; }
Tests whether ot not a config option has been provided in the tag If the all setting is present this will return true
18,925
protected function setupTitle ( ) { if ( $ this -> title === null ) { $ segments = explode ( '\\' , $ this -> entityNamespace ) ; $ this -> title = end ( $ segments ) ; } $ this -> viewModel -> setVariable ( 'title' , $ this -> title ) ; }
Set Title into ViewModel extract Entity - Classname if no title set
18,926
public function listAction ( ) { $ metaSetManager = $ this -> get ( 'phlexible_meta_set.meta_set_manager' ) ; $ metaSet = $ metaSetManager -> findAll ( ) ; $ data = [ ] ; foreach ( $ metaSet as $ set ) { $ data [ ] = [ 'id' => $ set -> getId ( ) , 'name' => $ set -> getName ( ) , 'createdAt' => $ set -> getCreatedAt ( ) ? $ set -> getCreatedAt ( ) -> format ( 'Y-m-d H:i:s' ) : null , 'createUser' => $ set -> getCreateUser ( ) , 'modifiedAt' => $ set -> getModifiedAt ( ) ? $ set -> getModifiedAt ( ) -> format ( 'Y-m-d H:i:s' ) : null , 'modifyUser' => $ set -> getModifyUser ( ) , 'revision' => $ set -> getRevision ( ) , ] ; } return new JsonResponse ( [ 'sets' => $ data ] ) ; }
List sets .
18,927
public function fieldsAction ( Request $ request ) { $ id = $ request -> get ( 'id' ) ; $ metaSetManager = $ this -> get ( 'phlexible_meta_set.meta_set_manager' ) ; $ metaSet = $ metaSetManager -> find ( $ id ) ; $ fields = $ metaSet -> getFields ( ) ; $ data = [ ] ; foreach ( $ fields as $ field ) { $ data [ ] = [ 'id' => $ field -> getId ( ) , 'key' => $ field -> getName ( ) , 'type' => $ field -> getType ( ) , 'required' => $ field -> isRequired ( ) , 'synchronized' => $ field -> isSynchronized ( ) , 'readonly' => $ field -> isReadonly ( ) , 'options' => $ field -> getOptions ( ) , ] ; } return new JsonResponse ( [ 'values' => $ data ] ) ; }
List fields .
18,928
public function createAction ( Request $ request ) { $ name = $ request -> get ( 'name' , 'new_set' ) ; $ metaSetManager = $ this -> get ( 'phlexible_meta_set.meta_set_manager' ) ; if ( $ metaSetManager -> findOneByName ( $ name ) ) { return new ResultResponse ( false , 'Name already in use.' ) ; } $ metaSet = $ metaSetManager -> createMetaSet ( ) ; $ metaSet -> setId ( UuidUtil :: generate ( ) ) -> setName ( $ name ) -> setCreateUser ( $ this -> getUser ( ) -> getDisplayName ( ) ) -> setCreatedAt ( new \ DateTime ( ) ) -> setModifyUser ( $ this -> getUser ( ) -> getDisplayName ( ) ) -> setModifiedAt ( new \ DateTime ( ) ) ; $ metaSetManager -> updateMetaSet ( $ metaSet ) ; return new ResultResponse ( true , "Meta Set {$metaSet->getName()} created." ) ; }
Create set .
18,929
public function renameAction ( Request $ request ) { $ id = $ request -> get ( 'id' ) ; $ name = $ request -> get ( 'name' ) ; $ metaSetManager = $ this -> get ( 'phlexible_meta_set.meta_set_manager' ) ; if ( $ metaSetManager -> findOneByName ( $ name ) ) { return new ResultResponse ( false , 'Name already in use.' ) ; } $ metaSet = $ metaSetManager -> find ( $ id ) ; $ oldName = $ metaSet -> getName ( ) ; $ metaSet -> setName ( $ name ) ; $ metaSetManager -> updateMetaSet ( $ metaSet ) ; return new ResultResponse ( true , "Meta Set $oldName renamed to $name." ) ; }
Rename set .
18,930
public function saveAction ( Request $ request ) { $ id = $ request -> get ( 'id' ) ; $ data = $ request -> get ( 'data' ) ; $ data = json_decode ( $ data , true ) ; $ metaSetManager = $ this -> get ( 'phlexible_meta_set.meta_set_manager' ) ; $ metaSet = $ metaSetManager -> find ( $ id ) ; $ metaSet -> setRevision ( $ metaSet -> getRevision ( ) + 1 ) ; $ fields = [ ] ; foreach ( $ metaSet -> getFields ( ) as $ field ) { $ fields [ $ field -> getId ( ) ] = $ field ; } foreach ( $ data as $ item ) { if ( ! empty ( $ item [ 'options' ] ) ) { $ options = [ ] ; foreach ( explode ( ',' , $ item [ 'options' ] ) as $ key => $ value ) { $ options [ $ key ] = trim ( $ value ) ; } $ item [ 'options' ] = implode ( ',' , $ options ) ; } if ( isset ( $ fields [ $ item [ 'id' ] ] ) ) { $ field = $ fields [ $ item [ 'id' ] ] ; unset ( $ fields [ $ item [ 'id' ] ] ) ; } else { $ field = $ metaSetManager -> createMetaSetField ( ) -> setId ( UuidUtil :: generate ( ) ) ; } $ field -> setName ( $ item [ 'key' ] ) -> setMetaSet ( $ metaSet ) -> setType ( $ item [ 'type' ] ) -> setRequired ( ! empty ( $ item [ 'required' ] ) ? 1 : 0 ) -> setSynchronized ( ! empty ( $ item [ 'synchronized' ] ) ? 1 : 0 ) -> setReadonly ( ! empty ( $ item [ 'readonly' ] ) ? 1 : 0 ) -> setOptions ( ! empty ( $ item [ 'options' ] ) ? $ item [ 'options' ] : null ) ; $ metaSet -> addField ( $ field ) ; } $ metaSet -> setModifyUser ( $ this -> getUser ( ) -> getDisplayName ( ) ) -> setModifiedAt ( new \ DateTime ( ) ) ; foreach ( $ fields as $ field ) { $ metaSet -> removeField ( $ field ) ; } $ metaSetManager -> updateMetaSet ( $ metaSet ) ; return new ResultResponse ( true , "Fields saved for set {$metaSet->getName()}." ) ; }
Save set .
18,931
public function getData ( $ key , $ defaultValue = null ) { $ key = $ this -> processKey ( $ key ) ; if ( ! $ this -> hasData ( $ key ) ) { return $ defaultValue ; } if ( is_array ( $ this -> shared [ $ key ] ) && isset ( $ this -> shared [ $ key ] [ '#value' ] ) ) { return $ this -> shared [ $ key ] [ '#value' ] ; } return $ this -> shared [ $ key ] ; }
Get data by key
18,932
public function hasData ( $ key ) { $ key = $ this -> processKey ( $ key ) ; return isset ( $ this -> shared [ $ key ] ) ; }
Check that data is set
18,933
protected function mergeDataEntry ( $ value , $ key ) { if ( ! isset ( $ this -> shared [ $ key ] ) ) { $ this -> shared [ $ key ] = $ value ; } elseif ( isset ( $ this -> shared [ $ key ] [ '#merged' ] ) ) { $ this -> shared [ $ key ] [ '#value' ] [ ] = $ value ; } else { $ oldValue = $ this -> shared [ $ key ] ; $ this -> shared [ $ key ] = [ '#merged' => true , '#value' => [ $ oldValue , $ value ] ] ; } }
Merge data entry with new one
18,934
public static function getSharedFromArgs ( $ arguments = [ ] , $ key = null , $ defaultValue = null ) { if ( $ key === null ) { return null ; } if ( ( $ instance = static :: instanceFromArguments ( $ arguments ) ) === null ) { return null ; } return $ instance -> getData ( $ key , $ defaultValue ) ; }
Get data from function arguments shared instance
18,935
public static function addSharedToArgs ( $ arguments = [ ] , $ value , $ key = null ) { if ( ( $ instance = static :: instanceFromArguments ( $ arguments ) ) === null ) { return null ; } return $ instance -> addData ( $ value , $ key ) ; }
Add data to chain instance from function arguments
18,936
public static function instanceFromArguments ( $ arguments = [ ] ) { $ arguments = array_values ( $ arguments ) ; $ argumentsCount = count ( $ arguments ) ; for ( $ i = 0 ; $ i < $ argumentsCount ; $ i ++ ) { if ( is_object ( $ arguments [ $ i ] ) && $ arguments [ $ i ] instanceof SharedDataInterface ) { return $ arguments [ $ i ] ; } } return null ; }
Get instance from function arguments
18,937
public function invoke ( $ methodName , array $ arguments = [ ] ) { $ this -> trigger ( self :: EVENT_BEFORE_METHOD ) ; $ result = call_user_func_array ( [ $ this -> o , $ methodName ] , $ arguments ) ; $ this -> trigger ( self :: EVENT_AFTER_METHOD ) ; return $ result ; }
Invoke method in decorated object
18,938
public static function instance ( $ name = null , array $ config = null , $ writable = true ) { \ Config :: load ( 'db' , true ) ; if ( $ name === null ) { $ name = \ Config :: get ( 'db.active' ) ; } if ( ! $ writable and ( $ readonly = \ Config :: get ( 'db.' . $ name . '.readonly' , false ) ) ) { ! isset ( static :: $ _readonly [ $ name ] ) and static :: $ _readonly [ $ name ] = \ Arr :: get ( $ readonly , array_rand ( $ readonly ) ) ; $ name = static :: $ _readonly [ $ name ] ; } if ( ! isset ( static :: $ instances [ $ name ] ) ) { if ( $ config === null ) { $ config = \ Config :: get ( 'db.' . $ name ) ; } if ( ! isset ( $ config [ 'type' ] ) ) { throw new \ FuelException ( 'Database type not defined in "' . $ name . '" configuration or "' . $ name . '" configuration does not exist' ) ; } $ driver = '\\Database_' . ucfirst ( $ config [ 'type' ] ) . '_Connection' ; new $ driver ( $ name , $ config ) ; } return static :: $ instances [ $ name ] ; }
Get a singleton Database instance . If configuration is not specified it will be loaded from the database configuration file using the same group as the name .
18,939
public function count_last_query ( ) { if ( $ sql = $ this -> last_query ) { $ sql = trim ( $ sql ) ; if ( stripos ( $ sql , 'SELECT' ) !== 0 ) { return false ; } if ( stripos ( $ sql , 'LIMIT' ) !== false ) { $ sql = preg_replace ( '/\sLIMIT\s+[^a-z]+/i' , ' ' , $ sql ) ; } if ( stripos ( $ sql , 'OFFSET' ) !== false ) { $ sql = preg_replace ( '/\sOFFSET\s+\d+/i' , '' , $ sql ) ; } $ result = $ this -> query ( \ DB :: SELECT , 'SELECT COUNT(*) AS ' . $ this -> quote_identifier ( 'total_rows' ) . ' ' . 'FROM (' . $ sql . ') AS ' . $ this -> quote_table ( 'counted_results' ) , true ) ; return ( int ) $ result -> current ( ) -> total_rows ; } return false ; }
Count the number of records in the last query without LIMIT or OFFSET applied .
18,940
public function count_records ( $ table ) { $ table = $ this -> quote_table ( $ table ) ; return $ this -> query ( \ DB :: SELECT , 'SELECT COUNT(*) AS total_row_count FROM ' . $ table , false ) -> get ( 'total_row_count' ) ; }
Count the number of records in a table .
18,941
protected function _parse_type ( $ type ) { if ( ( $ open = strpos ( $ type , '(' ) ) === false ) { return array ( $ type , null ) ; } $ close = strpos ( $ type , ')' , $ open ) ; $ length = substr ( $ type , $ open + 1 , $ close - 1 - $ open ) ; $ type = substr ( $ type , 0 , $ open ) . substr ( $ type , $ close + 1 ) ; return array ( $ type , $ length ) ; }
Extracts the text between parentheses if any .
18,942
public function table_prefix ( $ table = null ) { if ( $ table !== null ) { return $ this -> _config [ 'table_prefix' ] . $ table ; } return $ this -> _config [ 'table_prefix' ] ; }
Return the table prefix defined in the current configuration .
18,943
public function quote ( $ value ) { if ( $ value === null ) { return 'null' ; } elseif ( $ value === true ) { return "'1'" ; } elseif ( $ value === false ) { return "'0'" ; } elseif ( is_object ( $ value ) ) { if ( $ value instanceof Database_Query ) { return '(' . $ value -> compile ( $ this ) . ')' ; } elseif ( $ value instanceof Database_Expression ) { return $ value -> value ( ) ; } else { return $ this -> quote ( ( string ) $ value ) ; } } elseif ( is_array ( $ value ) ) { return '(' . implode ( ', ' , array_map ( array ( $ this , __FUNCTION__ ) , $ value ) ) . ')' ; } elseif ( is_int ( $ value ) ) { return ( int ) $ value ; } elseif ( is_float ( $ value ) ) { return sprintf ( '%F' , $ value ) ; } return $ this -> escape ( $ value ) ; }
Quote a value for an SQL query .
18,944
public function quote_identifier ( $ value ) { if ( $ value === '*' ) { return $ value ; } elseif ( is_object ( $ value ) ) { if ( $ value instanceof Database_Query ) { return '(' . $ value -> compile ( $ this ) . ')' ; } elseif ( $ value instanceof Database_Expression ) { return $ value -> value ( ) ; } else { return $ this -> quote_identifier ( ( string ) $ value ) ; } } elseif ( is_array ( $ value ) ) { list ( $ value , $ alias ) = $ value ; return $ this -> quote_identifier ( $ value ) . ' AS ' . $ this -> quote_identifier ( $ alias ) ; } if ( preg_match ( '/^(["\']).*\1$/m' , $ value ) ) { return $ value ; } if ( strpos ( $ value , '.' ) !== false ) { $ parts = explode ( '.' , $ value ) ; if ( $ prefix = $ this -> table_prefix ( ) ) { $ offset = count ( $ parts ) - 2 ; $ parts [ $ offset ] = $ prefix . $ parts [ $ offset ] ; } return implode ( '.' , array_map ( array ( $ this , __FUNCTION__ ) , $ parts ) ) ; } return $ this -> _identifier . str_replace ( $ this -> _identifier , $ this -> _identifier . $ this -> _identifier , $ value ) . $ this -> _identifier ; }
Quote a database identifier such as a column name . Adds the table prefix to the identifier if a table name is present .
18,945
public function start_transaction ( ) { $ result = true ; if ( $ this -> _transaction_depth == 0 ) { if ( $ this -> driver_start_transaction ( ) ) { $ this -> _in_transaction = true ; } else { $ result = false ; } } else { $ result = $ this -> set_savepoint ( $ this -> _transaction_depth ) ; isset ( $ result ) or $ result = true ; } $ result and $ this -> _transaction_depth ++ ; return $ result ; }
Begins a nested transaction on instance
18,946
public function commit_transaction ( ) { if ( $ this -> _transaction_depth <= 0 ) { return false ; } if ( $ this -> _transaction_depth - 1 ) { $ result = $ this -> release_savepoint ( $ this -> _transaction_depth - 1 ) ; ! isset ( $ result ) and $ result = true ; } else { $ this -> _in_transaction = false ; $ result = $ this -> driver_commit ( ) ; } $ result and $ this -> _transaction_depth -- ; return $ result ; }
Commits nested transaction
18,947
public function rollback_transaction ( $ rollback_all = true ) { if ( $ this -> _transaction_depth > 0 ) { if ( $ rollback_all or $ this -> _transaction_depth == 1 ) { if ( $ result = $ this -> driver_rollback ( ) ) { $ this -> _transaction_depth = 0 ; $ this -> _in_transaction = false ; } } else { $ result = $ this -> rollback_savepoint ( $ this -> _transaction_depth - 1 ) ; isset ( $ result ) or $ result = true ; $ result and $ this -> _transaction_depth -- ; } } else { $ result = false ; } return $ result ; }
Rollsback nested pending transaction queries . Rollback to the current level uses SAVEPOINT it does not work if current RDBMS does not support them . In this case system rollbacks all queries and closes the transaction
18,948
public function render ( $ name , array $ args = array ( ) ) { if ( $ this -> has ( $ name ) ) { $ callback = $ this -> widgets [ $ name ] ; return $ this -> executeCallback ( $ callback , $ args ) ; } return '' ; }
Render widget instance
18,949
protected function callStringCallback ( $ callback , $ args = [ ] ) { if ( strpos ( $ callback , '@' ) ) { list ( $ klass , $ method ) = explode ( '@' , $ callback ) ; } else { $ klass = $ callback ; $ method = 'render' ; } $ klass = isset ( $ this -> instantiatedWidgets [ $ klass ] ) ? $ this -> instantiatedWidgets [ $ klass ] : new $ klass ; return call_user_func_array ( [ $ klass , $ method ] , $ args ) ; }
Execute string callback
18,950
public function getModules ( ) { if ( $ this -> loadModules != 'ALL' ) { $ this -> connection -> select ( 'name' ) ; $ this -> connection -> from ( $ this -> tableModule ) ; $ modules = $ this -> connection -> get ( ) -> fetchAll ( \ PDO :: FETCH_ASSOC ) ; foreach ( $ modules as $ module ) { $ this -> getModule ( $ module [ 'name' ] ) ; } $ this -> loadModules = 'ALL' ; } return $ this -> modules ; }
Retorna todos los modulos de la aplicacion
18,951
public function getProfiles ( ) { if ( $ this -> loadProfiles != 'ALL' ) { $ this -> connection -> select ( 'name' ) ; $ this -> connection -> from ( $ this -> tableProfile ) ; $ profiles = $ this -> connection -> get ( ) -> fetchAll ( \ PDO :: FETCH_ASSOC ) ; foreach ( $ profiles as $ profile ) { $ this -> getProfile ( $ profile [ 'name' ] ) ; } $ this -> loadModules = 'ALL' ; } return $ this -> profiles ; }
Retorna todos los profiles de la aplicacion
18,952
public function string ( $ name , $ length = 255 , $ default = null ) { $ cmnd = $ name . ' varchar(' . $ length . ')' ; if ( ! empty ( $ default ) ) { $ cmnd .= " DEFAULT '$default' " ; } self :: $ colmuns [ ] = $ cmnd ; return $ this ; }
function to add varchar column .
18,953
public function bool ( $ name , $ default = null ) { $ cmnd = $ name . ' tinyint(1)' ; if ( ! empty ( $ default ) ) { $ default = $ default ? '1' : '0' ; $ cmnd .= " DEFAULT $default " ; } self :: $ colmuns [ ] = $ cmnd ; return $ this ; }
function to add bool column .
18,954
public function timestamp ( $ name , $ default = '' ) { $ cmnd = $ name . ' int(15)' ; if ( ! empty ( $ default ) ) { $ cmnd .= " DEFAULT $default " ; } self :: $ colmuns [ ] = $ cmnd ; return $ this ; }
function to add timestamp column .
18,955
public function affect ( $ value ) { $ i = Collection :: count ( self :: $ colmuns ) - 1 ; self :: $ colmuns [ $ i ] .= " default '" . $ value . "'" ; return $ this ; }
function to add default constraint .
18,956
public function notnull ( ) { $ i = Collection :: count ( self :: $ colmuns ) - 1 ; self :: $ colmuns [ $ i ] .= ' not null' ; return $ this ; }
function to add not null constraint .
18,957
public function foreignkey ( $ table , $ colmun = null ) { $ i = Collection :: count ( self :: $ colmuns ) - 1 ; self :: $ colmuns [ $ i ] .= ' references ' . $ table ; if ( ! empty ( $ colmun ) ) { self :: $ colmuns [ $ i ] .= '(' . $ colmun . ')' ; } return $ this ; }
function to add foreign key constraint .
18,958
public function unique ( $ name , array $ colmuns ) { if ( is_array ( $ colmuns ) ) { $ query = "CONSTRAINT $name UNIQUE (" ; for ( $ i = 0 ; $ i < Collection :: count ( $ colmuns ) ; $ i ++ ) { if ( $ i == Collection :: count ( $ colmuns ) - 1 ) { $ query .= $ colmuns [ $ i ] ; } else { $ query .= $ colmuns [ $ i ] . ',' ; } } $ query .= ')' ; self :: $ colmuns [ ] = $ query ; } return $ this ; }
function to add unique constraint .
18,959
public static function drop ( $ name ) { if ( self :: existe ( $ name ) ) { $ name = self :: table ( $ name ) ; return Database :: exec ( 'DROP TABLE ' . $ name ) ; } else { throw new SchemaTableNotExistException ( $ name ) ; } }
function to build query of table erasing .
18,960
public static function add ( $ name , $ script ) { if ( self :: existe ( $ name ) ) { $ name = self :: table ( $ name ) ; self :: $ query = 'alter table ' . $ name . ' ' ; $ object = new self ( ) ; $ script ( $ object ) ; $ query = '' ; for ( $ i = 0 ; $ i < Collection :: count ( self :: $ colmuns ) ; $ i ++ ) { $ query .= ' add ' . self :: $ colmuns [ $ i ] . ( ( $ i == ( Collection :: count ( self :: $ colmuns ) - 1 ) ) ? '' : ',' ) ; } self :: $ query .= $ query ; return Database :: exec ( self :: $ query ) ; } else { throw new SchemaTableNotExistException ( $ name ) ; } }
function to build query for adding column to table .
18,961
public static function remove ( $ name , $ colmuns ) { if ( self :: existe ( $ name ) ) { $ name = self :: table ( $ name ) ; self :: $ query = 'alter table ' . $ name . ' ' ; if ( is_array ( $ colmuns ) ) { for ( $ i = 0 ; $ i < Collection :: count ( $ colmuns ) ; $ i ++ ) { self :: $ query .= ' drop ' . $ colmuns [ $ i ] . ( ( $ i == ( Collection :: count ( $ colmuns ) - 1 ) ) ? '' : ',' ) ; } } else { self :: $ query .= ' drop ' . $ colmuns ; } return Database :: exec ( self :: $ query ) ; } else { throw new SchemaTableNotExistException ( $ name ) ; } }
function to build query for removing column to table .
18,962
public function image64 ( $ path ) { $ file = new File ( $ path , false ) ; if ( ! $ file -> isFile ( ) || 0 !== strpos ( $ file -> getMimeType ( ) , 'image/' ) ) { return ; } $ binary = file_get_contents ( $ path ) ; return sprintf ( 'data:image/%s;base64,%s' , $ file -> guessExtension ( ) , base64_encode ( $ binary ) ) ; }
Transform image to base 64
18,963
public function execute ( $ params = array ( ) , $ requestParams = array ( ) ) { $ deleteParams = $ params ; if ( count ( $ requestParams ) > 0 ) { $ deleteParams = $ requestParams ; } $ this -> beginTransaction ( ) ; $ firstResult = null ; try { $ this -> deleteI18nLocales ( $ deleteParams ) ; $ this -> deleteOneToOneRows ( $ deleteParams ) ; $ this -> getQueryBuilder ( ) -> where ( $ deleteParams ) ; $ query = $ this -> getQueryBuilder ( ) -> getQuery ( $ this -> entity , QueryBuilder :: DELETE_QUERY ) ; $ firstResult = $ this -> query ( $ query ) ; $ this -> commitTransaction ( ) ; } catch ( Exception $ e ) { $ this -> logger -> addError ( $ e -> getMessage ( ) ) ; $ this -> rollbackTransaction ( ) ; } return $ firstResult ; }
Deletes an entity row from the database
18,964
private function deleteI18nLocales ( $ params ) { if ( ! $ this -> entity instanceof AbstractI18nEntity ) { return ; } $ filter = array ( $ this -> entity -> getI18nIdentifier ( ) => $ params [ 'id' ] ) ; $ this -> getQueryBuilder ( ) -> where ( $ filter ) ; $ this -> query ( $ this -> getQueryBuilder ( ) -> getQuery ( $ this -> entity , QueryBuilder :: DELETE_QUERY , QueryBuilder :: CHILD_ONLY ) ) ; }
deletes a row from the I18n table
18,965
public function actionGenerate ( ) { $ this -> stdout ( "Polary Devkit Tool (based on Yii)\n\n" ) ; try { $ component = $ this -> getComponent ( ) ; $ configList = $ this -> getConfig ( $ component ) ; $ config = new Config ( [ 'files' => $ configList , ] ) ; $ builder = new Builder ( [ 'components' => $ config -> getComponents ( ) , 'template' => require __DIR__ . '/templates/helper.php' , ] ) ; if ( $ component -> result === null ) { $ component -> result = ( $ this -> getDetector ( ) -> detect ( ) === 'basic' ) ? '@app/_ide_components.php' : '@console/../_ide_components.php' ; } $ result = Yii :: getAlias ( $ component -> result ) ; $ result = FileHelper :: normalizePath ( $ result ) ; $ this -> stdout ( "Generate new IDE auto-completion code '{$result}'\n" ) ; $ time = microtime ( true ) ; $ builder -> build ( $ result ) ; $ this -> stdout ( 'New auto-completion code created successfully. (time: ' . sprintf ( '%.3f' , microtime ( true ) - $ time ) . "s)\n" , Console :: FG_GREEN ) ; } catch ( Exception $ exception ) { $ this -> stdout ( 'Generate failed ' . $ exception -> getMessage ( ) . "\n" , Console :: FG_RED ) ; } }
Generate IDE auto - completion code .
18,966
public function add ( $ id ) { if ( $ this -> has ( $ id ) ) { return $ this -> get ( $ id ) ; } $ menu = $ this -> container -> make ( Menu :: class , [ 'menuFactory' => $ this ] ) ; $ this -> runHook ( 'menu-factory:add' , [ $ this , $ menu ] ) ; $ this -> menus -> put ( $ id , $ menu ) ; return $ menu ; }
Creates a new menu or returns an existing
18,967
public function forget ( $ id ) { $ this -> runHook ( 'menu-factory:forget' , [ $ this , $ id ] ) ; $ this -> menus -> forget ( $ id ) ; return $ this ; }
Removes a menu
18,968
public function setCache ( \ Psr \ SimpleCache \ CacheInterface $ cache , $ key , $ ttl = 86400 ) { $ this -> cache = $ cache ; $ this -> cacheKey = $ key ; $ this -> cacheTime = $ ttl ; if ( empty ( $ this -> cacheKey ) ) { $ this -> cacheKey = 'concatenate-' . md5 ( serialize ( $ this ) ) ; } return $ this ; }
Set cache manager
18,969
public function addObject ( $ objectValue , $ filters ) { if ( empty ( $ objectValue ) ) { throw new \ Exception ( "Failed to add empty object value!" ) ; } $ object = null ; if ( strpos ( $ objectValue , 'http' ) !== false ) { $ object = new Items \ URL ( ) ; } else { $ object = new Items \ File ( $ this -> fileSearchDirectories ) ; } $ object -> initialize ( $ objectValue , $ filters ) ; $ this -> objectList [ ] = $ object ; return $ this ; }
Add an object to the list
18,970
public function concatenateObjectList ( ) { if ( empty ( $ this -> cache ) || empty ( $ this -> cacheKey ) || empty ( $ this -> cacheTime ) ) { $ this -> source = 'raw' ; $ this -> output = $ this -> concatenateObjects ( ) ; return ; } if ( ! $ this -> cacheRefresh && ( $ this -> output = $ this -> cache -> get ( $ this -> cacheKey ) ) !== null ) { $ this -> getActualLastModifiedTime ( ) ; $ lastCacheModifiedTime = $ this -> extractLastModifiedTime ( $ this -> output ) ; if ( $ lastCacheModifiedTime == $ this -> lastModifiedTime ) { $ this -> source = 'cache' ; return ; } } $ this -> output = $ this -> concatenateObjects ( ) ; $ this -> cache -> set ( $ this -> cacheKey , $ this -> output , $ this -> cacheTime ) ; $ this -> source = 'fetched' ; }
Concatenate the object list
18,971
private function getActualLastModifiedTime ( ) { if ( empty ( $ this -> objectList ) ) return ; foreach ( $ this -> objectList as $ object ) { $ modifiedTime = $ object -> getLastModifiedTimestamp ( ) ; if ( ! empty ( $ modifiedTime ) && $ modifiedTime > $ this -> lastModifiedTime ) { $ this -> lastModifiedTime = $ modifiedTime ; } } }
Gets actual last modified time of files to see if we need to bust cache
18,972
private function concatenateObjects ( ) { $ output = "" ; if ( empty ( $ this -> objectList ) ) return $ output ; foreach ( $ this -> objectList as $ object ) { if ( $ object -> isValid ( ) ) { $ output .= $ object -> getData ( ) ; $ modifiedTime = $ object -> getLastModifiedTimestamp ( ) ; if ( ! empty ( $ modifiedTime ) && $ modifiedTime > $ this -> lastModifiedTime ) { $ this -> lastModifiedTime = $ modifiedTime ; } } else { $ output .= $ this -> handleInvalidFile ( $ object -> getValue ( ) ) ; } } if ( ! empty ( $ this -> lastModifiedTime ) ) { $ output = $ this -> formatLastModifiedTime ( ) . $ output ; } return $ output ; }
Concatenate the actual files and set output
18,973
private function extractLastModifiedTime ( $ cacheData ) { $ matches = array ( ) ; preg_match ( '#modified:([a-z0-9:-]*)#i' , $ cacheData , $ matches ) ; if ( ! empty ( $ matches [ 1 ] ) ) { return strtotime ( $ matches [ 1 ] ) ; } return 0 ; }
Retrieve the last modified date from cached data
18,974
public function trigger ( $ value , $ precedence = null ) { if ( is_null ( $ precedence ) ) { $ functions = array ( ) ; ksort ( $ this -> hooks ) ; foreach ( $ this -> hooks as $ function_set ) { foreach ( $ function_set as $ function ) { $ functions [ ] = $ function ; } } foreach ( $ functions as $ function ) { $ value = call_user_func_array ( $ function , array ( $ value ) ) ; } return $ value ; } else { if ( isset ( $ this -> hooks [ $ precedence ] ) ) { foreach ( $ this -> hooks [ $ precedence ] as $ function ) { $ value = call_user_func_array ( $ function , array ( $ value ) ) ; } } return $ value ; } }
Invokes all hooks of a given precedence for a given event .
18,975
public function attachToXml ( $ data , $ prefix , & $ parentNode = false ) { if ( ! $ parentNode ) { $ parentNode = & $ this -> mainNode ; } if ( strtolower ( $ prefix ) == 'attributes' ) { foreach ( $ data as $ key => $ val ) { $ parentNode -> setAttribute ( $ key , $ val ) ; } $ node = & $ parentNode ; } else { $ node = $ this -> convertToXml ( $ data , $ prefix ) ; $ parentNode -> appendChild ( $ node ) ; } return $ node ; }
the heart of DOMi - take a complex data tree and build it into an XML tree with the specified prefix and attach it to either the specified node or the root node
18,976
public function convertToXml ( $ data , $ prefix ) { $ nodeName = $ prefix ; if ( ! self :: isValidPrefix ( $ prefix ) ) { throw new DomiException ( "invalid prefix '$prefix'" ) ; } if ( self :: isListNode ( $ data ) ) { $ nodeName = $ prefix . $ this -> listSuffix ; } switch ( self :: getDataType ( $ data ) ) { case self :: DT_ATTR_ARRAY : $ node = $ this -> createElement ( $ nodeName , isset ( $ data [ 'values' ] ) ? $ data [ 'values' ] : null ) ; $ data [ 'attributes' ] = isset ( $ data [ 'attributes' ] ) ? $ data [ 'attributes' ] : array ( ) ; foreach ( $ data [ 'attributes' ] as $ key => $ val ) { $ node -> setAttribute ( $ key , $ val ) ; } unset ( $ data [ 'attributes' ] ) ; unset ( $ data [ 'values' ] ) ; case self :: DT_ARRAY : if ( ! isset ( $ node ) ) { $ node = $ this -> createElement ( $ nodeName ) ; } foreach ( $ data as $ k => $ d ) { $ childPrefix = self :: isValidPrefix ( $ k ) ? $ k : $ prefix ; $ node -> appendChild ( $ this -> convertToXml ( $ d , $ childPrefix ) ) ; } break ; case self :: DT_DOMI : case self :: DT_DOMDOCUMENT : $ data = $ data -> childNodes -> item ( 0 ) ; case self :: DT_DOMNODE : $ domNode = $ this -> importNode ( $ data , true ) ; if ( $ prefix == $ domNode -> nodeName ) { $ node = $ domNode ; } else { $ node = $ this -> createElement ( $ prefix ) ; $ node -> appendChild ( $ domNode ) ; } break ; case self :: DT_OBJECT : $ node = $ this -> convertToXml ( $ this -> convertObjectToArray ( $ data ) , $ prefix ) ; break ; case self :: DT_BOOL : $ data = $ data ? 'TRUE' : 'FALSE' ; default : $ node = $ this -> createElement ( $ nodeName , htmlspecialchars ( ( string ) $ data ) ) ; break ; } return $ node ; }
convert a data tree to an XML tree with the name specified as the prefix
18,977
public function render ( $ stylesheets = false , $ mode = self :: RENDER_HTML ) { $ this -> xslt -> importStylesheet ( $ this -> generateXsl ( $ stylesheets ) ) ; return $ this -> generateOutput ( $ mode ) ; }
process and return the output that will be sent to screen during the display process
18,978
public function render ( $ response_sent , $ status = NULL ) { $ response = $ this -> _parse ( $ response_sent ) ; if ( is_null ( $ status ) ) { $ status = $ this -> getStatus ( $ this -> _default_header ) ; } elseif ( ! is_null ( $ status ) ) { $ status = $ this -> getStatus ( $ status ) ; } elseif ( ! is_null ( $ response [ 'status' ] ) ) { $ status = $ this -> getStatus ( $ response [ 'status' ] ) ; } else { $ status = $ this -> getStatus ( 500 ) ; } if ( ! headers_sent ( ) ) { if ( ! strpos ( PHP_SAPI , 'cgi' ) ) { header ( $ status ) ; } foreach ( $ response [ 'headers' ] as $ header ) { header ( $ header , false ) ; } } $ length = strlen ( $ response [ 'body' ] ) ; for ( $ i = 0 ; $ i < $ length ; $ i += $ this -> _config [ 'buffer_size' ] ) { echo substr ( $ response [ 'body' ] , $ i , $ this -> _config [ 'buffer_size' ] ) ; } }
Renderiza la respuesta completa
18,979
public function update ( $ component ) { $ component = $ this -> component -> findOrFail ( $ component ) ; $ packages = $ component -> getComposerAttr ( 'require' , [ ] ) ; chdir ( base_path ( ) ) ; foreach ( $ packages as $ name => $ version ) { $ package = "\"{$name}:{$version}\"" ; $ this -> run ( "composer require {$package}" ) ; } }
Update the dependencies for the specified component by given the component name .
18,980
public function setFromData ( $ data ) { $ model = $ this ; $ chk = self :: CHECK_SIGNATURE ; if ( $ chk && ! isset ( $ data [ 'signature' ] ) ) { throw new InvalidParameter ( "All decoded requests must have a signature." ) ; } if ( $ chk && $ data [ 'signature' ] != self :: calculateSignature ( $ data ) ) { throw new InvalidParameter ( "Leave now, and Never come Back! *gollem, gollem* (Decoded request signature mismatch)." ) ; } if ( isset ( $ data [ 'data' ] ) && ! empty ( $ data [ 'data' ] ) ) { $ model -> setData ( $ data [ 'data' ] ) ; } else if ( isset ( $ data [ 'body' ] ) ) { $ model -> setBody ( $ data [ 'body' ] ) ; } if ( isset ( $ data [ 'headers' ] ) ) { $ model -> setHeaders ( $ data [ 'headers' ] ) ; } if ( isset ( $ data [ 'cookies' ] ) ) { $ model -> setCookies ( $ data [ 'cookies' ] ) ; } if ( isset ( $ data [ 'post' ] ) ) { $ model -> setPost ( $ data [ 'post' ] ) ; } if ( isset ( $ data [ 'status' ] ) ) { $ model -> setStatus ( $ data [ 'status' ] ) ; } return $ model ; }
Serialize & deserialize requests
18,981
public function hasData ( ) { if ( ! isset ( $ this -> data ) ) { if ( ! isset ( $ this -> error ) ) $ this -> setError ( 'No input data set' ) ; return false ; } else { return true ; } }
Check if request has data
18,982
public function buildLeaf ( $ uniqueKey = null , $ parentKey = null ) { if ( isset ( $ this -> crown [ $ uniqueKey ] ) ) { throw new InvalidArgumentException ( sprintf ( 'The leaf with key "%s" is already exists.' , $ uniqueKey ) ) ; } if ( $ parentKey && ! isset ( $ this -> crown [ $ parentKey ] ) ) { throw new InvalidArgumentException ( sprintf ( 'Unknown leaf "%s" specified as parent.' , $ parentKey ) ) ; } $ leaf = clone $ this -> getLeafPrototype ( ) ; $ this -> injectInCrown ( $ leaf , $ uniqueKey ) ; if ( $ parentKey ) { $ parent = $ this -> crown [ $ parentKey ] ; $ parent -> addChild ( $ leaf ) ; } else { $ this -> branch [ $ leaf -> getUniqueKey ( ) ] = $ leaf ; $ leaf -> setDepth ( 0 ) ; } return $ leaf ; }
Builds the leaf .
18,983
public function getLeaf ( $ uniqueKey ) { if ( ! isset ( $ this -> crown [ $ uniqueKey ] ) ) { throw new InvalidArgumentException ( sprintf ( 'The leaf with unique key "%s" not exists.' , $ uniqueKey ) ) ; } return $ this -> crown [ $ uniqueKey ] ; }
Gets the specified leaf .
18,984
public function current ( ) { if ( is_null ( $ this -> current ) ) { $ this -> current = current ( $ this -> branch ) ; } if ( $ this -> current instanceof RecursiveLeafInterface ) { return $ this -> current -> current ( ) ; } return false ; }
Returns the current leaf .
18,985
protected function injectInCrown ( RecursiveLeafInterface $ leaf , $ uniqueKey = null ) { if ( is_null ( $ uniqueKey ) ) { $ this -> crown [ ] = null ; $ uniqueKey = key ( array_slice ( $ this -> crown , - 1 , 1 , true ) ) ; } $ leaf -> setUniqueKey ( $ uniqueKey ) ; $ this -> crown [ $ uniqueKey ] = $ leaf ; }
Injects leaf in crown of the tree .
18,986
public static function count ( string $ text = '' , int $ minWorldLength = 0 ) : int { if ( \ trim ( $ text ) === '' ) { return 0 ; } $ text = StripTags :: strip ( $ text ) ; $ text = \ htmlspecialchars_decode ( ( string ) $ text , ENT_COMPAT | ENT_HTML5 ) ; $ text = \ preg_replace ( '/[^\w[:space:]]/u' , '' , $ text ) ; if ( $ minWorldLength > 1 ) { $ text = \ preg_replace ( '/(\b\w{1,' . ( $ minWorldLength - 1 ) . '}\b)/u' , ' ' , $ text ) ; } $ text = \ trim ( \ preg_replace ( '/\s+/' , ' ' , $ text ) ) ; if ( $ text === '' ) { return 0 ; } $ words = \ explode ( ' ' , $ text ) ; return \ count ( $ words ) ; }
Counts words with provided min length
18,987
public function registerSubscriptions ( EventDispatcher $ dispatcher ) { if ( $ this -> registered ) { throw new \ RuntimeException ( 'Cannot register debug toolbar subscriptions when already registered.' ) ; } foreach ( $ this -> toolbar -> getExtensions ( ) as $ extension ) { if ( ! $ extension instanceof EventSubscriberInterface ) { continue ; } $ dispatcher -> addSubscriber ( $ extension ) ; } $ this -> registered = true ; }
Register the subscriptions for extensions that have them .
18,988
public function doCompile ( $ activeConfig , $ context = 'main' , $ value = '' ) { $ tempConfig = [ ] ; while ( ! empty ( $ activeConfig ) ) { $ lineConfig = array_shift ( $ activeConfig ) ; $ tempConfig [ ] = $ this -> subCompile ( $ activeConfig , $ lineConfig ) ; } return $ this -> buildBlockDirective ( $ context , $ value , $ tempConfig ) ; }
Does a nested array of lines depending on container Directives .
18,989
private function subCompile ( & $ activeConfig , $ lineConfig ) { if ( preg_match ( $ this -> startMultiLine , $ lineConfig , $ container ) ) { return $ this -> findEndingKey ( trim ( $ container [ 'key' ] ) , trim ( $ container [ 'value' ] ) , $ activeConfig ) ; } if ( ! preg_match ( $ this -> simpleDirective , $ lineConfig , $ container ) ) { throw InvalidConfigException :: forSimpleDirectiveSyntaxError ( $ lineConfig ) ; } return $ this -> buildSimpleDirective ( trim ( $ container [ 'key' ] ) , trim ( $ container [ 'value' ] ) ) ; }
Looks for a container directive .
18,990
private function findEndingKey ( $ context , $ contextValue , & $ activeConfig ) { $ lines = [ ] ; $ endMultiLine = sprintf ( $ this -> endMultiLine , $ context ) ; while ( ! empty ( $ activeConfig ) ) { $ lineConfig = array_shift ( $ activeConfig ) ; if ( preg_match ( $ endMultiLine , $ lineConfig ) ) { return $ this -> buildBlockDirective ( $ context , $ contextValue , $ lines ) ; } $ lines [ ] = $ this -> subCompile ( $ activeConfig , $ lineConfig ) ; } throw InvalidConfigException :: forEndingKeyNotFound ( $ context ) ; }
Finds the end of a container directive .
18,991
private function buildBlockDirective ( $ context , $ contextValue , $ lines ) { $ class = 'WebHelper\Parser\Directive\BlockDirective' ; $ known = $ this -> parser -> getServer ( ) -> getKnownDirectives ( ) ; if ( in_array ( $ context , array_keys ( $ known ) ) ) { if ( isset ( $ known [ $ context ] [ 'class' ] ) ) { $ class = 'WebHelper\Parser\Directive\\' . $ known [ $ context ] [ 'class' ] ; } } $ block = new $ class ( $ context , $ contextValue ) ; foreach ( $ lines as $ directive ) { $ block -> add ( $ directive ) ; } return $ block ; }
Builds a BlockDirective .
18,992
private function buildSimpleDirective ( $ key , $ value ) { $ known = $ this -> parser -> getServer ( ) -> getKnownDirectives ( ) ; if ( in_array ( $ key , array_keys ( $ known ) ) ) { if ( isset ( $ known [ $ key ] [ 'class' ] ) ) { $ class = 'WebHelper\Parser\Directive\\' . $ known [ $ key ] [ 'class' ] ; return new $ class ( $ key , $ value , $ this -> parser ) ; } } return new SimpleDirective ( $ key , $ value ) ; }
Build a SimpleDirective or an InclusionDirective .
18,993
public static function instance ( $ className = __CLASS__ ) { if ( ! isset ( self :: $ instances [ $ className ] ) ) { self :: $ instances [ $ className ] = new $ className ; } return self :: $ instances [ $ className ] ; }
Get Model instance
18,994
public function redirectCheck ( ) { if ( isset ( $ _COOKIE [ 'twofactorDir-' . $ this -> dir ] ) && $ _COOKIE [ 'twofactorDir-' . $ this -> dir ] == $ this -> cookieCode ) { self :: redirect ( ) ; return true ; } else { return false ; } }
CAUTION this method uses cookie it must be called before any print this method check if the cookie exists and if it is correct if it is correct the method perform redirect
18,995
public function checkCode ( $ code ) { $ res = $ this -> twofactorAdapter -> check ( $ code ) ; if ( $ res ) { setcookie ( 'twofactorDir-' . $ this -> dir , $ this -> cookieCode , 0 , "/" ) ; self :: redirect ( ) ; } return $ res ; }
CAUTION this method uses cookie it must be called before any print this method checks code and performs login this method perform redirect if the code is correct after setting the cookie
18,996
static public function install ( $ dir = "." ) { $ cookieCode = md5 ( rand ( ) ) ; $ strReplaceS = array ( "{SRC_DIR}" , "{CUR_DIR}" , "{COOKIE_CODE}" ) ; $ strReplaceR = array ( __DIR__ . "/.." , $ dir , $ cookieCode ) ; $ f = fopen ( $ dir . "/.htaccess" , "a" ) ; if ( strpos ( file_get_contents ( $ dir . "/.htaccess" ) , "##START twofactor-dir" ) === false ) { fwrite ( $ f , str_replace ( $ strReplaceS , $ strReplaceR , file_get_contents ( __DIR__ . "/../files/x.htaccess" ) ) ) ; } else { $ preg = "/RewriteCond %{HTTP_COOKIE} !twofactorDir-.*=(.*)/" ; $ ret = array ( ) ; preg_match ( $ preg , file_get_contents ( $ dir . "/.htaccess" ) , $ ret ) ; $ strReplaceR [ 2 ] = $ ret [ 1 ] ; } fclose ( $ f ) ; $ f = fopen ( $ dir . "/redirect.php" , "w" ) ; fwrite ( $ f , str_replace ( $ strReplaceS , $ strReplaceR , file_get_contents ( __DIR__ . "/../files/redirect.php" ) ) ) ; fclose ( $ f ) ; $ f = fopen ( $ dir . "/get_qr.php" , "w" ) ; fwrite ( $ f , str_replace ( $ strReplaceS , $ strReplaceR , file_get_contents ( __DIR__ . "/../files/get_qr.php" ) ) ) ; fclose ( $ f ) ; fclose ( fopen ( $ dir . "/secret.php" , "a" ) ) ; }
Install library into a dir
18,997
private function closeCursor ( ) { try { if ( $ this -> stmt ) { $ this -> stmt -> closeCursor ( ) ; } } catch ( \ PDOException $ e ) { die ( "Error: " . $ e -> getMessage ( ) ) ; } }
Closes cursor for next execution
18,998
public function getRow ( $ fetch_style = null ) { if ( is_null ( $ fetch_style ) ) { $ fetch_style = \ PDO :: FETCH_ASSOC ; } try { return $ this -> stmt -> fetch ( $ fetch_style ) ; } catch ( \ PDOException $ e ) { die ( "Error: " . $ e -> getMessage ( ) ) ; } }
Returns a next row from a result set
18,999
public function prepare ( string $ sql , $ standalone = false ) { try { $ stmt = $ this -> dbh -> prepare ( $ sql ) ; if ( $ standalone ) { return $ stmt ; } else { $ this -> stmt = $ stmt ; } return $ this ; } catch ( \ PDOException $ e ) { die ( "Error: " . $ e -> getMessage ( ) ) ; } }
Prepares an SQL statement