idx
int64
0
60.3k
question
stringlengths
92
4.62k
target
stringlengths
7
635
58,000
protected function _fields ( $ fields , $ context ) { $ alias = $ context -> alias ( ) ; $ models = $ context -> models ( $ this ) ; $ list = [ ] ; foreach ( $ fields as $ key => $ field ) { if ( ! is_string ( $ field ) ) { if ( isset ( $ models [ $ key ] ) ) { $ field = array_fill_keys ( $ field , true ) ; $ list [ $ ...
Reformats fields to be alias based .
58,001
protected function _fieldsQuote ( $ alias , $ field ) { list ( $ open , $ close ) = $ this -> _quotes ; $ aliasing = preg_split ( "/\s+as\s+/i" , $ field ) ; if ( isset ( $ aliasing [ 1 ] ) ) { list ( $ aliasname , $ fieldname ) = $ this -> _splitFieldname ( $ aliasing [ 0 ] ) ; $ alias = $ aliasname ? : $ alias ; retu...
Quotes fields also handles aliased fields .
58,002
protected function _fieldsReturn ( $ type , $ context , $ fields , $ schema ) { if ( $ type === 'create' || $ type === 'update' ) { $ data = $ context -> data ( ) ; if ( isset ( $ data [ 'data' ] ) && is_array ( $ data [ 'data' ] ) && count ( $ data ) === 1 ) { $ data = $ data [ 'data' ] ; } if ( $ fields && is_array (...
Renders the fields SQL fragment for queries .
58,003
protected function _createFields ( $ data , $ schema , $ context ) { $ fields = [ ] ; $ values = [ ] ; foreach ( $ data as $ field => $ value ) { $ fields [ ] = $ this -> name ( $ field ) ; $ values [ ] = $ this -> value ( $ value , isset ( $ schema [ $ field ] ) ? $ schema [ $ field ] : [ ] ) ; } return [ 'fields' => ...
Renders the fields part for _create_ queries .
58,004
protected function _updateFields ( $ data , $ schema , $ context ) { $ fields = [ ] ; $ increment = [ ] ; if ( $ entity = $ context -> entity ( ) ) { $ export = $ entity -> export ( ) ; $ increment = $ export [ 'increment' ] ; array_map ( function ( $ key ) use ( & $ data , $ export ) { if ( ! empty ( $ data [ $ key ] ...
Renders the fields part for _update_ queries .
58,005
public function joins ( array $ joins , $ context ) { $ result = null ; foreach ( $ joins as $ key => $ join ) { if ( $ result ) { $ result .= ' ' ; } $ join = is_array ( $ join ) ? $ this -> _instance ( 'query' , $ join ) : $ join ; $ options [ 'keys' ] = [ 'mode' , 'source' , 'alias' , 'constraints' ] ; $ result .= $...
Returns a join statement for given array of query objects
58,006
public function constraints ( $ constraints , $ context , array $ options = [ ] ) { $ defaults = [ 'prepend' => 'ON' ] ; $ options += $ defaults ; if ( is_array ( $ constraints ) ) { $ constraints = $ this -> _constraints ( $ constraints ) ; } return $ this -> _conditions ( $ constraints , $ context , $ options ) ; }
Returns a string of formatted constraints to be inserted into the query statement .
58,007
protected function _constraints ( array $ constraints ) { foreach ( $ constraints as & $ value ) { if ( is_string ( $ value ) ) { $ value = ( object ) $ this -> name ( $ value ) ; } elseif ( is_array ( $ value ) ) { $ value = $ this -> _constraints ( $ value ) ; } } return $ constraints ; }
Auto escape string value to a field name value
58,008
public function order ( $ order , $ context ) { if ( ! $ order ) { return null ; } $ model = $ context -> model ( ) ; $ alias = $ context -> alias ( ) ; $ normalized = [ ] ; if ( is_string ( $ order ) ) { if ( preg_match ( '/^(.*?)\s+((?:A|DE)SC)$/i' , $ order , $ match ) ) { $ normalized [ $ match [ 1 ] ] = strtoupper...
Return formatted clause for ORDER BY with known fields escaped and directions normalized to uppercase . When order direction is missing or unrecognized defaults to ASC .
58,009
public function group ( $ group , $ context ) { if ( ! $ group ) { return null ; } $ self = $ this ; $ model = $ context -> model ( ) ; $ alias = $ context -> alias ( ) ; $ escaped = array_map ( function ( $ field ) use ( $ self , $ model , $ alias ) { if ( ! $ model || ! $ model :: schema ( $ field ) ) { return $ self...
Return formatted clause for GROUP BY with known fields escaped .
58,010
protected function _operator ( $ key , $ value , array $ schema = [ ] , array $ options = [ ] ) { $ defaults = [ 'boolean' => 'AND' ] ; $ options += $ defaults ; $ op = strtoupper ( key ( $ value ) ) ; $ value = current ( $ value ) ; $ config = $ this -> _operators [ $ op ] ; $ key = $ this -> name ( $ key ) ; $ values...
Handles conversion of SQL operator keys to SQL statements .
58,011
protected function _toBoolean ( $ value ) { if ( is_bool ( $ value ) ) { return $ value ; } if ( is_int ( $ value ) || is_float ( $ value ) ) { return ( $ value !== 0 ) ; } if ( is_string ( $ value ) ) { return ( $ value === 't' || $ value === 'T' || $ value === 'true' ) ; } return ( boolean ) $ value ; }
Casts a value which is being written or compared to a boolean - type database column .
58,012
protected function _error ( $ sql ) { $ params = compact ( 'sql' ) ; return Filters :: run ( $ this , __FUNCTION__ , $ params , function ( $ params ) { list ( $ code , $ error ) = $ this -> error ( ) ; throw new QueryException ( "{$params['sql']}: {$error}" , $ code ) ; } ) ; }
Throw a QueryException error
58,013
public function applyStrategy ( $ options , $ context ) { if ( $ context -> type ( ) !== 'read' ) { return ; } $ options += [ 'strategy' => 'joined' ] ; if ( ! $ model = $ context -> model ( ) ) { throw new ConfigException ( 'The `\'with\'` option need a valid `\'model\'` option.' ) ; } $ strategy = $ options [ 'strate...
Applying a strategy to a lithium \ data \ model \ Query object
58,014
public function join ( $ context , $ rel , $ fromAlias = null , $ toAlias = null , $ constraints = [ ] ) { $ model = $ rel -> to ( ) ; if ( $ fromAlias === null ) { $ fromAlias = $ context -> alias ( ) ; } if ( $ toAlias === null ) { $ toAlias = $ context -> alias ( null , $ rel -> name ( ) ) ; } if ( ! is_object ( $ c...
Set a query s join according a Relationship .
58,015
protected function _aliasing ( $ name , $ alias , $ map = [ ] ) { list ( $ first , $ second ) = $ this -> _splitFieldname ( $ name ) ; if ( ! $ first && preg_match ( '/^[a-z0-9_-]+$/i' , $ second ) ) { return $ alias . "." . $ second ; } elseif ( isset ( $ map [ $ first ] ) ) { return $ map [ $ first ] . "." . $ second...
Helper which add an alias basename to a field name if necessary
58,016
public function on ( $ rel , $ aliasFrom = null , $ aliasTo = null , $ constraints = [ ] ) { $ model = $ rel -> from ( ) ; $ aliasFrom = $ aliasFrom ? : $ model :: meta ( 'name' ) ; $ aliasTo = $ aliasTo ? : $ rel -> name ( ) ; $ keyConstraints = [ ] ; foreach ( $ rel -> key ( ) as $ from => $ to ) { $ keyConstraints [...
Build the ON constraints from a Relationship instance
58,017
public function createSchema ( $ source , $ schema ) { if ( ! $ schema instanceof $ this -> _classes [ 'schema' ] ) { throw new InvalidArgumentException ( "Passed schema is not a valid `{$class}` instance." ) ; } $ columns = [ ] ; $ primary = null ; $ source = $ this -> name ( $ source ) ; foreach ( $ schema -> fields ...
Create a database - native schema
58,018
protected function _buildMetas ( $ type , array $ metas , $ names = null , $ joiner = ' ' ) { $ result = '' ; $ names = $ names ? ( array ) $ names : array_keys ( $ metas ) ; foreach ( $ names as $ name ) { $ value = isset ( $ metas [ $ name ] ) ? $ metas [ $ name ] : null ; if ( $ value && $ meta = $ this -> _meta ( $...
Helper for building columns metas
58,019
protected function _buildConstraints ( array $ constraints , $ schema = null , $ joiner = ' ' , $ primary = false ) { $ result = '' ; foreach ( $ constraints as $ constraint ) { if ( isset ( $ constraint [ 'type' ] ) ) { $ name = $ constraint [ 'type' ] ; if ( $ meta = $ this -> _constraint ( $ name , $ constraint , $ ...
Helper for building columns constraints
58,020
public function column ( $ field ) { if ( ! isset ( $ field [ 'type' ] ) ) { $ field [ 'type' ] = 'string' ; } if ( ! isset ( $ field [ 'name' ] ) ) { throw new InvalidArgumentException ( "Column name not defined." ) ; } if ( ! isset ( $ this -> _columns [ $ field [ 'type' ] ] ) ) { throw new UnexpectedValueException (...
Generate a database - native column schema string
58,021
protected function _init ( ) { $ hosts = [ ] ; foreach ( ( array ) $ this -> _config [ 'host' ] as $ host ) { $ host = HostString :: parse ( $ host ) + [ 'host' => static :: DEFAULT_HOST , 'port' => static :: DEFAULT_PORT ] ; $ hosts [ ] = "{$host['host']}:{$host['port']}" ; } if ( $ this -> _config [ 'login' ] ) { $ t...
Initializer . Adds operator handlers which will later allow to correctly cast any values . Constructs a DSN from configuration .
58,022
public function connect ( ) { $ server = $ this -> _classes [ 'server' ] ; if ( $ this -> server && $ this -> server -> getConnections ( ) && $ this -> connection ) { return $ this -> _isConnected = true ; } $ this -> _isConnected = false ; $ options = [ 'connect' => true , 'connectTimeoutMS' => $ this -> _config [ 'ti...
Connects to the Mongo server . Matches up parameters from the constructor to create a Mongo database connection .
58,023
public function disconnect ( ) { if ( $ this -> server && $ this -> server -> getConnections ( ) ) { $ this -> _isConnected = false ; unset ( $ this -> connection , $ this -> server ) ; } return true ; }
Disconnect from the Mongo server .
58,024
public function sources ( $ class = null ) { $ this -> _checkConnection ( ) ; $ conn = $ this -> connection ; return array_map ( function ( $ col ) { return $ col -> getName ( ) ; } , $ conn -> listCollections ( ) ) ; }
Returns the list of collections in the currently - connected database .
58,025
public function describe ( $ collection , $ fields = [ ] , array $ meta = [ ] ) { if ( ! $ fields && ( $ func = $ this -> _schema ) ) { $ fields = $ func ( $ this , $ collection , $ meta ) ; } return $ this -> _instance ( 'schema' , compact ( 'fields' ) ) ; }
Gets the column schema for a given MongoDB collection . Only returns a schema if the schema configuration flag has been set in the constructor .
58,026
public function read ( $ query , array $ options = [ ] ) { $ this -> _checkConnection ( ) ; $ defaults = [ 'return' => 'resource' ] ; $ options += $ defaults ; $ params = compact ( 'query' , 'options' ) ; return Filters :: run ( $ this , __FUNCTION__ , $ params , function ( $ params ) { $ prefix = $ this -> _config [ '...
Read from document
58,027
public function relationship ( $ class , $ type , $ name , array $ config = [ ] ) { $ fieldName = $ this -> relationFieldName ( $ type , $ name ) ; $ config += compact ( 'name' , 'type' , 'key' , 'fieldName' ) ; $ config [ 'from' ] = $ class ; return $ this -> _instance ( 'relationship' , $ config + [ 'strategy' => fun...
Document relationships .
58,028
public function group ( $ group , $ context ) { if ( ! $ group ) { return ; } if ( is_string ( $ group ) && strpos ( $ group , 'function' ) === 0 ) { return [ '$keyf' => new MongoCode ( $ group ) ] ; } $ group = ( array ) $ group ; foreach ( $ group as $ i => $ field ) { if ( is_int ( $ i ) ) { $ group [ $ field ] = tr...
Formats group clauses for MongoDB .
58,029
public function conditions ( $ conditions , $ context ) { if ( ! $ conditions ) { return [ ] ; } if ( $ code = $ this -> _isMongoCode ( $ conditions ) ) { return $ code ; } $ schema = null ; $ model = null ; if ( $ context ) { $ schema = $ context -> schema ( ) ; $ model = $ context -> model ( ) ; } return $ this -> _c...
Maps incoming conditions with their corresponding MongoDB - native operators .
58,030
protected function _conditions ( array $ conditions , $ model , $ schema , $ context ) { $ ops = $ this -> _operators ; $ castOpts = [ 'first' => true , 'database' => $ this , 'wrap' => false , 'asContent' => true ] ; $ cast = function ( $ key , $ value ) use ( & $ schema , & $ castOpts ) { return $ schema ? $ schema -...
Protected helper method used to format conditions .
58,031
public function order ( $ order , $ context ) { if ( ! $ order ) { return [ ] ; } if ( is_string ( $ order ) ) { return [ $ order => 1 ] ; } if ( ! is_array ( $ order ) ) { return [ ] ; } foreach ( $ order as $ key => $ value ) { if ( ! is_string ( $ key ) ) { unset ( $ order [ $ key ] ) ; $ order [ $ value ] = 1 ; con...
Return formatted clause for order .
58,032
public static function canonicalize ( $ locale ) { $ tags = static :: decompose ( $ locale ) ; foreach ( $ tags as $ name => & $ tag ) { foreach ( ( array ) static :: $ _tags [ $ name ] [ 'formatter' ] as $ formatter ) { $ tag = $ formatter ( $ tag ) ; } } return static :: compose ( $ tags ) ; }
Returns a locale in its canonical form with tags formatted properly .
58,033
public static function cascade ( $ locale ) { $ locales [ ] = $ locale ; if ( $ locale === 'root' ) { return $ locales ; } $ tags = static :: decompose ( $ locale ) ; while ( count ( $ tags ) > 1 ) { array_pop ( $ tags ) ; $ locales [ ] = static :: compose ( $ tags ) ; } $ locales [ ] = 'root' ; return $ locales ; }
Cascades a locale .
58,034
public static function lookup ( $ locales , $ locale ) { $ tags = static :: decompose ( $ locale ) ; while ( ( $ count = count ( $ tags ) ) > 0 ) { if ( ( $ key = array_search ( static :: compose ( $ tags ) , $ locales ) ) !== false ) { return $ locales [ $ key ] ; } if ( $ count === 1 ) { foreach ( $ locales as $ curr...
Searches an array of locales for the best match to a locale . The locale is iteratively simplified until either it matches one of the locales in the list or the locale can t be further simplified .
58,035
public static function preferred ( $ request , $ available = null ) { if ( is_array ( $ request ) ) { $ result = $ request ; } elseif ( $ request instanceof ActionRequest ) { $ result = static :: _preferredAction ( $ request ) ; } elseif ( $ request instanceof ConsoleRequest ) { $ result = static :: _preferredConsole (...
Determines the preferred locale from a request or array . Optionally negotiates the preferred locale with available locales .
58,036
protected static function _preferredAction ( $ request ) { $ result = [ ] ; $ regex = "/^\s*(?P<locale>\w\w(?:[-]\w\w)?)(?:;q=(?P<quality>(0|1|0\.\d+)))?\s*$/" ; foreach ( explode ( ',' , $ request -> env ( 'HTTP_ACCEPT_LANGUAGE' ) ) as $ part ) { if ( preg_match ( $ regex , $ part , $ matches ) ) { $ locale = static :...
Detects preferred locales from an action request by looking at the Accept - Language header as described by RFC 2616 section 14 . 4 .
58,037
public static function calculate ( $ data , array $ options = [ ] ) { if ( ! is_scalar ( $ data ) ) { $ data = ( $ data instanceof Closure ) ? spl_object_hash ( $ data ) : serialize ( $ data ) ; } $ defaults = [ 'type' => 'sha512' , 'salt' => false , 'key' => false , 'raw' => false ] ; $ options += $ defaults ; if ( $ ...
Uses PHP s hashing functions to calculate a hash over the data provided using the options specified . The default hash algorithm is SHA - 512 .
58,038
public static function compare ( $ known , $ user ) { if ( function_exists ( 'hash_equals' ) ) { return hash_equals ( $ known , $ user ) ; } if ( ! is_string ( $ known ) || ! is_string ( $ user ) ) { trigger_error ( 'Expected `$known` & `$user` parameters to be strings.' , E_USER_WARNING ) ; return false ; } if ( ( $ l...
Compares two hashes in constant time to prevent timing attacks .
58,039
public function write ( $ priority , $ message ) { return function ( $ params ) { $ path = $ this -> _config [ 'path' ] . '/' . $ this -> _config [ 'file' ] ( $ params , $ this -> _config ) ; $ params [ 'timestamp' ] = date ( $ this -> _config [ 'timestamp' ] ) ; $ message = Text :: insert ( $ this -> _config [ 'format...
Appends a message to a log file .
58,040
public function run ( array $ params , $ implementation ) { $ this -> _implementation = $ implementation ; $ filter = reset ( $ this -> _filters ) ; $ result = $ filter ( $ params , $ this ) ; $ this -> _implementation = null ; return $ result ; }
Runs the chain causing any queued callables and finally the implementation to be executed .
58,041
public function next ( $ params ) { $ message = '`$chain->next()` has been deprecated in favor of `$chain($params)`.' ; trigger_error ( $ message , E_USER_DEPRECATED ) ; return $ this ( $ this -> _bcNext ( func_get_args ( ) ) ) ; }
Advances the chain by one and executes the next filter in line . This method is usually accessed from within a filter function .
58,042
public static function enabled ( ) { $ loaded = extension_loaded ( 'apc' ) ; $ isCli = ( php_sapi_name ( ) === 'cli' ) ; $ enabled = ( ! $ isCli && ini_get ( 'apc.enabled' ) ) || ( $ isCli && ini_get ( 'apc.enable_cli' ) ) ; return ( $ loaded && $ enabled ) ; }
Determines if the APC extension has been installed and if the userspace cache is available .
58,043
public function config ( array $ config = [ ] ) { if ( ! $ config ) { $ keys = [ 'base' => '' , 'text' => '' , 'textarea' => '' , 'attributes' => '' ] ; return [ 'templates' => $ this -> _templateMap ] + array_intersect_key ( $ this -> _config , $ keys ) ; } if ( isset ( $ config [ 'templates' ] ) ) { $ this -> _templa...
Allows you to configure a default set of options which are included on a per - method basis and configure method template overrides .
58,044
public function binding ( $ name = null ) { if ( ! $ this -> _binding ) { return $ this -> _config [ 'binding' ] ( null , $ name ) ; } $ binding = $ this -> _binding ; $ model = null ; $ key = $ name ; if ( is_array ( $ binding ) ) { switch ( true ) { case strpos ( $ name , '.' ) : list ( $ model , $ key ) = explode ( ...
Returns the entity that the Form helper is currently bound to .
58,045
protected function _defaults ( $ method , $ name , $ options ) { $ params = compact ( 'method' , 'name' , 'options' ) ; return Filters :: run ( $ this , __FUNCTION__ , $ params , function ( $ params ) { $ method = $ params [ 'method' ] ; $ name = $ params [ 'name' ] ; $ options = $ params [ 'options' ] ; $ methodConfig...
Builds the defaults array for a method by name according to the config .
58,046
protected function _generators ( $ method , $ name , $ options ) { foreach ( $ this -> _config [ 'attributes' ] as $ key => $ generator ) { if ( $ key === 'name' ) { continue ; } if ( $ generator && ! isset ( $ options [ $ key ] ) ) { if ( ( $ attr = $ generator ( $ method , $ name , $ options ) ) !== null ) { $ option...
Iterates over the configured attribute generators and modifies the settings for a tag .
58,047
protected function _init ( ) { parent :: _init ( ) ; $ encoding = 'UTF-8' ; if ( $ this -> _response ) { $ encoding = & $ this -> _response -> encoding ; } $ h = function ( $ data ) use ( & $ encoding ) { return htmlspecialchars ( ( string ) $ data , ENT_QUOTES , $ encoding ) ; } ; $ this -> outputFilters += compact ( ...
Perform initialization of the View .
58,048
protected function _conditions ( array $ step , array $ params , array $ data , array $ options ) { if ( ! $ conditions = $ step [ 'conditions' ] ) { return true ; } $ isCallable = is_callable ( $ conditions ) && ! is_string ( $ conditions ) ; if ( $ isCallable && ! $ conditions ( $ params , $ data , $ options ) ) { re...
Evaluates a step condition to determine if the step should be executed .
58,049
protected function _step ( array $ step , array $ params , array & $ data , array & $ options = [ ] ) { $ step += [ 'path' => null , 'capture' => null ] ; $ _renderer = $ this -> _renderer ; $ _loader = $ this -> _loader ; $ filters = $ this -> outputFilters ; $ params = compact ( 'step' , 'params' , 'options' ) + [ 'd...
Performs a rendering step .
58,050
protected function _process ( $ process , & $ params ) { $ defaults = [ 'conditions' => null , 'multi' => false ] ; if ( ! is_array ( $ process ) ) { if ( ! isset ( $ this -> _processes [ $ process ] ) ) { throw new TemplateException ( "Undefined rendering process '{$process}'." ) ; } $ process = $ this -> _processes [...
Converts a process name to an array containing the rendering steps to be executed for each process .
58,051
public function open ( array $ options = [ ] ) { parent :: open ( $ options ) ; $ config = $ this -> _config ; if ( ! $ config [ 'scheme' ] || ! $ config [ 'host' ] ) { return false ; } $ url = "{$config['scheme']}://{$config['host']}:{$config['port']}" ; $ context = [ $ config [ 'scheme' ] => [ 'timeout' => $ this -> ...
Opens the socket and sets its timeout value .
58,052
public function read ( ) { if ( ! is_resource ( $ this -> _resource ) ) { return false ; } $ meta = stream_get_meta_data ( $ this -> _resource ) ; if ( isset ( $ meta [ 'wrapper_data' ] ) ) { $ headers = join ( "\r\n" , $ meta [ 'wrapper_data' ] ) . "\r\n\r\n" ; } else { $ headers = null ; } return $ headers . stream_g...
Reads from the socket . Does not apply to this implementation .
58,053
protected static function _initAdapter ( $ class , array $ config ) { $ params = compact ( 'class' , 'config' ) ; return Filters :: run ( get_called_class ( ) , __FUNCTION__ , $ params , function ( $ params ) { return new $ params [ 'class' ] ( $ params [ 'config' ] ) ; } ) ; }
Provides an extension point for modifying how adapters are instantiated .
58,054
protected static function _class ( $ config , $ paths = [ ] ) { if ( ! $ name = $ config [ 'adapter' ] ) { $ self = get_called_class ( ) ; throw new ConfigException ( "No adapter set for configuration in class `{$self}`." ) ; } if ( ! $ class = static :: _locate ( $ paths , $ name ) ) { $ self = get_called_class ( ) ; ...
Looks up an adapter by class by name .
58,055
protected static function _strategy ( $ name , $ paths = [ ] ) { if ( ! $ name ) { $ self = get_called_class ( ) ; throw new ConfigException ( "No strategy set for configuration in class `{$self}`." ) ; } if ( ! $ class = static :: _locate ( $ paths , $ name ) ) { $ self = get_called_class ( ) ; throw new ConfigExcepti...
Looks up a strategy by class by name .
58,056
protected static function _locate ( $ paths , $ name ) { foreach ( ( array ) $ paths as $ path ) { if ( $ class = Libraries :: locate ( $ path , $ name ) ) { return $ class ; } } return null ; }
Perform library location for an array of paths or a single string - based path .
58,057
protected static function _config ( $ name ) { if ( ! isset ( static :: $ _configurations [ $ name ] ) ) { return null ; } $ settings = static :: $ _configurations [ $ name ] ; if ( isset ( $ settings [ 0 ] ) ) { return $ settings [ 0 ] ; } $ env = Environment :: get ( ) ; $ config = isset ( $ settings [ $ env ] ) ? $ ...
Gets an array of settings for the given named configuration in the current environment . Each configuration will at least contain an adapter option .
58,058
public static function comment ( $ comment ) { $ text = null ; $ tags = [ ] ; $ description = null ; $ comment = trim ( preg_replace ( '/^(\s*\/\*\*|\s*\*{1,2}\/|\s*\* ?)/m' , '' , $ comment ) ) ; $ comment = str_replace ( "\r\n" , "\n" , $ comment ) ; if ( $ items = preg_split ( '/\n@/ms' , $ comment , 2 ) ) { list ( ...
Parses a doc block into its major components of description text and tags .
58,059
public static function config ( $ config = [ ] ) { if ( ! $ config ) { return [ 'rules' => static :: $ _rules ] ; } foreach ( $ config as $ key => $ val ) { if ( isset ( static :: $ { '_' . $ key } ) ) { static :: $ { '_' . $ key } = $ val + static :: $ { '_' . $ key } ; } } }
Used to set configuration parameters for the Dispatcher .
58,060
protected static function _callable ( $ request , $ params , $ options ) { $ params = compact ( 'request' , 'params' , 'options' ) ; return Filters :: run ( get_called_class ( ) , __FUNCTION__ , $ params , function ( $ params ) { $ request = $ params [ 'request' ] ; $ params = $ params [ 'params' ] ; $ name = $ params ...
Determines which command to use for current request .
58,061
protected static function _call ( $ callable , $ request , $ params ) { $ params = compact ( 'callable' , 'request' , 'params' ) ; return Filters :: run ( get_called_class ( ) , __FUNCTION__ , $ params , function ( $ params ) { if ( is_callable ( $ callable = $ params [ 'callable' ] ) ) { $ request = $ params [ 'reques...
Calls a given command with the appropriate action .
58,062
public function charset ( $ encoding = null ) { if ( $ response = $ this -> _context -> response ( ) ) { $ encoding = $ encoding ? : $ response -> encoding ; } return $ this -> _render ( __METHOD__ , 'charset' , compact ( 'encoding' ) ) ; }
Returns a charset meta - tag for declaring the encoding of the document .
58,063
protected function _metaLink ( $ type , $ url = null , array $ options = [ ] ) { $ options += isset ( $ this -> _metaLinks [ $ type ] ) ? $ this -> _metaLinks [ $ type ] : [ ] ; if ( $ type === 'icon' ) { $ url = $ url ? : 'favicon.ico' ; $ standard = $ this -> _render ( __METHOD__ , 'meta-link' , compact ( 'url' , 'op...
Creates a link to an external resource .
58,064
public function get ( $ name = null ) { if ( $ name === null ) { $ result = [ ] ; $ this -> _configurations = array_filter ( $ this -> _configurations ) ; foreach ( $ this -> _configurations as $ key => $ value ) { $ result [ $ key ] = $ this -> get ( $ key ) ; } return $ result ; } $ settings = & $ this -> _configurat...
Gets an array of settings for the given named configuration in the current environment .
58,065
public function export ( string $ fingerprint ) : string { $ gnupg = new \ Crypt_GPG ( $ this -> options ) ; try { $ gnupg -> addEncryptKey ( $ fingerprint ) ; return $ gnupg -> exportPublicKey ( $ fingerprint , true ) ; } catch ( \ PEAR_Exception $ ex ) { throw new GPGMailerException ( 'Could not export fingerprint "'...
Get the public key corresponding to a fingerprint .
58,066
public function import ( string $ gpgKey ) : string { try { $ gnupg = new \ Crypt_GPG ( $ this -> options ) ; $ data = $ gnupg -> importKey ( $ gpgKey ) ; return $ data [ 'fingerprint' ] ; } catch ( \ PEAR_Exception $ ex ) { throw new GPGMailerException ( 'Could not import public key: ' . $ ex -> getMessage ( ) , $ ex ...
Import a public key return the fingerprint
58,067
public function send ( Message $ message , string $ fingerprint ) { if ( $ this -> serverKeyFingerprint ) { $ this -> mailer -> send ( $ this -> encryptAndSign ( $ message , $ fingerprint ) ) ; } else { $ this -> mailer -> send ( $ this -> encrypt ( $ message , $ fingerprint ) ) ; } }
Encrypt then email a message
58,068
public function sendUnencrypted ( Message $ message , bool $ force = false ) { if ( ! $ this -> serverKeyFingerprint ) { if ( $ force ) { $ message -> setBody ( $ message -> getBodyText ( ) ) ; } return ; } $ this -> mailer -> send ( $ this -> sign ( $ message ) ) ; }
Email a message without encrypting it .
58,069
public function setOption ( string $ key , $ value ) : self { $ options = $ this -> options ; $ options [ $ key ] = $ value ; try { ( new \ Crypt_GPG ( $ options ) ) ; } catch ( \ PEAR_Exception $ ex ) { throw new GPGMailerException ( 'Could not set option "' . $ key . '": ' . $ ex -> getMessage ( ) , $ ex -> getCode (...
Override an option at runtime
58,070
public function setPrivateKey ( string $ serverKey ) : self { $ this -> serverKeyFingerprint = $ this -> import ( $ serverKey ) ; return $ this ; }
Sets the private key for signing .
58,071
public function verify ( Message $ message , string $ fingerprint ) : bool { $ gnupg = new \ Crypt_GPG ( $ this -> options ) ; $ gnupg -> addSignKey ( $ fingerprint ) ; try { $ verified = $ gnupg -> verify ( $ message -> getBodyText ( ) ) ; foreach ( $ verified as $ sig ) { if ( $ sig -> isValid ( ) ) { return true ; }...
Verify a message
58,072
protected function hasDelimiterToArray ( $ str ) { if ( is_string ( $ str ) && preg_match ( '/[,|]/is' , $ str ) ) { return preg_split ( '/ ?[,|] ?/' , strtolower ( $ str ) ) ; } return is_array ( $ str ) ? array_filter ( $ str , 'strtolower' ) : ( is_object ( $ str ) ? $ str : strtolower ( $ str ) ) ; }
Converts strings having comma or pipe to an array in lowercase
58,073
protected function hasRole ( ) { $ request = $ this -> request ; $ role = $ this -> getAction ( 'is' ) ; return ! $ this -> forbiddenRoute ( ) && $ request -> user ( ) -> hasRole ( $ role ) ; }
Check if user has requested route role .
58,074
protected function hasPermission ( ) { $ request = $ this -> request ; $ do = $ this -> getAction ( 'can' ) ; return ! $ this -> forbiddenRoute ( ) && $ request -> user ( ) -> can ( $ do ) ; }
Check if user has requested route permissions .
58,075
protected function protectMethods ( ) { $ request = $ this -> request ; $ resources = $ this -> crud [ 'resources' ] ; $ methods = $ this -> getAction ( 'protect_methods' ) ; $ caller = $ this -> parseMethod ( ) ; $ called = in_array ( $ caller , $ resources ) ? $ caller : $ request -> method ( ) ; $ methods = is_array...
Protect Crud functions of controller .
58,076
protected function getAction ( $ key ) { $ action = $ this -> request -> route ( ) -> getAction ( ) ; return isset ( $ action [ $ key ] ) ? $ action [ $ key ] : false ; }
Extract required action from requested route .
58,077
protected function parseAlias ( ) { if ( $ alias = $ this -> getAction ( 'protect_alias' ) ) { return $ alias ; } $ action = $ this -> request -> route ( ) -> getActionName ( ) ; $ ctrl = preg_match ( '/([^@]+)+/is' , $ action , $ m ) ? $ m [ 1 ] : $ action ; $ name = last ( explode ( '\\' , $ ctrl ) ) ; $ name = str_r...
Extract controller name make it singular to match it with model name to be able to match against permissions view . user create . user etc .
58,078
protected function parseMethod ( ) { $ action = $ this -> request -> route ( ) -> getActionName ( ) ; if ( preg_match ( '/@([^\s].+)$/is' , $ action , $ m ) ) { $ controller = $ m [ 1 ] ; if ( $ controller != 'Closure' ) { return $ controller ; } } return false ; }
Extract controller method
58,079
protected function crudConfigOverride ( ) { if ( ( $ restful = config ( 'acl.crud.restful' ) ) != null ) { $ this -> crud [ 'restful' ] = $ restful ; } if ( ( $ resource = config ( 'acl.crud.resource' ) ) != null ) { $ this -> crud [ 'resource' ] = $ resource ; } }
Override crud property via config .
58,080
public function getPermissions ( ) { $ permissions = \ Cache :: remember ( 'acl.getPermissionsById_' . $ this -> id , config ( 'acl.cacheMinutes' ) , function ( ) { return $ this -> getPermissionsInherited ( ) ; } ) ; foreach ( $ this -> roles as $ role ) { foreach ( $ role -> getPermissions ( ) as $ slug => $ array ) ...
Get all user permissions including user all role permissions .
58,081
public function can ( $ permission , $ operator = null ) { $ merge = \ Cache :: remember ( 'acl.getMergeById_' . $ this -> id , config ( 'acl.cacheMinutes' ) , function ( ) { return $ this -> getPermissions ( ) ; } ) ; $ model = config ( 'acl.role' , 'Kodeine\Acl\Models\Eloquent\Role' ) ; return ( new $ model ) -> can ...
Check if User has the given permission .
58,082
public function assignPermission ( $ permission ) { return $ this -> mapArray ( $ permission , function ( $ permission ) { $ permissionId = $ this -> parsePermissionId ( $ permission ) ; if ( ! $ this -> permissions -> keyBy ( 'id' ) -> has ( $ permissionId ) ) { $ this -> permissions ( ) -> attach ( $ permissionId ) ;...
Assigns the given permission to the user .
58,083
public function revokePermission ( $ permission ) { return $ this -> mapArray ( $ permission , function ( $ permission ) { $ permissionId = $ this -> parsePermissionId ( $ permission ) ; return $ this -> permissions ( ) -> detach ( $ permissionId ) ; } ) ; }
Revokes the given permission from the user .
58,084
protected function parsePermissionId ( $ permission ) { if ( is_string ( $ permission ) || is_numeric ( $ permission ) ) { $ model = config ( 'acl.permission' , 'Kodeine\Acl\Models\Eloquent\Permission' ) ; $ key = is_numeric ( $ permission ) ? 'id' : 'name' ; $ alias = ( new $ model ) -> where ( $ key , $ permission ) ...
Parses permission id from object or array .
58,085
public function scopeRole ( $ query , $ role , $ column = null ) { if ( is_null ( $ role ) ) { return $ query ; } return $ query -> whereHas ( 'roles' , function ( $ query ) use ( $ role , $ column ) { if ( is_array ( $ role ) ) { $ queryColumn = ! is_null ( $ column ) ? $ column : 'roles.slug' ; $ query -> whereIn ( $...
Scope to select users having a specific role . Role can be an id or slug .
58,086
public function revokeRole ( $ role ) { return $ this -> mapArray ( $ role , function ( $ role ) { $ roleId = $ this -> parseRoleId ( $ role ) ; return $ this -> roles ( ) -> detach ( $ roleId ) ; } ) ; }
Revokes the given role from the user .
58,087
protected function parseRoleId ( $ role ) { if ( is_string ( $ role ) || is_numeric ( $ role ) ) { $ model = config ( 'acl.role' , 'Kodeine\Acl\Models\Eloquent\Role' ) ; $ key = is_numeric ( $ role ) ? 'id' : 'slug' ; $ alias = ( new $ model ) -> where ( $ key , $ role ) -> first ( ) ; if ( ! is_object ( $ alias ) || !...
Parses role id from object array or a string .
58,088
protected function registerBlade5_1 ( ) { Blade :: directive ( 'role' , function ( $ expression ) { return "<?php if (Auth::check() && Auth::user()->is{$expression}): ?>" ; } ) ; Blade :: directive ( 'endrole' , function ( ) { return "<?php endif; ?>" ; } ) ; Blade :: directive ( 'permission' , function ( $ expression ...
Register Blade Template Extensions for > = L5 . 1
58,089
protected function registerBlade5_0 ( ) { $ blade = $ this -> app [ 'view' ] -> getEngineResolver ( ) -> resolve ( 'blade' ) -> getCompiler ( ) ; $ blade -> extend ( function ( $ view , $ compiler ) { $ pattern = $ compiler -> createMatcher ( 'role' ) ; return preg_replace ( $ pattern , '<?php if (Auth::check() && Auth...
Register Blade Template Extensions for < = L5 . 0
58,090
public function setStreamTimeout ( $ seconds ) { if ( $ this -> isConnected ( ) === true ) { if ( is_numeric ( $ seconds ) === true ) { try { $ timeout = number_format ( $ seconds , 3 ) ; $ seconds = floor ( $ timeout ) ; $ microseconds = ( ( $ timeout - $ seconds ) * 1000 ) ; return stream_set_timeout ( $ this -> stre...
Set Stream Timeout .
58,091
private function getStream ( $ address , $ timeout , $ context ) { $ errno = null ; $ errstr = null ; set_error_handler ( function ( ) { return true ; } ) ; $ fp = stream_socket_client ( $ address , $ errno , $ errstr , $ timeout , STREAM_CLIENT_CONNECT , $ context ) ; restore_error_handler ( ) ; if ( $ fp === false ) ...
Returns an stream socket to the desired server .
58,092
private function send ( $ payload ) { $ msg = $ payload . "\r\n" ; $ len = strlen ( $ msg ) ; while ( true ) { $ written = @ fwrite ( $ this -> streamSocket , $ msg ) ; if ( $ written === false ) { throw new \ Exception ( 'Error sending data' ) ; } if ( $ written === 0 ) { throw new \ Exception ( 'Broken pipe or closed...
Sends data thought the stream .
58,093
private function receive ( $ len = 0 ) { if ( $ len > 0 ) { $ chunkSize = $ this -> chunkSize ; $ line = null ; $ receivedBytes = 0 ; while ( $ receivedBytes < $ len ) { $ bytesLeft = ( $ len - $ receivedBytes ) ; if ( $ bytesLeft < $ this -> chunkSize ) { $ chunkSize = $ bytesLeft ; } $ readChunk = fread ( $ this -> s...
Receives a message thought the stream .
58,094
private function handleMSG ( $ line ) { $ parts = explode ( ' ' , $ line ) ; $ subject = null ; $ length = trim ( $ parts [ 3 ] ) ; $ sid = $ parts [ 2 ] ; if ( count ( $ parts ) === 5 ) { $ length = trim ( $ parts [ 4 ] ) ; $ subject = $ parts [ 3 ] ; } elseif ( count ( $ parts ) === 4 ) { $ length = trim ( $ parts [ ...
Handles MSG command .
58,095
public function request ( $ subject , $ payload , \ Closure $ callback ) { $ inbox = uniqid ( '_INBOX.' ) ; $ sid = $ this -> subscribe ( $ inbox , $ callback ) ; $ this -> unsubscribe ( $ sid , 1 ) ; $ this -> publish ( $ subject , $ payload , $ inbox ) ; $ this -> wait ( 1 ) ; }
Request does a request and executes a callback with the response .
58,096
public function unsubscribe ( $ sid , $ quantity = null ) { $ msg = 'UNSUB ' . $ sid ; if ( $ quantity !== null ) { $ msg = $ msg . ' ' . $ quantity ; } $ this -> send ( $ msg ) ; if ( $ quantity === null ) { unset ( $ this -> subscriptions [ $ sid ] ) ; } }
Unsubscribe from a event given a subject .
58,097
public function wait ( $ quantity = 0 ) { $ count = 0 ; $ info = stream_get_meta_data ( $ this -> streamSocket ) ; while ( is_resource ( $ this -> streamSocket ) === true && feof ( $ this -> streamSocket ) === false && empty ( $ info [ 'timed_out' ] ) === true ) { $ line = $ this -> receive ( ) ; if ( $ line === false ...
Waits for messages .
58,098
public function close ( ) { if ( $ this -> streamSocket === null ) { return ; } fclose ( $ this -> streamSocket ) ; $ this -> streamSocket = null ; }
Close will close the connection to the server .
58,099
public function decryptStringRequestWithSharedKey ( RequestInterface $ request , SharedEncryptionKey $ key ) : string { return Simple :: decrypt ( ( string ) $ request -> getBody ( ) , $ key ) ; }
Decrypt an HTTP request with a pre - shared key then get the body as a string .