idx
int64
0
60.3k
question
stringlengths
64
4.24k
target
stringlengths
5
618
14,800
public function socialLink ( $ provider , $ providerKey , $ userid = null ) { $ this -> debug -> groupCollapsed ( __METHOD__ ) ; if ( $ userid === null ) { $ userid = $ this -> userid ; } $ vals = array ( 'userid' => $ userid , 'provider' => strtolower ( $ provider ) , 'providerkey' => $ providerKey , ) ; $ where = array ( 'provider' => strtolower ( $ provider ) , 'providerkey' => $ providerKey , ) ; $ found = $ this -> db -> query ( 'SELECT * FROM `user_social` ' . $ this -> db -> buildWhere ( $ where ) ) [ 0 ] ; if ( $ found ) { $ this -> socialUnlink ( $ found [ 0 ] [ 'provider' ] , $ found [ 0 ] [ 'providerkey' ] ) ; } $ this -> db -> rowMan ( 'user_social' , $ vals ) ; $ this -> log ( 'socialLink' , $ userid , array ( 'provider' => strtolower ( $ provider ) , 'providerKey' => $ providerKey , ) ) ; $ this -> debug -> groupEnd ( ) ; return ; }
Link user to a authentication provider
14,801
public function socialUnlink ( $ provider , $ userid = null ) { $ this -> debug -> groupCollapsed ( __METHOD__ ) ; if ( $ userid === null ) { $ userid = $ this -> userid ; } $ where = array ( 'userid' => $ userid , 'provider' => strtolower ( $ provider ) , ) ; $ this -> db -> rowMan ( 'user_social' , null , $ where ) ; $ this -> log ( 'sociaUnlink' , $ userid , array ( 'provider' => strtolower ( $ provider ) , ) ) ; $ this -> debug -> groupEnd ( ) ; return ; }
unlink user from authentication provider
14,802
public function verifyEmailToken ( $ token ) { $ this -> debug -> groupCollapsed ( __METHOD__ ) ; $ return = false ; $ token = base64_decode ( $ token ) ; $ vals = array ( 'token_hash' => $ this -> db -> quoteValue ( sha1 ( $ token ) ) , ) ; $ query = Str :: quickTemp ( 'SELECT * FROM `email_tokens` WHERE `token_hash` = [::token_hash::]' , $ vals ) ; $ rows = $ this -> db -> query ( $ query ) [ 0 ] ; $ this -> debug -> table ( $ rows , 'rows' ) ; if ( $ rows ) { $ return = $ rows [ 0 ] [ 'userid' ] ; $ where = $ vals ; $ this -> db -> rowMan ( 'email_tokens' , null , $ where ) ; $ this -> log ( 'pwForgotTokenSuccess' , $ rows [ 0 ] [ 'userid' ] ) ; } else { $ this -> log ( 'pwForgotTokenFail' ) ; } $ this -> debug -> groupEnd ( ) ; return $ return ; }
verifies a token sent via email searches for token in db if found will remove from db
14,803
private function genToken ( $ tokenLen = null ) { $ this -> debug -> groupCollapsed ( __METHOD__ ) ; $ tokenLen = isset ( $ tokenLen ) ? $ tokenLen : $ this -> cfg [ 'tokenLen' ] ; $ token = '' ; if ( function_exists ( 'mcrypt_create_iv' ) && ! defined ( 'PHALANGER' ) ) { $ token = mcrypt_create_iv ( $ tokenLen , MCRYPT_DEV_URANDOM ) ; } if ( empty ( $ token ) && function_exists ( 'openssl_random_pseudo_bytes' ) ) { $ token = openssl_random_pseudo_bytes ( $ tokenLen ) ; } if ( empty ( $ token ) && is_readable ( '/dev/urandom' ) ) { $ file = fopen ( '/dev/urandom' , 'r' ) ; $ len = strlen ( $ token ) ; while ( $ len < $ tokenLen ) { $ token .= fread ( $ file , $ tokenLen - $ len ) ; $ len = strlen ( $ token ) ; } fclose ( $ file ) ; } $ this -> debug -> log ( 'token' , $ token ) ; $ this -> debug -> groupEnd ( ) ; return $ token ; }
generate crypto strength token
14,804
private function hashPassword ( $ pwClear ) { $ this -> debug -> groupCollapsed ( __METHOD__ ) ; $ this -> debug -> time ( 'hash' ) ; $ hash = password_hash ( $ pwClear , $ this -> cfg [ 'passwordHashAlgo' ] , $ this -> cfg [ 'passwordHashOptions' ] ) ; $ this -> debug -> log ( 'hash' , strlen ( $ hash ) , $ hash ) ; $ this -> debug -> timeEnd ( 'hash' ) ; $ this -> debug -> groupEnd ( ) ; return $ hash ; }
returns hashed password
14,805
private function resume ( ) { $ this -> debug -> groupCollapsed ( __METHOD__ ) ; if ( isset ( $ _SESSION ) ) { $ this -> user = ArrayUtil :: pathGet ( $ _SESSION , $ this -> cfg [ 'sessionPath' ] ) ; } if ( ! empty ( $ this -> user ) ) { $ this -> debug -> info ( 'resuming from session' ) ; if ( isset ( $ this -> user [ '_ts_cur' ] ) ) { $ this -> user [ 'lastactivity' ] = $ this -> user [ '_ts_cur' ] ; } $ this -> userid = $ this -> user [ 'userid' ] ; $ this -> auth_via = 'session' ; $ this -> auth = 2 ; if ( $ this -> user [ 'lastactivity' ] + $ this -> cfg [ 'maxIdle' ] < time ( ) ) { $ this -> debug -> warn ( 'idle' ) ; $ this -> debug -> log ( 'lastactivity' , $ this -> user [ 'lastactivity' ] ) ; $ this -> auth = 0 ; } else { $ this -> update ( array ( 'lastactivity' => 'NOW()' ) ) ; } } if ( empty ( $ this -> auth ) && isset ( $ _COOKIE [ $ this -> cfg [ 'persistCookie' ] [ 'name' ] ] ) ) { $ persist_vals = Cookie :: get ( $ this -> cfg [ 'persistCookie' ] [ 'name' ] ) ; $ userid = isset ( $ persist_vals [ 'username' ] ) && isset ( $ persist_vals [ 'token' ] ) ? $ this -> verifyPersistToken ( $ persist_vals [ 'username' ] , $ persist_vals [ 'token' ] ) : null ; if ( $ userid ) { $ this -> debug -> info ( 'resuming from persist token' ) ; $ this -> setCurrent ( $ userid ) ; $ this -> setPersistToken ( ) ; $ this -> auth_via = 'cookie' ; $ this -> auth = 1 ; } } if ( empty ( $ this -> auth ) ) { } if ( ! empty ( $ this -> auth ) ) { $ this -> user [ '_ts_cur' ] = time ( ) ; } $ this -> debug -> groupEnd ( ) ; }
attempts to load user data from session or via persistant login cookie
14,806
public function lastInsertId ( $ name = null ) { if ( is_null ( $ name ) ) { throw new \ Exception ( 'Postgres requires a sequence name to get the last insert ID' ) ; } $ primary_key = $ this -> getPrimaryKey ( $ name ) ; $ id = $ this -> pdo -> lastInsertId ( $ name . '_' . $ primary_key . '_seq' ) ; if ( $ id === false || is_null ( $ id ) ) { throw new \ Exception ( "Can't get last insert ID for " . $ name . "; you must supply the correct sequence name." ) ; } return $ id ; }
Wrappers for some useful PDO functions
14,807
public static function toLeftFoldable ( $ input ) { Arguments :: define ( Boa :: leftFoldable ( ) ) -> check ( $ input ) ; if ( $ input instanceof LeftFoldableInterface ) { return $ input ; } if ( is_array ( $ input ) || $ input instanceof ArrayObject ) { return static :: toList ( $ input ) ; } if ( $ input instanceof Traversable ) { return new TraversableLeftFoldable ( $ input ) ; } throw new CoreException ( 'Unable to build LeftFoldable' ) ; }
Wrap the provided value inside a LeftFoldable .
14,808
public static function toFunctor ( $ input ) { Arguments :: define ( Boa :: leftFoldable ( ) ) -> check ( $ input ) ; if ( $ input instanceof FunctorInterface ) { return $ input ; } if ( is_array ( $ input ) || $ input instanceof ArrayObject ) { return static :: toList ( $ input ) ; } throw new CoreException ( 'Unable to build Functor' ) ; }
Wrap the provided value inside a Functor .
14,809
public static function toList ( $ input ) { Arguments :: define ( Boa :: lst ( ) ) -> check ( $ input ) ; if ( $ input instanceof ListInterface ) { return $ input ; } return ArrayList :: of ( $ input ) ; }
Wrap provided value inside a List .
14,810
public static function toFoldable ( $ input ) { Arguments :: define ( Boa :: foldable ( ) ) -> check ( $ input ) ; if ( $ input instanceof FoldableInterface ) { return $ input ; } if ( is_array ( $ input ) || $ input instanceof ArrayObject ) { return static :: toList ( $ input ) ; } throw new CoreException ( 'Unable to build Foldable' ) ; }
Wrap provided value inside a Foldable .
14,811
public static function toReadMap ( $ input ) { Arguments :: define ( Boa :: readMap ( ) ) -> check ( $ input ) ; if ( $ input instanceof ReadMapInterface ) { return $ input ; } if ( is_array ( $ input ) || $ input instanceof ArrayObject || $ input instanceof ArrayAccess ) { return static :: toMap ( $ input ) ; } if ( $ input instanceof Traversable ) { return new TraversableLeftFoldable ( $ input ) ; } throw new CoreException ( 'Unable to build ReadMap' ) ; }
Wrap the provided value inside a ReadMap .
14,812
public static function toMap ( $ input ) { Arguments :: define ( Boa :: map ( ) ) -> check ( $ input ) ; if ( $ input instanceof MapInterface ) { return $ input ; } if ( is_array ( $ input ) || $ input instanceof ArrayObject ) { return new ArrayMap ( $ input ) ; } if ( $ input instanceof ArrayAccess ) { return new ArrayAccessMap ( $ input ) ; } throw new CoreException ( 'Unable to build Map' ) ; }
Wrap the provided value inside a Map .
14,813
protected function clearParams ( ) { $ this -> limit = null ; $ this -> limitStart = false ; $ this -> limitEnd = false ; $ this -> where = null ; $ this -> orderBy = null ; $ this -> groupBy = null ; $ this -> in = null ; $ this -> params = [ ] ; $ this -> joins = [ ] ; $ this -> query = '' ; }
Set params default value
14,814
public function match ( $ input ) { if ( $ this -> token instanceof Token ) { if ( $ this -> token -> matches ( $ input ) ) { return true ; } return false ; } if ( $ this -> token === $ input ) { return true ; } return false ; }
Returns true is the given token matches the Condition s token
14,815
public function matched ( $ input ) { if ( $ this -> token instanceof Token ) { return $ this -> token -> matched ( $ input ) ; } return $ input ; }
Returns information about the matched token .
14,816
public function colorize ( string $ startColor , string $ text , string $ endColor = self :: NORMAL ) : string { if ( $ this -> getEnableColoredOutput ( ) ) { return $ startColor . $ text . $ endColor ; } return $ text ; }
Wrap the text in colors
14,817
public static function GetFileNames ( $ dir , $ filters = array ( ) ) { $ filenames = array_diff ( scandir ( $ dir ) , array ( '..' , '.' ) ) ; if ( count ( $ filters > 0 ) ) { $ filenames = self :: FilterArray ( $ filenames , $ filters ) ; } return $ filenames ; }
Get the file paths for the current directory
14,818
public static function FilterArray ( $ targetArray , $ valuesToRemove ) { if ( is_array ( $ valuesToRemove ) ) { foreach ( $ valuesToRemove as $ value ) { if ( ( $ key = array_search ( $ value , $ targetArray ) ) !== false ) { unset ( $ targetArray [ $ key ] ) ; } else { } } } else { } return $ targetArray ; }
Filter values out of a given array of values .
14,819
public static function GetApplicationRootDir ( ) { return \ Puzzlout \ Framework \ Enums \ ApplicationFolderName :: AppsFolderName . "APP_NAME" . \ Puzzlout \ Framework \ Enums \ ApplicationFolderName :: ViewsFolderName ; }
Get the directory where are stored the current Application views .
14,820
public function View ( $ Name , $ SQL ) { if ( is_string ( $ SQL ) ) { $ SQLString = $ SQL ; $ SQL = NULL ; } else { $ SQLString = $ SQL -> GetSelect ( ) ; } $ Result = $ this -> Query ( 'create or replace view ' . $ this -> _DatabasePrefix . $ Name . " as \n" . $ SQLString ) ; if ( ! is_null ( $ SQL ) ) { $ SQL -> Reset ( ) ; } }
Specifies the name of the view to create or modify .
14,821
public function error ( ) { $ errors = $ this -> validator -> errors ( ) ; $ this -> error = empty ( $ errors ) ? : array_pop ( $ errors ) [ 0 ] ; return $ this -> error ; }
Get first validation error if exists .
14,822
public function equals ( InputOption $ option ) { return $ option -> getName ( ) === $ this -> getName ( ) && $ option -> getShortcut ( ) === $ this -> getShortcut ( ) && $ option -> getDefault ( ) === $ this -> getDefault ( ) && $ option -> isArray ( ) === $ this -> isArray ( ) && $ option -> isValueRequired ( ) === $ this -> isValueRequired ( ) && $ option -> isValueOptional ( ) === $ this -> isValueOptional ( ) ; }
Checks whether the given option equals this one .
14,823
public function getPath ( $ serviceName ) { if ( in_array ( $ serviceName , $ this -> services ) ) { return str_replace ( '_' , '/' , $ serviceName ) ; } else { $ services = implode ( ', ' , $ this -> services ) ; throw new \ Exception ( "Service \"{$serviceName}\" is not one of: {$services}" ) ; } }
Gets the path of a service .
14,824
public static function checkConnections ( $ connection_name , $ table , $ check ) { if ( $ check === true ) { $ connections = DB :: connection ( $ connection_name ) -> table ( $ table ) -> get ( ) ; foreach ( $ connections as $ connection ) { $ name = $ connection -> name ; try { $ testConnection = DB :: connection ( $ name ) -> getPdo ( ) ; } catch ( \ Exception $ e ) { $ error = $ e -> getMessage ( ) ; \ error_log ( $ error ) ; } if ( ! empty ( $ testConnection ) && empty ( $ error ) ) { $ update = DB :: connection ( $ connection_name ) -> table ( $ table ) -> where ( 'name' , $ name ) -> update ( [ 'status' => true ] ) ; } else { $ update = DB :: connection ( $ connection_name ) -> table ( $ table ) -> where ( 'name' , $ name ) -> update ( [ 'status' => false ] ) ; } } } }
checkConnections function .
14,825
public static function random_string ( $ length ) { $ key = '' ; $ keys = array_merge ( range ( 0 , 9 ) , range ( 'a' , 'z' ) ) ; for ( $ i = 0 ; $ i < $ length ; $ i ++ ) { $ key .= $ keys [ array_rand ( $ keys ) ] ; } return $ key ; }
random_string function Does what it says on the tin .
14,826
public static function fromXml ( \ DOMNodeList $ xml ) { $ value = null ; if ( $ xml -> length > 0 ) { $ value = new \ DateTimeImmutable ( $ xml -> item ( 0 ) -> textContent ) ; } return new static ( $ value ) ; }
Builds a DateTime object from XML .
14,827
public function addDatabase ( Database $ database ) { if ( ! $ this -> getDatabases ( ) -> contains ( $ database ) ) { $ database -> setId ( $ this -> getDatabases ( ) -> count ( ) ) ; $ database -> setInstance ( $ this ) ; $ this -> getDatabases ( ) -> add ( $ database ) ; } }
Add database to the list
14,828
public function removeDatabase ( Database $ database ) { if ( $ this -> getDatabases ( ) -> contains ( $ database ) ) { $ this -> getDatabases ( ) -> remove ( $ database ) ; } }
Remove database from the list
14,829
public function boot ( Application $ app ) { $ app -> get ( '/api.js' , function ( Application $ app ) { return $ app [ 'direct.api' ] -> getApi ( ) ; } ) -> bind ( 'directapi' ) ; $ app -> get ( '/remoting.js' , function ( Application $ app ) { return $ app [ 'direct.api' ] -> getRemoting ( ) ; } ) ; $ app -> post ( '/route' , function ( Application $ app ) { return $ app [ 'direct.router' ] -> route ( ) ; } ) ; }
Setup the application .
14,830
public function execute ( $ sql , array $ parameters = [ ] ) { $ sth = $ this -> prepare ( $ sql ) ; $ sth -> execute ( $ parameters ) ; return $ sth ; }
Prepares and executes a prepared statement
14,831
public function trigger ( $ event ) { if ( is_string ( $ event ) ) { $ event = new Event ( $ event ) ; } $ listeners = $ this -> getListeners ( $ event -> name ) ; if ( empty ( $ listeners ) ) { return $ event ; } $ urgency = ksort ( $ listeners , SORT_NUMERIC ) ; $ callbacks = array_reverse ( $ listeners , true ) ; foreach ( $ callbacks as $ priority => $ listener ) { if ( $ event -> isStopped ( ) ) { break ; } foreach ( $ listener as $ callback ) { if ( $ event -> isStopped ( ) ) { break ; } $ this -> propergate ( $ event , $ callback ) ; } } return $ event ; }
Triggers an event ;
14,832
public function getListeners ( $ eventName = null ) { if ( empty ( $ eventName ) ) return $ this -> listeners ; if ( ! empty ( $ eventName ) && ! isset ( $ this -> listeners [ $ eventName ] ) ) return [ ] ; return $ this -> listeners [ $ eventName ] ; }
Returns the callbacks attached to a specific event ;
14,833
protected function propergate ( & $ event , $ callback ) { $ result = call_user_func ( $ callback [ 'callable' ] , $ event , $ callback [ 'params' ] ) ; if ( $ result === false ) { $ event -> stop ( ) ; } if ( $ result !== null ) { $ event -> setResult ( $ result ) ; } }
Propergate the event to all callbacks ;
14,834
public function listeners ( $ event_name ) { if ( ! $ this -> have_read_from_file ) { $ this -> readConfigFile ( ) ; } if ( ! isset ( $ this -> listeners [ $ event_name ] ) ) { return [ ] ; } if ( ! $ this -> listeners [ $ event_name ] [ 0 ] ) { array_multisort ( $ this -> listeners [ $ event_name ] [ 1 ] , SORT_NUMERIC , $ this -> listeners [ $ event_name ] [ 2 ] ) ; $ this -> listeners [ $ event_name ] [ 0 ] = true ; } return $ this -> listeners [ $ event_name ] [ 2 ] ; }
Returns an array of listeners for a single event . They are sorted by priority .
14,835
public function removeListener ( $ event_name , callable $ listener ) { if ( ! $ this -> have_read_from_file ) { $ this -> readConfigFile ( ) ; } if ( ! isset ( $ this -> listeners [ $ event_name ] ) ) { return false ; } foreach ( $ this -> listeners [ $ event_name ] [ 2 ] as $ index => $ check ) { if ( $ check === $ listener ) { unset ( $ this -> listeners [ $ event_name ] [ 1 ] [ $ index ] ) ; unset ( $ this -> listeners [ $ event_name ] [ 2 ] [ $ index ] ) ; return true ; } } return false ; }
Removes a single listener from an event .
14,836
public function xml ( $ type = 'dom' ) { $ xml = $ this -> content ; $ type = trim ( strtolower ( $ type ) ) ; switch ( $ type ) { case 'dom' : $ xml = new \ DOMDocument ( ) ; $ xml -> loadXML ( $ this -> content ) ; break ; case 'simple' : $ xml = new \ SimpleXMLElement ( $ this -> content ) ; break ; } return $ xml ; }
Return the xml object of the ressource
14,837
public function content ( $ arg = null ) { switch ( $ this -> format ) { case 'json' : if ( ! isset ( $ arg ) ) { $ arg = false ; } return $ this -> json ( $ arg ) ; break ; case 'xml' : if ( ! isset ( $ arg ) ) { $ arg = 'dom' ; } return $ this -> xml ( $ arg ) ; break ; default : return $ this -> getContent ( ) ; break ; } }
Get the content of the ressource Return a result depending on the type of the resource
14,838
public function isActive ( $ requestUri = null ) { $ uri = rawurldecode ( preg_replace ( '/[\\?#].*$/' , '' , ( string ) $ this -> getUri ( ) ) ) ; if ( empty ( $ uri ) || '/' !== $ uri [ 0 ] ) { return false ; } if ( null === $ requestUri ) { if ( null === $ this -> requestUri ) { $ this -> requestUri = $ this -> getServiceLocator ( ) -> get ( 'Request' ) -> getRequestUri ( ) ; $ this -> requestUri = preg_replace ( '/\\?.*$/' , '' , $ this -> requestUri ) ; } $ requestUri = $ this -> requestUri ; } else { $ requestUri = preg_replace ( '/[\\?#].*$/' , '' , ( string ) $ requestUri ) ; } $ requestUri = rawurldecode ( $ requestUri ) ; return $ requestUri === $ uri || ( mb_strlen ( $ requestUri ) > mb_strlen ( $ uri ) && mb_substr ( $ requestUri , 0 , mb_strlen ( $ uri ) + 1 ) === ( $ uri . '/' ) ) ; }
Is this menu - item is active?
14,839
public function retrieveToken ( $ key ) { $ location = $ this -> _createFileName ( $ key ) ; if ( file_exists ( $ location ) ) { return file_get_contents ( $ location ) ; } return null ; }
Retrieve a token from storage
14,840
public function getDescriptor ( ) { if ( null == $ this -> descriptor ) { $ this -> setDescriptor ( EntityDescriptorRegistry :: getInstance ( ) -> getDescriptorFor ( $ this -> getEntityClassName ( ) ) ) ; } return $ this -> descriptor ; }
Get entity descriptor
14,841
public function getEntityClassName ( ) { if ( null == $ this -> entityClassName ) { $ this -> setEntityClassName ( get_class ( $ this -> entity ) ) ; } return $ this -> entityClassName ; }
Gets entity class name for this mapper
14,842
public static function Tr ( array $ r , array & $ rt ) { $ wm = [ ] ; $ i ; $ j ; for ( $ i = 0 ; $ i < 3 ; $ i ++ ) { for ( $ j = 0 ; $ j < 3 ; $ j ++ ) { $ wm [ $ i ] [ $ j ] = $ r [ $ j ] [ $ i ] ; } } IAU :: Cr ( $ wm , $ rt ) ; return ; }
- - - - - - i a u T r - - - - - -
14,843
public function merge ( ) { $ marged = NULL ; foreach ( func_get_args ( ) as $ arg ) { if ( $ marged === null ) { $ marged = $ arg ; } elseif ( gettype ( $ marged ) !== gettype ( $ arg ) ) { $ marged = $ arg ; } elseif ( ! is_array ( $ arg ) ) { $ marged = $ arg ; } else { foreach ( $ arg as $ _key => $ _val ) { if ( is_int ( $ _key ) ) { $ marged [ ] = $ _val ; } elseif ( ! isset ( $ marged [ $ _key ] ) ) { $ marged [ $ _key ] = $ _val ; } else { $ marged [ $ _key ] = $ this -> merge ( $ marged [ $ _key ] , $ _val ) ; } } } } return $ marged ; }
merge recursive .
14,844
protected function createClass ( ) { $ file = $ this -> getPath ( ) ; if ( $ this -> files -> exists ( $ file ) ) { throw new PresenterExistsException ( ) ; } else { return $ this -> files -> put ( $ file , $ this -> stub -> populateStub ( $ this -> getPopulatedData ( ) ) ) ; } }
Create the Presenter file
14,845
protected function createDirectory ( ) { $ dir = $ this -> getDirectory ( ) ; if ( ! $ this -> files -> isDirectory ( $ dir ) ) { $ this -> files -> makeDirectory ( $ dir , 0755 , true ) ; } return $ this ; }
Create the directory that will be used to receive the Presenters
14,846
public function setAction ( $ action ) { if ( $ action instanceof \ Closure ) { $ this -> action = $ action ; return $ this ; } $ parts = explode ( '::' , $ action ) ; if ( count ( $ parts ) != 2 ) { throw new \ LengthException ( 'Malformed action string' ) ; } $ this -> validateRoutable ( $ parts [ 0 ] , $ parts [ 1 ] ) ; $ this -> action = $ parts ; return $ this ; }
Sets the action
14,847
public function acceptedVerb ( $ verb ) { if ( isset ( $ this -> verbs [ 0 ] ) && $ this -> verbs [ 0 ] == static :: ANY_METHOD_WILDCARD ) { return true ; } return in_array ( strtoupper ( $ verb ) , $ this -> getVerbs ( ) , true ) ; }
Asserts if http verb is accepted
14,848
public function getActionAsClosure ( ) { if ( $ this -> action instanceof \ Closure ) { return $ this -> action ; } return function ( ) { $ action = $ this -> getActionAsCallable ( ) ; return call_user_func_array ( $ action , func_get_args ( ) ) ; } ; }
Forces the action to be returns Closure
14,849
public function match ( $ uri ) { if ( preg_match ( $ this -> getParsedPattern ( ) , trim ( $ uri ) , $ matches ) > 0 ) { $ this -> parameters = array_slice ( $ matches , 1 ) ; return true ; } return false ; }
Determines if uri matches with regex . If match return params of uri
14,850
public function toUri ( array $ parameters = [ ] ) { $ pattern = $ this -> getPattern ( ) ; $ wildcardsRegexes = $ this -> wildcardsToRegexGroups ( $ matches = $ this -> getPatternWildcards ( ) ) ; $ parameters = array_slice ( $ parameters , 0 , count ( $ wildcardsRegexes ) ) ; $ this -> validateParametersByWildcards ( $ matches , $ parameters ) ; $ uri = preg_replace ( $ wildcardsRegexes , $ parameters , $ pattern , 1 ) ; return '/' . rtrim ( $ uri , '/' ) ; }
Generates the uri from current route
14,851
protected function getPatternWildcards ( ) { preg_match_all ( $ this -> wildcardsToRegex ( ) , $ this -> getPattern ( ) , $ matches ) ; return empty ( $ matches [ 0 ] ) ? [ ] : $ matches [ 0 ] ; }
Gets the wildcards of route pattern
14,852
public function getAllKeyValues ( ) { $ query = $ this -> _table -> query ( ) ; $ query -> formatResults ( function ( ResultSet $ results ) { return $ results -> map ( function ( $ row ) { if ( $ row [ 'serialized' ] === true ) { $ row [ 'value' ] = unserialize ( $ row [ 'value' ] ) ; } return $ row ; } ) ; } ) ; $ settings = [ ] ; foreach ( $ query -> all ( ) as $ row ) { $ key = $ row [ 'scope' ] . '__' . $ row [ $ this -> config ( 'fields.key' ) ] ; $ value = $ row [ $ this -> config ( 'fields.value' ) ] ; $ settings [ $ key ] = $ value ; } return Hash :: expand ( $ settings , '__' ) ; }
Returns all keys and their values for all scopes .
14,853
public function getKeyValues ( Entity $ entity , array $ keys ) { $ scope = $ this -> config ( 'scope' ) ; $ query = $ this -> _table -> query ( ) ; $ query -> where ( [ 'scope' => $ scope , $ this -> config ( 'fields.key' ) . ' IN' => $ keys ] ) -> hydrate ( false ) ; $ query -> formatResults ( function ( ResultSet $ results ) { return $ results -> map ( function ( $ row ) { if ( $ row [ 'serialized' ] === true ) { $ row [ 'value' ] = unserialize ( $ row [ 'value' ] ) ; } return $ row ; } ) ; } ) ; foreach ( $ query -> all ( ) as $ row ) { $ entity -> { $ row [ $ this -> config ( 'fields.key' ) ] } = $ row [ $ this -> config ( 'fields.value' ) ] ; } return $ entity ; }
Generate a custom entity with all keys as properties and their corresponding values
14,854
public function saveKeyValues ( Entity $ entity , array $ keys ) { $ event = $ this -> _table -> dispatchEvent ( 'Model.beforeSaveKeyValues' , compact ( 'entity' ) ) ; if ( $ event -> isStopped ( ) ) { return $ event -> result ; } if ( ! empty ( $ event -> result ) ) { $ entity = $ event -> result ; } $ fields = $ this -> config ( 'fields' ) ; if ( $ entity -> has ( $ fields [ 'key' ] ) && $ entity -> has ( $ fields [ 'value' ] ) ) { return true ; } $ mappedIds = $ this -> _getFieldToIdMapping ( $ keys ) ; $ entities = [ ] ; foreach ( $ entity -> toArray ( ) as $ key => $ value ) { if ( $ this -> _table -> hasField ( $ key ) ) { continue ; } $ serialized = false ; if ( in_array ( $ key , $ this -> config ( 'serializeFields' ) ) ) { $ value = serialize ( $ value ) ; $ serialized = true ; } $ kvEntity = $ this -> _table -> newEntity ( [ 'scope' => $ this -> config ( 'scope' ) , $ this -> config ( 'fields.key' ) => $ key , $ this -> config ( 'fields.value' ) => $ value , 'serialized' => $ serialized ] ) ; if ( ( $ existingId = Hash :: get ( $ mappedIds , $ key ) ) !== null ) { $ kvEntity -> id = $ existingId ; } $ entities [ ] = $ kvEntity ; } $ result = $ this -> _table -> connection ( ) -> transactional ( function ( ) use ( $ entities ) { foreach ( $ entities as $ e ) { $ this -> _table -> save ( $ e ) ; } } ) ; return ( $ result !== false ) ; }
Save key value pairs .
14,855
protected function _getFieldToIdMapping ( array $ keys ) { return $ this -> _table -> find ( 'list' , [ 'keyField' => $ this -> config ( 'fields.key' ) , 'valueField' => 'id' ] ) -> where ( [ 'scope' => $ this -> config ( 'scope' ) , $ this -> config ( 'fields.key' ) . ' IN' => $ keys ] ) -> toArray ( ) ; }
Returns an array of existing keys and their corresponding ids
14,856
protected static function loadSchema ( ) { if ( ! array_key_exists ( static :: table ( ) , static :: $ _schema ) ) { static :: $ _schema [ static :: table ( ) ] = null ; } if ( static :: $ _schema [ static :: table ( ) ] === null ) { $ result = static :: connection ( ) -> prepare ( "DESCRIBE `" . static :: table ( ) . "`" ) -> exec ( ) ; foreach ( $ result -> fetchAll ( \ PDO :: FETCH_COLUMN ) as $ column ) { static :: $ _schema [ static :: table ( ) ] [ $ column [ 'Field' ] ] = array ( 'type' => $ column [ 'Type' ] , 'default' => $ column [ 'Default' ] , 'null' => $ column [ 'Null' ] == 'NO' ? false : true , 'key' => $ column [ 'Key' ] , 'extra' => $ column [ 'Extra' ] ) ; } } }
Used to fetch the tables schema .
14,857
public static function find ( $ find , $ value = null ) { if ( $ value === null ) { $ value = $ find ; $ find = static :: $ _primaryKey ; } return static :: select ( ) -> where ( "{$find} = ?" , $ value ) -> fetch ( ) ; }
Returns the first found row .
14,858
public function data ( ) { $ data = array ( ) ; foreach ( array_keys ( static :: schema ( ) ) as $ column ) { if ( isset ( $ this -> { $ column } ) ) { $ data [ $ column ] = $ this -> { $ column } ; } } return $ data ; }
Gets the models data .
14,859
public function save ( ) { if ( ! $ this -> validates ( ) ) { return false ; } $ this -> runFilters ( 'before' , $ this -> _isNew ? 'create' : 'save' ) ; $ data = static :: data ( ) ; if ( $ this -> _isNew ) { $ result = static :: connection ( ) -> insert ( $ data ) -> into ( static :: table ( ) ) -> exec ( ) ; $ this -> id = static :: connection ( ) -> lastInsertId ( ) ; } else { $ result = static :: connection ( ) -> update ( static :: table ( ) ) -> set ( $ data ) -> where ( static :: $ _primaryKey . ' = ?' , $ data [ static :: $ _primaryKey ] ) -> exec ( ) ; } $ this -> runFilters ( 'after' , $ this -> _isNew ? 'create' : 'save' ) ; return $ result ; }
Saves the model to the database .
14,860
public function delete ( ) { $ result = static :: connection ( ) -> delete ( ) -> from ( static :: table ( ) ) -> where ( static :: $ _primaryKey . " = ?" , $ this -> { static :: $ _primaryKey } ) -> limit ( 1 ) -> exec ( ) ; if ( $ result ) { $ this -> runFilters ( 'after' , 'delete' ) ; } return $ result ; }
Deletes the row from the database .
14,861
public function __toArray ( ) { $ data = array ( ) ; foreach ( static :: schema ( ) as $ field => $ options ) { $ data [ $ field ] = $ this -> { $ field } ; } return $ data ; }
Returns the models properties in a key = > value array .
14,862
function it_matches_identifiers ( ) { $ this -> match ( '123' ) -> shouldReturn ( '123' ) ; $ this -> match ( '3.14' ) -> shouldReturn ( '3.14' ) ; $ this -> match ( '-123' ) -> shouldReturn ( '-123' ) ; }
It matches identifiers .
14,863
public static function Gst06a ( $ uta , $ utb , $ tta , $ ttb ) { $ rnpb = [ ] ; $ gst ; IAU :: Pnm06a ( $ tta , $ ttb , $ rnpb ) ; $ gst = IAU :: Gst06 ( $ uta , $ utb , $ tta , $ ttb , $ rnpb ) ; return $ gst ; }
- - - - - - - - - - i a u G s t 0 6 a - - - - - - - - - -
14,864
public function setExcludes ( array $ excludes ) : self { $ this -> excludes = \ array_map ( function ( $ value ) { return \ trim ( $ value , '/' ) ; } , $ excludes ) ; return $ this ; }
Exclude paths from finder .
14,865
public function setComposerAutoload ( string $ packageName , array $ autoload ) : self { $ this -> reset ( ) ; if ( isset ( $ autoload [ 'psr-0' ] ) ) { $ this -> addPsr0 ( $ packageName , ( array ) $ autoload [ 'psr-0' ] ) ; } if ( isset ( $ autoload [ 'psr-4' ] ) ) { $ this -> addPsr4 ( $ packageName , ( array ) $ autoload [ 'psr-4' ] ) ; } if ( isset ( $ autoload [ 'classmap' ] ) ) { $ this -> addClassmap ( $ packageName , ( array ) $ autoload [ 'classmap' ] ) ; } if ( isset ( $ autoload [ 'exclude-from-classmap' ] ) ) { $ this -> setExcludes ( ( array ) $ autoload [ 'exclude-from-classmap' ] ) ; } return $ this ; }
Set the composer . json file autoload key values .
14,866
public function addPsr0 ( string $ packageName , array $ paths ) : self { $ this -> paths [ 'psr0' ] [ $ packageName ] = $ paths ; return $ this ; }
Add composer psr0 paths .
14,867
public function addPsr4 ( string $ packageName , array $ paths ) : self { $ this -> paths [ 'psr4' ] [ $ packageName ] = $ paths ; return $ this ; }
Add composer psr4 paths .
14,868
public function addClassmap ( string $ packageName , array $ paths ) : self { $ this -> paths [ 'classmap' ] [ $ packageName ] = $ paths ; return $ this ; }
Add composer classmap paths .
14,869
public function find ( ) : self { $ preparedPaths = \ array_unique ( \ array_merge ( $ this -> getPreparedPaths ( ( array ) $ this -> paths [ 'psr0' ] ) , $ this -> getPreparedPaths ( ( array ) $ this -> paths [ 'psr4' ] ) , $ this -> getPreparedPaths ( ( array ) $ this -> paths [ 'classmap' ] ) ) , \ SORT_STRING ) ; $ finder = Finder :: create ( ) -> files ( ) -> in ( $ preparedPaths ) -> exclude ( $ this -> excludes ) -> name ( '*.php' ) -> sortByName ( ) ; if ( $ this -> filter !== null ) { $ finder -> filter ( $ this -> filter ) ; } foreach ( $ finder as $ file ) { $ realPath = ( string ) $ file -> getRealPath ( ) ; $ namespace = null ; $ tokens = \ token_get_all ( ( string ) \ file_get_contents ( $ realPath ) ) ; foreach ( $ tokens as $ key => $ token ) { if ( \ is_array ( $ token ) ) { if ( $ token [ 0 ] === \ T_NAMESPACE ) { $ namespace = self :: getNamespace ( $ key + 2 , $ tokens ) ; } elseif ( $ token [ 0 ] === \ T_INTERFACE ) { $ name = self :: getName ( $ key + 2 , $ tokens ) ; if ( $ name === null ) { continue 2 ; } $ this -> interfaces [ \ ltrim ( $ namespace . '\\' . $ name , '\\' ) ] = $ realPath ; } elseif ( $ token [ 0 ] === \ T_TRAIT ) { $ name = self :: getName ( $ key + 2 , $ tokens ) ; if ( $ name === null ) { continue 2 ; } $ this -> traits [ \ ltrim ( $ namespace . '\\' . $ name , '\\' ) ] = $ realPath ; } elseif ( $ token [ 0 ] === \ T_ABSTRACT ) { $ name = self :: getName ( $ key + 4 , $ tokens ) ; if ( $ name === null ) { continue 2 ; } $ this -> abstractClasses [ \ ltrim ( $ namespace . '\\' . $ name , '\\' ) ] = $ realPath ; continue 2 ; } elseif ( $ token [ 0 ] === \ T_CLASS ) { $ name = self :: getName ( $ key + 2 , $ tokens ) ; if ( $ name === null ) { continue 2 ; } $ this -> classes [ \ ltrim ( $ namespace . '\\' . $ name , '\\' ) ] = $ realPath ; } } } unset ( $ tokens ) ; \ gc_mem_caches ( ) ; } return $ this ; }
Find all the class traits and interface names in a given directory .
14,870
public function getAll ( ) : array { return \ array_merge ( $ this -> interfaces , $ this -> traits , $ this -> abstractClasses , $ this -> classes ) ; }
Returns a array of all found classes interface and traits .
14,871
private static function getName ( $ key , array $ tokens ) : ? string { $ class = null ; $ tokenCount = \ count ( $ tokens ) ; for ( $ i = $ key ; $ i < $ tokenCount ; $ i ++ ) { if ( \ is_array ( $ tokens [ $ i ] ) ) { if ( $ tokens [ $ i ] [ 0 ] === \ T_STRING ) { $ class .= $ tokens [ $ i ] [ 1 ] ; } elseif ( $ tokens [ $ i ] [ 0 ] === \ T_WHITESPACE ) { return $ class ; } } } return null ; }
Find the name in the tokens starting at a given key .
14,872
private function getPreparedPaths ( array $ paths ) : array { $ fullPaths = [ ] ; foreach ( $ paths as $ name => $ path ) { if ( \ is_array ( $ path ) ) { foreach ( $ path as $ p ) { $ fullPaths [ ] = \ rtrim ( $ this -> vendorDir . \ DIRECTORY_SEPARATOR . $ name . \ DIRECTORY_SEPARATOR . $ p , '/' ) ; } } else { $ fullPaths [ ] = \ rtrim ( $ this -> vendorDir . \ DIRECTORY_SEPARATOR . $ name . \ DIRECTORY_SEPARATOR . $ path , '/' ) ; } } return $ fullPaths ; }
Prepare psr0 and psr4 to full vendor package paths .
14,873
public function infoAction ( Request $ request ) { $ securityContext = $ this -> get ( 'security.context' ) ; $ lines = [ ] ; if ( $ securityContext -> isGranted ( 'ROLE_SUPER_ADMIN' ) ) { $ lines [ ] = [ 'Project:' , $ this -> container -> getParameter ( 'phlexible_gui.project.title' ) . ' ' . $ this -> container -> getParameter ( 'phlexible_gui.project.version' ) , ] ; $ lines [ ] = [ 'Env:' , $ this -> container -> getParameter ( 'kernel.environment' ) . ( $ this -> container -> getParameter ( 'kernel.debug' ) ? ' [DEBUG]' : '' ) , ] ; $ lines [ ] = [ 'Host:' , $ request -> server -> get ( 'SERVER_NAME' ) . ' [' . PHP_SAPI . ']' ] ; $ connection = $ this -> getDoctrine ( ) -> getConnection ( ) ; $ lines [ ] = [ 'Default Database:' , $ connection -> getHost ( ) . ' / ' . $ connection -> getDatabase ( ) . ' [' . $ connection -> getDriver ( ) -> getName ( ) . ']' , ] ; $ lines [ ] = [ 'Session:' , $ request -> getSession ( ) -> getId ( ) . ' [' . $ request -> server -> get ( 'REMOTE_ADDR' ) . ']' ] ; $ lines [ ] = [ 'User:' , $ this -> getUser ( ) -> getUsername ( ) . ' [' . implode ( ', ' , $ this -> getUser ( ) -> getRoles ( ) ) . ']' , ] ; $ lines [ ] = [ 'UserAgent:' , $ request -> server -> get ( 'HTTP_USER_AGENT' ) ] ; } else { $ lines [ ] = [ 'Project:' , $ this -> container -> getParameter ( 'phlexible_gui.project.title' ) . ' ' . $ this -> container -> getParameter ( 'phlexible_gui.project.version' ) , ] ; } $ l1 = 0 ; $ l2 = 0 ; foreach ( $ lines as $ line ) { if ( strlen ( $ line [ 0 ] ) > $ l1 ) { $ l1 = strlen ( $ line [ 0 ] ) ; } if ( isset ( $ line [ 1 ] ) && strlen ( $ line [ 1 ] ) > $ l2 ) { $ l2 = strlen ( $ line [ 1 ] ) ; } } $ table = '' ; foreach ( $ lines as $ line ) { $ table .= str_pad ( $ line [ 0 ] , $ l1 + 2 ) ; $ table .= str_pad ( $ line [ 1 ] , $ l2 + 2 ) ; if ( isset ( $ line [ 2 ] ) ) { $ table .= $ line [ 2 ] ; } $ table .= PHP_EOL ; } $ out = '<pre>' . $ table . '</pre>' ; return new Response ( $ out ) ; }
Return info .
14,874
public function setOffset ( $ offset , $ parseHints = Parser :: HINT_NONE ) { $ this -> offset = $ offset ; $ this -> parseHints = $ parseHints ; }
Sets a offset
14,875
private function iterateKeyReader ( ) { $ results = $ this -> index -> getKeyReader ( ) -> readKeys ( $ this -> offset , $ this -> direction , $ this -> parseHints ) ; if ( empty ( $ results ) ) { return $ results ; } if ( $ this -> direction == KeyReader :: DIRECTION_BACKWARD ) { $ revertBackwardResults = array ( ) ; foreach ( $ results as $ result ) { if ( $ result -> getOffset ( ) > $ this -> offset ) { break ; } array_unshift ( $ revertBackwardResults , $ result ) ; } $ results = $ revertBackwardResults ; } $ end = end ( $ results ) ; switch ( $ this -> direction ) { case KeyReader :: DIRECTION_FORWARD : $ this -> setOffset ( $ end -> getOffset ( ) + strlen ( $ end -> getData ( ) ) ) ; break ; case KeyReader :: DIRECTION_BACKWARD : $ this -> setOffset ( $ end -> getOffset ( ) - 1 ) ; break ; default : throw new \ LogicException ( "invalid direction" ) ; } $ this -> avoidBackwardDuplicates ( $ results ) ; reset ( $ results ) ; return $ results ; }
Iterates in the index and shifts the offset
14,876
private function avoidBackwardDuplicates ( array & $ results ) { if ( $ this -> direction == KeyReader :: DIRECTION_FORWARD || $ this -> offset >= 0 ) { return ; } $ lastResults = $ this -> iterator -> getArrayCopy ( ) ; if ( empty ( $ lastResults ) ) { return ; } $ lastMinimum = end ( $ lastResults ) -> getKey ( ) ; $ reducedResults = array ( ) ; foreach ( $ results as $ result ) { if ( $ result -> getKey ( ) >= $ lastMinimum ) { continue ; } $ reducedResults [ ] = $ result ; } $ results = $ reducedResults ; }
Removes results which were found in the previous iteration .
14,877
private function prepareSelectValues ( array $ values ) : array { $ options = [ ] ; foreach ( $ values as $ key => $ value ) { $ options [ ] = [ 'id' => $ key , 'caption' => $ value , ] ; } return $ options ; }
Prepares values to use in filter
14,878
public function getDefaultSource ( ) { $ source = i18n :: getData ( ) -> getCountries ( ) ; $ invalid = $ this -> config ( ) -> invalid_countries ; return array_filter ( $ source , function ( $ code ) use ( $ invalid ) { return ! in_array ( $ code , $ invalid ) ; } , ARRAY_FILTER_USE_KEY ) ; }
Answers the default source options for the receiver .
14,879
public static function create ( $ year = null , $ month = null , $ day = null , $ hour = null , $ min = null , $ second = null ) { return Carbon :: create ( $ year , $ month , $ day , $ hour , $ min , $ second ) ; }
create new date .
14,880
protected function getResult ( $ data ) { if ( is_array ( $ data ) ) { header ( 'content-type: application/json' ) ; return $ this -> cypher -> encode ( json_encode ( $ data ) ) ; } return $ data ; }
Encoding and cypher result
14,881
protected function getRequestDataByMethod ( $ method = HttpMethods :: GET ) { switch ( $ method ) { case HttpMethods :: POST : $ postData = array_merge ( $ _GET , $ _POST ) ; return $ postData ? : [ ] ; break ; case HttpMethods :: PUT : case HttpMethods :: PATCH : $ data = $ this -> cypher -> decode ( file_get_contents ( 'php://input' ) ) ; parse_str ( $ data , $ patchData ) ; $ patchData = array_merge ( $ _GET , $ patchData ) ; return $ patchData ? : [ ] ; break ; case HttpMethods :: DELETE : case HttpMethods :: HEAD : case HttpMethods :: OPTIONS : return [ ] ; break ; case HttpMethods :: GET : default : return $ _GET ; break ; } }
Returns the incoming array of parameters based on the type of the request
14,882
protected function getActionArguments ( $ class , $ action ) { $ method = new \ ReflectionMethod ( $ class , $ action ) ; $ this -> action = $ method ; $ parameters = $ method -> getParameters ( ) ; $ result = [ ] ; foreach ( $ parameters as $ parameter ) { $ attribute = new ActionAttribute ( ) ; $ attribute -> name = $ parameter -> getName ( ) ; $ attribute -> isRequired = ! $ parameter -> isDefaultValueAvailable ( ) ; if ( ! $ attribute -> isRequired ) { $ attribute -> defaultValue = $ parameter -> getDefaultValue ( ) ; } $ result [ ] = $ attribute ; } return $ result ; }
It goes through the parameters of the method and checks for the default value and requirement
14,883
protected function callAction ( ControllerInterface $ class , $ action , $ arguments , array $ data ) { if ( null !== $ this -> action || $ this -> action -> getName ( ) !== $ this -> action ) { $ this -> action = new \ ReflectionMethod ( $ class , $ action ) ; } $ params = [ ] ; $ dataBox = new Param ( $ data ) ; foreach ( $ arguments as $ argument ) { $ params [ $ argument -> name ] = $ dataBox -> get ( $ argument -> name , $ argument -> defaultValue ) ; } return $ this -> action -> invokeArgs ( $ class , $ params ) ; }
Calling action with request data in params
14,884
protected function getAllowedMethodsForRoute ( ControllerInterface $ class , $ action ) { $ actionsInfo = $ class -> getMethods ( ) ; if ( isset ( $ actionsInfo [ $ action ] ) ) { $ methods = implode ( ', ' , $ actionsInfo [ $ action ] -> getAllowedMethods ( ) ) ; $ methodInfo = ReflectionHelper :: getMethodInfo ( $ class , $ action ) ; header ( 'Access-Control-Allow-Origin : *' ) ; header ( 'Access-Control-Allow-Methods : ' . $ methods ) ; header ( 'Access-Control-Allow-Headers : *' ) ; return $ methodInfo ; } return [ ] ; }
Return action description and set headers to output
14,885
public static function typed ( string $ type , iterable $ input = [ ] ) : Queue { $ resolver = Resolver :: typed ( $ type ) ; return new static ( $ input , $ resolver ) ; }
Queue named constructor .
14,886
public function getData ( $ segments ) { $ data = new stdClass ; $ data -> errors = array ( ) ; $ data -> email = BRequest :: getString ( 'email' ) ; $ data -> name = BRequest :: getString ( 'name' ) ; $ data -> password = BRequest :: getString ( 'password' ) ; $ data -> result = false ; $ data -> do = BRequest :: getString ( 'do' ) ; if ( $ data -> do == 'register' ) { if ( empty ( $ data -> name ) ) { $ data -> errors [ 'name' ] = 'Could not' ; return $ data ; } if ( strlen ( $ data -> password ) < 6 ) { $ data -> errors [ 'password' ] = 'Password length < 6 chars' ; return $ data ; } $ user = new BUser ( ) ; $ user -> name = $ data -> name ; $ user -> email = $ data -> email ; $ user -> setpassword ( $ data -> password ) ; $ r = $ user -> saveToDB ( ) ; if ( ! empty ( $ r ) ) { $ data -> errors = $ r ; } if ( $ r === true ) { $ data -> result = true ; $ data -> errors = array ( ) ; } } return $ data ; }
Get Data and try to registar user if need .
14,887
public function callback_dismiss_notification ( ) { if ( isset ( $ _POST [ 'namespace' ] ) || isset ( $ _POST [ 'id' ] ) ) { $ namespace = $ _POST [ 'namespace' ] ; $ id = $ _POST [ 'id' ] ; $ n_class = get_class ( ) ; $ notify = new $ n_class ( $ namespace ) ; $ notify -> hide_notification ( $ id ) ; } exit ; }
Callback to handle dismiss button AJAX request
14,888
private function load_notices ( ) { $ notices = get_option ( 'wp_easy_notify_' . $ this -> prefix , array ( ) ) ; $ this -> notices = $ notices ; $ active = get_option ( 'wp_easy_notify_active_' . $ this -> prefix , array ( ) ) ; $ this -> active = $ active ; }
Load all notices into the class .
14,889
public function display_notices ( ) { foreach ( $ this -> active as $ id => $ count ) { if ( is_callable ( $ this -> notices [ $ id ] [ 'cond_func' ] ) ) { $ cond = call_user_func ( $ this -> notices [ $ id ] [ 'cond_func' ] ) ; } else { $ cond = true ; } if ( $ cond ) { $ this -> print_notification ( $ this -> notices [ $ id ] ) ; } if ( $ count === 1 ) { unset ( $ this -> active [ $ id ] ) ; } if ( $ count > 1 ) { $ this -> active [ $ id ] = $ count - 1 ; } } $ this -> save ( ) ; }
Display the notices .
14,890
private function print_notification ( $ notice ) { do_action ( 'easy_notifications_before_notice' , $ notice ) ; echo '<div class="updated ' . $ notice [ 'type' ] . '"> ' . $ notice [ 'content' ] . ' <a href="#" class="dismiss-notice" data-namespace="' . $ this -> prefix . '" data-noticeid="' . $ notice [ 'id' ] . '" >Dismiss Notification</a> </div>' ; do_action ( 'easy_notifications_after_notice' , $ notice ) ; }
Print a notification to the current Page .
14,891
private function save ( ) { update_option ( 'wp_easy_notify_' . $ this -> prefix , $ this -> notices ) ; update_option ( 'wp_easy_notify_active_' . $ this -> prefix , $ this -> active ) ; }
Save the class data to Database .
14,892
public function add_notification ( $ id , $ content , $ type = null , $ hide_button = null , $ cond_func = null ) { if ( isset ( $ this -> notices [ $ id ] ) ) { return false ; } if ( ! $ type ) { $ type = 'success' ; } if ( ! $ hide_button ) { $ hide_button = true ; } if ( ! $ cond_func ) { $ cond_func = false ; } $ this -> notices [ $ id ] = array ( 'id' => $ id , 'content' => $ content , 'type' => $ type , 'hide_button' => $ hide_button , 'cond_func' => $ cond_func , ) ; $ this -> save ( ) ; }
Add a notification to the notices namespace .
14,893
public function update_notification ( $ id , $ content = null , $ type = null , $ hide_button = null , $ cond_func = null ) { if ( ! isset ( $ this -> notices [ $ id ] ) ) { $ this -> add_notification ( $ id , $ content , $ type , $ hide_button , $ cond_func ) ; } if ( $ content ) { $ this -> notices [ $ id ] [ 'content' ] = $ content ; } if ( $ type ) { $ this -> notices [ $ id ] [ 'type' ] = $ type ; } if ( $ hide_button ) { $ this -> notices [ $ id ] [ 'hide_button' ] = $ hide_button ; } if ( $ cond_func ) { $ this -> notices [ $ id ] [ 'cond_func' ] = $ cond_func ; } $ this -> save ( ) ; }
Update a notification configuration .
14,894
public function send ( ) { $ args = func_get_args ( ) ; if ( count ( $ args ) > 1 ) { $ message = call_user_func_array ( 'sprintf' , $ args ) ; } else { $ message = $ args [ 0 ] ; } $ this -> response -> send ( $ message ) ; }
implements for task output .
14,895
public function isUsage ( ) { $ options = array ( 'help' , 'usage' , 'option.h' ) ; foreach ( $ options as $ option ) { if ( $ this -> request -> get ( $ option ) ) return true ; } return false ; }
is usage ?
14,896
protected function setLanguage ( ) { $ matches = array ( ) ; if ( $ this -> owner -> user -> hasState ( '__locale' ) ) $ language = $ this -> owner -> user -> getState ( '__locale' ) ; else if ( preg_match ( '/^\/([a-z]{2}(?:_[a-z]{2})?)\//i' , substr ( $ this -> owner -> request -> url , strlen ( $ this -> owner -> baseUrl ) ) , $ matches ) !== false && isset ( $ matches [ 1 ] , $ this -> languages [ $ matches [ 1 ] ] ) ) $ language = $ matches [ 1 ] ; else $ language = $ this -> defaultLanguage ; $ this -> owner -> language = $ language ; }
Sets the application language from a user state if applicable .
14,897
public function getComponentName ( ) { $ component = $ this -> argument ( 'component' ) ? : app ( 'components' ) -> getUsedNow ( ) ; $ component = app ( 'components' ) -> findOrFail ( $ component ) ; return $ component -> getStudlyName ( ) ; }
Get the component name .
14,898
protected static function registerDump ( $ representation , $ backtrace ) { $ dump = new Dump ( $ representation , $ backtrace [ 0 ] [ 'file' ] , $ backtrace [ 0 ] [ 'line' ] ) ; static :: $ instances [ ] = $ dump ; return $ dump ; }
Registers a dump .
14,899
public function get ( string $ option ) { if ( ! isset ( $ this -> options [ $ option ] ) ) { throw new \ InvalidArgumentException ( sprintf ( 'Option "%s" does not exists.' , $ option ) ) ; } return $ this -> options [ $ option ] ; }
Returns options value by its name