idx int64 0 60.3k | question stringlengths 92 4.62k | target stringlengths 7 635 |
|---|---|---|
57,700 | public static function rules ( $ name = null ) { if ( ! $ name ) { return array_keys ( static :: $ _rules ) ; } return isset ( static :: $ _rules [ $ name ] ) ? static :: $ _rules [ $ name ] : null ; } | Returns a list of available validation rules or the configuration details of a single rule . |
57,701 | protected function _init ( ) { if ( ! $ this -> connection ) { $ this -> connection = new RedisCore ( ) ; } $ method = $ this -> _config [ 'persistent' ] ? 'pconnect' : 'connect' ; if ( HostString :: isSocket ( $ this -> _config [ 'host' ] ) ) { $ this -> connection -> { $ method } ( $ this -> _config [ 'host' ] ) ; } ... | Initialize the Redis connection object connect to the Redis server and sets prefix using the scope if provided . |
57,702 | protected function _merge ( array $ data , array $ item ) { if ( ! isset ( $ item [ 'id' ] ) ) { return $ data ; } $ id = $ item [ 'id' ] ; $ defaults = [ 'ids' => [ ] , 'translated' => null , 'flags' => [ ] , 'comments' => [ ] , 'occurrences' => [ ] ] ; $ item += $ defaults ; if ( isset ( $ item [ 'context' ] ) && $ i... | Merges an item into given data . |
57,703 | public static function template ( $ file , array $ options = [ ] ) { $ cachePath = Libraries :: get ( true , 'resources' ) . '/tmp/cache/templates' ; $ defaults = [ 'path' => $ cachePath , 'fallback' => false ] ; $ options += $ defaults ; $ stats = stat ( $ file ) ; $ oname = basename ( dirname ( $ file ) ) . '_' . bas... | Compiles a template and writes it to a cache file which is used for inclusion . |
57,704 | protected function _init ( ) { parent :: _init ( ) ; if ( ! $ this -> _context ) { return ; } $ this -> _context -> strings ( $ this -> _strings ) ; if ( $ this -> _config [ 'handlers' ] ) { $ this -> _context -> handlers ( $ this -> _config [ 'handlers' ] ) ; } } | Imports local string definitions into rendering context . |
57,705 | protected function _options ( array $ defaults , array $ scope ) { $ scope += $ defaults ; $ options = array_diff_key ( $ scope , $ defaults ) ; return [ $ scope , $ options ] ; } | Takes the defaults and current options merges them and returns options which have the default keys removed and full set of options as the scope . |
57,706 | protected function _attributes ( $ params , $ method = null , array $ options = [ ] ) { $ defaults = [ 'escape' => true , 'prepend' => ' ' , 'append' => '' ] ; $ options += $ defaults ; $ result = [ ] ; if ( ! is_array ( $ params ) ) { return ! $ params ? '' : $ options [ 'prepend' ] . $ params ; } foreach ( $ params a... | Converts a set of parameters to HTML attributes into a string . |
57,707 | public function send ( $ query = null , array $ options = [ ] ) { $ query = ! is_object ( $ query ) ? new Query ( ( array ) $ query ) : $ query ; $ method = $ query -> method ( ) ? : "get" ; $ path = $ query -> path ( ) ; $ data = $ query -> data ( ) ; $ insert = ( array ) $ options + $ data + $ query -> export ( $ thi... | Method to send to a specific resource . |
57,708 | public function disconnect ( ) { if ( $ this -> _isConnected && $ this -> connection !== null ) { $ this -> _isConnected = false ; } return ! $ this -> _isConnected ; } | Disconnect from socket . |
57,709 | public function read ( $ query , array $ options = [ ] ) { $ query = ! is_object ( $ query ) ? new Query ( ) : $ query ; $ query -> method ( ) ? : $ query -> method ( "get" ) ; $ query -> path ( ) ? : $ query -> path ( "/{:source}" ) ; $ params = [ $ query , $ options ] ; return Filters :: run ( $ this , __FUNCTION__ ,... | Read used by model to GET . |
57,710 | protected function _file ( $ category , $ locale , $ scope ) { $ path = $ this -> _config [ 'path' ] ; $ scope = $ scope ? : 'default' ; if ( ( $ pos = strpos ( $ category , 'Template' ) ) !== false ) { $ category = substr ( $ category , 0 , $ pos ) ; return "{$path}/{$category}_{$scope}.php" ; } return "{$path}/{$loca... | Helper method for transforming a category locale and scope into a filename . |
57,711 | protected function _init ( ) { $ this -> connection = $ this -> connection ? : new Memcached ( ) ; $ this -> connection -> addServers ( $ this -> _formatHostList ( $ this -> _config [ 'host' ] ) ) ; if ( $ this -> _config [ 'scope' ] ) { $ this -> connection -> setOption ( Memcached :: OPT_PREFIX_KEY , "{$this->_config... | Handles the actual Memcached connection and server connection adding for the adapter constructor and sets prefix using the scope if provided . |
57,712 | public static function config ( array $ config = [ ] ) { if ( ! $ config ) { return [ 'classes' => static :: $ _classes ] ; } foreach ( $ config as $ key => $ val ) { $ key = "_{$key}" ; if ( isset ( static :: $ { $ key } ) ) { static :: $ { $ key } = $ val + static :: $ { $ key } ; } } } | Used to get or reconfigure dependencies with custom classes . |
57,713 | public static function config ( array $ config = [ ] ) { if ( ! $ config ) { return [ 'classes' => static :: $ _classes , 'secret' => static :: $ _secret ] ; } if ( isset ( $ config [ 'classes' ] ) ) { static :: $ _classes = $ config [ 'classes' ] + static :: $ _classes ; } if ( isset ( $ config [ 'secret' ] ) ) { stat... | Configures the class or retrieves current class configuration . |
57,714 | public static function key ( array $ data ) { $ data += [ 'fields' => [ ] , 'locked' => [ ] , 'excluded' => [ ] ] ; return static :: _compile ( array_keys ( Set :: flatten ( $ data [ 'fields' ] ) ) , $ data [ 'locked' ] , array_keys ( $ data [ 'excluded' ] ) ) ; } | Generates form signature string from form data . |
57,715 | public static function check ( $ data ) { if ( is_object ( $ data ) && isset ( $ data -> data ) ) { $ data = $ data -> data ; } if ( ! isset ( $ data [ 'security' ] [ 'signature' ] ) ) { throw new Exception ( 'Unable to check form signature. Cannot find signature in data.' ) ; } $ signature = $ data [ 'security' ] [ 's... | Validates form data using an embedded form signature string . The form signature string must be embedded in security . signature alongside the other data to check against . |
57,716 | protected static function _signature ( $ data ) { $ hash = static :: $ _classes [ 'hash' ] ; if ( empty ( static :: $ _secret ) ) { $ message = 'Form signature requires a secret key. ' ; $ message .= 'Please see documentation on how to configure a key.' ; throw new ConfigException ( $ message ) ; } $ key = 'li3,1' . st... | Calculates signature over given data . |
57,717 | protected static function _parse ( $ string ) { if ( substr_count ( $ string , '::' ) !== 2 ) { throw new Exception ( 'Possible data tampering: form signature string has wrong format.' ) ; } list ( $ locked , $ excluded ) = explode ( '::' , $ string , 3 ) ; return [ 'locked' => unserialize ( urldecode ( $ locked ) ) , ... | Parses form signature string . |
57,718 | public static function export ( $ var ) { $ export = var_export ( $ var , true ) ; if ( is_array ( $ var ) ) { $ replace = [ " (" , " )" , " " , " )" , "=> \n\t" ] ; $ with = [ "(" , ")" , "\t" , "\t)" , "=> " ] ; $ export = str_replace ( $ replace , $ with , $ export ) ; } return $ export ; } | Returns a parseable string representation of a variable . |
57,719 | protected static function _definition ( $ reference , $ callLine ) { if ( file_exists ( $ reference ) ) { foreach ( array_reverse ( token_get_all ( file_get_contents ( $ reference ) ) ) as $ token ) { if ( ! is_array ( $ token ) || $ token [ 2 ] > $ callLine ) { continue ; } if ( $ token [ 0 ] === T_FUNCTION ) { return... | Locates original location of closures . |
57,720 | protected static function _closureDef ( $ frame , $ function ) { $ reference = '::' ; $ frame += [ 'file' => '??' , 'line' => '??' ] ; $ cacheKey = "{$frame['file']}@{$frame['line']}" ; if ( isset ( static :: $ _closureCache [ $ cacheKey ] ) ) { return static :: $ _closureCache [ $ cacheKey ] ; } if ( $ class = Inspect... | Helper method for caching closure function references to help the process of building the stack trace . |
57,721 | public static function apply ( $ class , $ method , $ filter ) { list ( $ id , ) = static :: _ids ( $ class , $ method ) ; if ( ! isset ( static :: $ _filters [ $ id ] ) ) { static :: $ _filters [ $ id ] = [ ] ; } static :: $ _filters [ $ id ] [ ] = $ filter ; if ( isset ( static :: $ _chains [ $ id ] ) ) { unset ( sta... | Lazily applies a filter to a method . |
57,722 | public static function run ( $ class , $ method , array $ params , $ implementation ) { $ implementation = static :: _bcImplementation ( $ class , $ method , $ params , $ implementation ) ; if ( ! static :: hasApplied ( $ class , $ method ) ) { return $ implementation ( $ params ) ; } return static :: _chain ( $ class ... | Runs the chain and returns its result value . This method is used to make a method filterable . |
57,723 | public static function clear ( $ class = null , $ method = null ) { if ( $ class === null && $ method === null ) { static :: $ _filters = static :: $ _chains = [ ] ; return ; } if ( is_string ( $ class ) ) { $ regex = '^<' . str_replace ( '\\' , '\\\\' , ltrim ( $ class , '\\' ) ) . '.*>' ; } else { $ regex = '^<.*#' .... | Clears filters optionally constrained by class or class and method combination . |
57,724 | public static function write ( $ name , $ key , $ data = null , $ expiry = null , array $ options = [ ] ) { $ options += [ 'conditions' => null , 'strategies' => true ] ; if ( is_callable ( $ options [ 'conditions' ] ) && ! $ options [ 'conditions' ] ( ) ) { return false ; } try { $ adapter = static :: adapter ( $ name... | Writes to the specified cache configuration . |
57,725 | public static function read ( $ name , $ key , array $ options = [ ] ) { $ options += [ 'conditions' => null , 'strategies' => true , 'write' => null ] ; if ( is_callable ( $ options [ 'conditions' ] ) && ! $ options [ 'conditions' ] ( ) ) { return false ; } try { $ adapter = static :: adapter ( $ name ) ; } catch ( Co... | Reads from the specified cache configuration . |
57,726 | public static function delete ( $ name , $ key , array $ options = [ ] ) { $ options += [ 'conditions' => null , 'strategies' => true ] ; if ( is_callable ( $ options [ 'conditions' ] ) && ! $ options [ 'conditions' ] ( ) ) { return false ; } try { $ adapter = static :: adapter ( $ name ) ; } catch ( ConfigException $ ... | Deletes using the specified cache configuration . |
57,727 | public static function increment ( $ name , $ key , $ offset = 1 , array $ options = [ ] ) { $ options += [ 'conditions' => null ] ; if ( is_callable ( $ options [ 'conditions' ] ) && ! $ options [ 'conditions' ] ( ) ) { return false ; } try { $ adapter = static :: adapter ( $ name ) ; } catch ( ConfigException $ e ) {... | Performs a increment operation on specified numeric cache item from the given cache configuration . |
57,728 | public function next ( ) { if ( $ this -> _buffer ) { list ( $ this -> _key , $ this -> _current ) = array_shift ( $ this -> _buffer ) ; return $ this -> _current ; } if ( ! $ next = $ this -> _fetch ( ) ) { $ this -> _key = null ; $ this -> _current = null ; $ this -> _valid = false ; return null ; } else { list ( $ t... | Fetches the next element from the resource . |
57,729 | public function peek ( ) { if ( $ this -> _buffer ) { return reset ( $ this -> _buffer ) ; } if ( ! $ next = $ this -> _fetch ( ) ) { return null ; } $ this -> _buffer [ ] = $ next ; $ first = reset ( $ this -> _buffer ) ; return end ( $ first ) ; } | Peeks at the next element in the resource without advancing Result s cursor . |
57,730 | protected function _init ( ) { if ( ! $ this -> _config [ 'host' ] && $ this -> _config [ 'host' ] !== false ) { throw new ConfigException ( 'No host configured.' ) ; } if ( $ this -> _config [ 'host' ] === false ) { $ this -> _config [ 'dsn' ] = sprintf ( 'pgsql:dbname=%s' , $ this -> _config [ 'database' ] ) ; } else... | Initializer . Constructs a DSN from configuration . |
57,731 | public function describe ( $ entity , $ fields = [ ] , array $ meta = [ ] ) { $ schema = $ this -> _config [ 'schema' ] ; $ params = compact ( 'entity' , 'meta' , 'fields' , 'schema' ) ; return Filters :: run ( $ this , __FUNCTION__ , $ params , function ( $ params ) { extract ( $ params ) ; if ( $ fields ) { return $ ... | Gets the column schema for a given PostgreSQL table . |
57,732 | public function body ( $ data = null , $ options = [ ] ) { $ defaults = [ 'encode' => true ] ; return parent :: body ( $ data , $ options + $ defaults ) ; } | Compile the HTTP message body optionally encoding its parts according to content type . |
57,733 | protected function _cookies ( ) { $ cookies = $ this -> cookies ; $ invalid = str_split ( ",; \+\t\r\n\013\014" ) ; $ replace = array_map ( 'rawurlencode' , $ invalid ) ; foreach ( $ cookies as $ key => & $ value ) { if ( ! is_scalar ( $ value ) ) { $ message = "Non-scalar value cannot be rendered for cookie `{$key}`" ... | Render Cookie header urlencoding invalid characters . |
57,734 | protected function _parseCookies ( $ header ) { $ cookies = array_map ( 'trim' , array_filter ( explode ( '; ' , $ header ) ) ) ; foreach ( $ cookies as $ cookie ) { list ( $ name , $ value ) = array_map ( 'urldecode' , explode ( '=' , $ cookie , 2 ) ) + [ '' , '' ] ; $ this -> cookies ( $ name , $ value ) ; } } | Parse Cookie header . |
57,735 | public function queryString ( $ params = [ ] , $ format = null ) { $ result = [ ] ; $ query = [ ] ; foreach ( array_filter ( [ $ this -> query , $ params ] ) as $ querySet ) { if ( is_string ( $ querySet ) ) { $ result [ ] = $ querySet ; continue ; } $ query = array_merge ( $ query , $ querySet ) ; } $ query = array_fi... | Get the full query string queryString . |
57,736 | public static function run ( array $ config = [ ] ) { $ defaults = [ 'trapErrors' => false , 'convertErrors' => true ] ; if ( static :: $ _isRunning ) { return ; } static :: $ _isRunning = true ; static :: $ _runOptions = $ config + $ defaults ; $ trap = function ( $ code , $ message , $ file , $ line = 0 , $ context =... | Register error and exception handlers . |
57,737 | public static function handle ( $ info , $ scope = [ ] ) { $ checks = static :: $ _checks ; $ rules = $ scope ? : static :: $ _config ; $ handler = static :: $ _exceptionHandler ; $ info = is_object ( $ info ) ? $ handler ( $ info , true ) : $ info ; $ defaults = [ 'type' => null , 'code' => 0 , 'message' => null , 'fi... | Receives the handled errors and exceptions that have been caught and processes them in a normalized manner . |
57,738 | public static function trace ( array $ stack ) { $ result = [ ] ; foreach ( $ stack as $ frame ) { if ( isset ( $ frame [ 'function' ] ) ) { if ( isset ( $ frame [ 'class' ] ) ) { $ result [ ] = trim ( $ frame [ 'class' ] , '\\' ) . '::' . $ frame [ 'function' ] ; } else { $ result [ ] = $ frame [ 'function' ] ; } } } ... | Trim down a typical stack trace to class & method calls . |
57,739 | protected function _use ( $ request ) { $ request -> params [ 'command' ] = 'model' ; return $ this -> _namespace ( $ request ) . '\\' . $ this -> _model ( $ request ) ; } | Get the fully - qualified model class that is used by the controller . |
57,740 | public function body ( $ data = null , $ options = [ ] ) { $ default = [ 'buffer' => null ] ; $ options += $ default ; $ this -> body = array_merge ( ( array ) $ this -> body , ( array ) $ data ) ; $ body = join ( "\r\n" , $ this -> body ) ; return ( $ options [ 'buffer' ] ) ? str_split ( $ body , $ options [ 'buffer' ... | Add body parts and compile the message body . |
57,741 | public function read ( $ data , array $ options = [ ] ) { $ class = $ options [ 'class' ] ; $ encrypted = $ class :: read ( null , [ 'strategies' => false ] ) ; $ key = isset ( $ options [ 'key' ] ) ? $ options [ 'key' ] : null ; if ( ! isset ( $ encrypted [ '__encrypted' ] ) || ! $ encrypted [ '__encrypted' ] ) { retu... | Read encryption method . |
57,742 | public function write ( $ data , array $ options = [ ] ) { $ class = $ options [ 'class' ] ; $ futureData = $ this -> read ( null , [ 'key' => null ] + $ options ) ? : [ ] ; $ futureData = [ $ options [ 'key' ] => $ data ] + $ futureData ; $ payload = empty ( $ futureData ) ? null : $ this -> _encrypt ( $ futureData ) ... | Write encryption method . |
57,743 | protected function _encrypt ( $ decrypted = [ ] ) { $ vector = $ this -> _config [ 'vector' ] ; $ secret = $ this -> _hashSecret ( $ this -> _config [ 'secret' ] ) ; mcrypt_generic_init ( static :: $ _resource , $ secret , $ vector ) ; $ encrypted = mcrypt_generic ( static :: $ _resource , serialize ( $ decrypted ) ) ;... | Serialize and encrypt a given data array . |
57,744 | protected function _decrypt ( $ encrypted ) { $ secret = $ this -> _hashSecret ( $ this -> _config [ 'secret' ] ) ; $ vectorSize = strlen ( base64_encode ( str_repeat ( " " , static :: _vectorSize ( ) ) ) ) ; $ vector = base64_decode ( substr ( $ encrypted , - $ vectorSize ) ) ; $ data = base64_decode ( substr ( $ encr... | Decrypt and unserialize a previously encrypted string . |
57,745 | protected function _hashSecret ( $ key ) { $ size = mcrypt_enc_get_key_size ( static :: $ _resource ) ; if ( strlen ( $ key ) >= $ size ) { return $ key ; } return substr ( hash ( 'sha256' , $ key , true ) , 0 , $ size ) ; } | Hashes the given secret to make harder to detect . |
57,746 | protected function _init ( ) { if ( $ this -> _config [ 'globals' ] ) { $ this -> _env += ( array ) $ _SERVER + ( array ) $ _ENV ; } $ this -> _env [ 'working' ] = str_replace ( '\\' , '/' , getcwd ( ) ) ? : null ; $ argv = ( array ) $ this -> env ( 'argv' ) ; $ this -> _env [ 'script' ] = array_shift ( $ argv ) ; $ th... | Initialize request object pulling request data from superglobals . |
57,747 | public function args ( $ key = 0 ) { if ( ! empty ( $ this -> args [ $ key ] ) ) { return $ this -> args [ $ key ] ; } return null ; } | Get the value of a command line argument at a given key |
57,748 | public static function compare ( $ known , $ user ) { $ message = "lithium\util\String::compare() has been deprecated in favor of " ; $ message .= "lithium\security\Hash::compare()." ; trigger_error ( $ message , E_USER_DEPRECATED ) ; return Hash :: compare ( $ known , $ user ) ; } | Compares two strings in constant time to prevent timing attacks . |
57,749 | public static function generate ( $ bytes , array $ options = [ ] ) { $ defaults = [ 'encode' => null ] ; $ options += $ defaults ; $ source = static :: $ _source ? : ( static :: $ _source = static :: _source ( ) ) ; $ result = $ source ( $ bytes ) ; if ( $ options [ 'encode' ] !== static :: ENCODE_BASE_64 ) { return $... | Generates random bytes for use in UUIDs and password salts using a cryptographically strong random number generator source . |
57,750 | protected static function _source ( ) { if ( function_exists ( 'random_bytes' ) ) { return function ( $ bytes ) { return random_bytes ( $ bytes ) ; } ; } if ( function_exists ( 'mcrypt_create_iv' ) ) { return function ( $ bytes ) { return mcrypt_create_iv ( $ bytes , MCRYPT_DEV_URANDOM ) ; } ; } if ( is_readable ( '/de... | Returns the best available random number generator source . |
57,751 | public static function apply ( $ class , $ method , $ filter ) { $ message = '`\lithium\util\collection\Filters::apply()` has been deprecated ' ; $ message .= 'in favor of `\lithium\aop\Filters::apply()`' ; trigger_error ( $ message , E_USER_DEPRECATED ) ; NewFilters :: apply ( $ class , $ method , $ filter ) ; } | Lazily applies a filter to a method of a static class . |
57,752 | public function next ( ) { if ( func_num_args ( ) !== 3 ) { trigger_error ( 'Missing argument/s.' , E_USER_WARNING ) ; return ; } list ( $ self , $ params , $ chain ) = func_get_args ( ) ; $ message = '`\lithium\util\collection\Filters::next()` has been deprecated ' ; $ message .= 'in favor of `\lithium\aop\Chain::next... | Provides short - hand convenience syntax for filter chaining . |
57,753 | public function template ( $ type , $ options ) { if ( isset ( $ options [ $ type ] ) ) { return $ options [ $ type ] ; } return isset ( $ options [ 'template' ] ) ? $ options [ 'template' ] : '' ; } | Returns a template string |
57,754 | protected static function _initialize ( $ class ) { $ self = static :: $ _instances [ $ class ] ; if ( isset ( static :: $ _initialized [ $ class ] ) && static :: $ _initialized [ $ class ] ) { return $ self ; } static :: $ _initialized [ $ class ] = true ; $ self -> _inherit ( ) ; $ source = [ 'classes' => [ ] , 'meta... | Init default connection options and connects default finders . |
57,755 | protected function _inherit ( ) { $ inherited = array_fill_keys ( $ this -> _inherited ( ) , [ ] ) ; foreach ( static :: _parents ( ) as $ parent ) { $ parentConfig = get_class_vars ( $ parent ) ; foreach ( $ inherited as $ key => $ value ) { if ( isset ( $ parentConfig [ "{$key}" ] ) ) { $ val = $ parentConfig [ "{$ke... | Merge parent class attributes to the current instance . |
57,756 | public static function find ( $ type , array $ options = [ ] ) { $ self = static :: _object ( ) ; if ( is_object ( $ type ) || ! isset ( $ self -> _finders [ $ type ] ) ) { $ options [ 'conditions' ] = static :: key ( $ type ) ; $ type = 'first' ; } $ options += ( array ) $ self -> _query ; $ meta = [ 'meta' => $ self ... | The find method allows you to retrieve data from the connected data source . |
57,757 | public static function finder ( $ name , $ finder = null ) { $ self = static :: _object ( ) ; if ( $ finder === null ) { return isset ( $ self -> _finders [ $ name ] ) ? $ self -> _finders [ $ name ] : null ; } if ( is_array ( $ finder ) ) { $ finder = function ( $ params , $ next ) use ( $ finder ) { $ params [ 'optio... | Sets or gets a custom finder by name . The finder definition can be an array of default query options or an anonymous functions that accepts an array of query options and a function to continue . To get a finder specify just the name . |
57,758 | protected static function _finders ( ) { $ self = static :: _object ( ) ; return [ 'all' => function ( $ params , $ next ) { return $ next ( $ params ) ; } , 'first' => function ( $ params , $ next ) { $ options = & $ params [ 'options' ] ; $ options [ 'limit' ] = 1 ; $ data = $ next ( $ params ) ; if ( isset ( $ optio... | Returns an array with the default finders . |
57,759 | public static function query ( $ query = null ) { $ self = static :: _object ( ) ; if ( ! $ query ) { return $ self -> _query ; } $ self -> _query = $ query + $ self -> _query ; } | Gets or sets the default query for the model . |
57,760 | public static function meta ( $ key = null , $ value = null ) { $ self = static :: _object ( ) ; $ isArray = is_array ( $ key ) ; if ( $ value || $ isArray ) { $ value ? $ self -> _meta [ $ key ] = $ value : $ self -> _meta = $ key + $ self -> _meta ; return ; } return $ self -> _getMetaKey ( $ isArray ? null : $ key )... | Gets or sets Model s metadata . |
57,761 | public static function key ( $ values = null ) { $ key = static :: meta ( 'key' ) ; if ( $ values === null ) { return $ key ; } $ self = static :: _object ( ) ; $ entity = $ self -> _classes [ 'entity' ] ; if ( is_object ( $ values ) && is_string ( $ key ) ) { return static :: _key ( $ key , $ values , $ entity ) ; } e... | If no values supplied returns the name of the Model key . If values are supplied returns the key value . |
57,762 | public static function relations ( $ type = null ) { $ self = static :: _object ( ) ; if ( $ type === null ) { return static :: _relations ( ) ; } if ( isset ( $ self -> _relationFieldNames [ $ type ] ) ) { $ type = $ self -> _relationFieldNames [ $ type ] ; } if ( isset ( $ self -> _relations [ $ type ] ) ) { return $... | Returns a list of models related to Model or a list of models related to this model but of a certain type . |
57,763 | protected static function _relations ( $ type = null , $ name = null ) { $ self = static :: _object ( ) ; if ( $ name ) { if ( isset ( $ self -> _relationsToLoad [ $ name ] ) ) { $ t = $ self -> _relationsToLoad [ $ name ] ; unset ( $ self -> _relationsToLoad [ $ name ] ) ; return static :: bind ( $ t , $ name , ( arra... | This method automagically bind in the fly unloaded relations . |
57,764 | public static function bind ( $ type , $ name , array $ config = [ ] ) { $ self = static :: _object ( ) ; if ( ! isset ( $ config [ 'fieldName' ] ) ) { $ config [ 'fieldName' ] = $ self -> _relationFieldName ( $ type , $ name ) ; } if ( ! in_array ( $ type , $ self -> _relationTypes ) ) { throw new ConfigException ( "I... | Creates a relationship binding between this model and another . |
57,765 | public static function hasField ( $ field ) { if ( ! is_array ( $ field ) ) { return static :: schema ( ) -> fields ( $ field ) ; } foreach ( $ field as $ f ) { if ( static :: hasField ( $ f ) ) { return $ f ; } } return false ; } | Checks to see if a particular field exists in a model s schema . Can check a single field or return the first field found in an array of multiple options . |
57,766 | public static function & connection ( ) { $ self = static :: _object ( ) ; $ connections = $ self -> _classes [ 'connections' ] ; $ name = isset ( $ self -> _meta [ 'connection' ] ) ? $ self -> _meta [ 'connection' ] : null ; if ( $ conn = $ connections :: get ( $ name ) ) { return $ conn ; } $ class = get_called_class... | Gets the connection object to which this model is bound . Throws exceptions if a connection isn t set or if the connection named isn t configured . |
57,767 | protected static function _relationsToLoad ( ) { try { if ( ! $ connection = static :: connection ( ) ) { return ; } } catch ( ConfigException $ e ) { return ; } if ( ! $ connection :: enabled ( 'relationships' ) ) { return ; } $ self = static :: _object ( ) ; foreach ( $ self -> _relationTypes as $ type ) { $ self -> ... | Iterates through relationship types to construct relation map . |
57,768 | protected function _save ( array $ params = [ ] ) { $ params [ 'path' ] = Inflector :: underscore ( $ this -> request -> action ) ; $ params [ 'file' ] = $ this -> request -> args ( 0 ) ; $ contents = $ this -> _template ( ) ; $ result = Text :: insert ( $ contents , $ params ) ; if ( ! empty ( $ this -> _library [ 'pa... | Override the save method to handle view specific params . |
57,769 | public function modified ( ) { if ( count ( $ this -> _original ) !== count ( $ this -> _data ) ) { return true ; } foreach ( $ this -> _original as $ key => $ doc ) { $ updated = $ this -> _data [ $ key ] ; if ( ! isset ( $ updated ) ) { return true ; } if ( $ doc !== $ updated ) { return true ; } if ( ! is_object ( $... | Determines if the DocumentSet has been modified since it was last saved |
57,770 | public function to ( $ format , array $ options = [ ] ) { $ this -> offsetGet ( null ) ; return parent :: to ( $ format , $ options ) ; } | Adds conversions checks to ensure certain class types and embedded values are properly cast . |
57,771 | protected function _populate ( ) { if ( $ this -> closed ( ) || ! $ this -> _result -> valid ( ) ) { return ; } $ data = $ this -> _result -> current ( ) ; $ result = $ this -> _set ( $ data , null , [ 'exists' => true , 'original' => true ] ) ; $ this -> _result -> next ( ) ; return $ result ; } | Extract the next item from the result ressource and wraps it into a Document object . |
57,772 | protected function _set ( $ data = null , $ offset = null , $ options = [ ] ) { if ( $ schema = $ this -> schema ( ) ) { $ model = $ this -> _model ; $ pathKey = $ this -> _pathKey ; $ options = compact ( 'model' , 'pathKey' ) + $ options ; $ data = ! is_object ( $ data ) ? $ schema -> cast ( $ this , $ offset , $ data... | Helper method to normalize and set data . |
57,773 | public static function get ( $ name = null , array $ options = [ ] ) { static $ mockAdapter ; $ defaults = [ 'config' => false , 'autoCreate' => true ] ; $ options += $ defaults ; if ( $ name === false ) { if ( ! $ mockAdapter ) { $ class = Libraries :: locate ( 'data.source' , 'Mock' ) ; $ mockAdapter = new $ class ( ... | Read the configuration or access the connections you have set up . |
57,774 | protected static function _class ( $ config , $ paths = [ ] ) { if ( ! $ config [ 'adapter' ] ) { $ config [ 'adapter' ] = $ config [ 'type' ] ; } else { $ paths = array_merge ( [ "adapter.data.source.{$config['type']}" ] , ( array ) $ paths ) ; } return parent :: _class ( $ config , $ paths ) ; } | Constructs a data source or adapter object instance from a configuration array . |
57,775 | public function output ( $ output ) { return fwrite ( $ this -> output , Text :: insert ( $ output , $ this -> styles ( ) ) ) ; } | Writes string to output stream |
57,776 | public function error ( $ error ) { return fwrite ( $ this -> error , Text :: insert ( $ error , $ this -> styles ( ) ) ) ; } | Writes string to error stream |
57,777 | protected static function _instance ( $ name , array $ options = [ ] ) { if ( is_string ( $ name ) && isset ( static :: $ _classes [ $ name ] ) ) { $ name = static :: $ _classes [ $ name ] ; } return Libraries :: instance ( null , $ name , $ options ) ; } | Returns an instance of a class with given config . The name could be a key from the classes array a fully namespaced class name or an object . Typically this method is used in _init to create the dependencies used in the current class . |
57,778 | public static function singularize ( $ word ) { if ( isset ( static :: $ _singularized [ $ word ] ) ) { return static :: $ _singularized [ $ word ] ; } if ( empty ( static :: $ _singular [ 'irregular' ] ) ) { static :: $ _singular [ 'irregular' ] = array_flip ( static :: $ _plural [ 'irregular' ] ) ; } extract ( static... | Changes the form of a word from plural to singular . |
57,779 | public static function config ( $ config = [ ] ) { if ( ! $ config ) { return [ 'classes' => static :: $ _classes , 'unicode' => static :: $ _unicode ] ; } if ( isset ( $ config [ 'classes' ] ) ) { static :: $ _classes = $ config [ 'classes' ] + static :: $ _classes ; } if ( isset ( $ config [ 'unicode' ] ) ) { static ... | Modify Router configuration settings and dependencies . |
57,780 | public static function connect ( $ template , $ params = [ ] , $ options = [ ] ) { if ( is_array ( $ options ) && isset ( $ options [ 'scope' ] ) ) { $ name = $ options [ 'scope' ] ; } else { $ name = static :: $ _scope ; } if ( is_object ( $ template ) ) { return ( static :: $ _configurations [ $ name ] [ ] = $ templa... | Connects a new route and returns the current routes array . This method creates a new Route object and registers it with the Router . The order in which routes are connected matters since the order of precedence is taken into account in parsing and matching operations . |
57,781 | protected static function _prepareParams ( $ url , $ context , array $ options ) { if ( is_string ( $ url ) ) { if ( strpos ( $ url , '://' ) !== false ) { return $ url ; } if ( preg_match ( '%^((#|//)|(mailto|tel|sms|javascript):)%' , $ url ) ) { return $ url ; } if ( is_string ( $ url = static :: _parseString ( $ url... | Prepares URL parameters for matching . Detects and Passes through un - routed URL strings leaving them untouched . |
57,782 | public static function get ( $ route = null , $ scope = null ) { if ( $ route === null && $ scope === null ) { return static :: $ _configurations ; } if ( $ scope === true ) { $ scope = static :: $ _scope ; } if ( $ route === null && $ scope !== null ) { if ( isset ( static :: $ _configurations [ $ scope ] ) ) { return... | Returns one or multiple connected routes . |
57,783 | protected static function _parseString ( $ path , $ context , array $ options = [ ] ) { if ( ! preg_match ( '/^[A-Za-z0-9._\\\\]+::[A-Za-z0-9_]+$/' , $ path ) ) { $ base = rtrim ( $ options [ 'base' ] , '/' ) ; if ( ( ! $ path || $ path [ 0 ] != '/' ) && $ context && isset ( $ context -> controller ) ) { $ formatters =... | Helper function for taking a path string and parsing it into a controller and action array . |
57,784 | public static function attach ( $ name , $ config = null , array $ vars = [ ] ) { if ( $ name === false ) { return null ; } if ( ! isset ( static :: $ _scopes ) ) { static :: _initScopes ( ) ; } if ( $ config === null ) { if ( $ vars && ( $ config = static :: $ _scopes -> get ( $ name ) ) ) { $ config [ 'values' ] = $ ... | Defines a scope and attaches it to a mount point . |
57,785 | protected static function _compileScope ( array $ config ) { $ defaults = [ 'absolute' => false , 'host' => null , 'scheme' => null , 'base' => null , 'prefix' => '' , 'pattern' => '' , 'params' => [ ] ] ; $ config += $ defaults ; $ config [ 'prefix' ] = trim ( $ config [ 'prefix' ] , '/' ) ; $ prefix = '/' . ( $ confi... | Compiles the scope into regular expression patterns for matching against request URLs |
57,786 | protected static function _parseScope ( $ name , $ request ) { $ url = trim ( $ request -> url , '/' ) ; $ url = $ url ? '/' . $ url . '/' : '/' ; if ( ! $ config = static :: attached ( $ name ) ) { return $ url ; } $ scheme = $ request -> scheme . ( $ request -> scheme ? '://' : '//' ) ; $ host = $ request -> host ; i... | Return the unscoped url to route . |
57,787 | public function decrement ( $ key , $ offset = 1 ) { if ( $ this -> _config [ 'scope' ] ) { $ key = "{$this->_config['scope']}_{$key}" ; } if ( ! $ result = $ this -> _read ( $ key ) ) { return false ; } if ( ! $ this -> _write ( $ key , $ result [ 'value' ] -= $ offset , $ result [ 'expiry' ] ) ) { return false ; } re... | Performs a decrement operation on a specified numeric cache item . |
57,788 | protected function _write ( $ key , $ value , $ expires ) { $ path = "{$this->_config['path']}/{$key}" ; if ( ! $ stream = fopen ( $ path , 'wb' ) ) { return false ; } fwrite ( $ stream , "{:expiry:{$expires}}\n" ) ; if ( is_resource ( $ value ) ) { stream_copy_to_stream ( $ value , $ stream ) ; } else { fwrite ( $ str... | Compiles value to format and writes file . |
57,789 | protected function _read ( $ key , $ streams = false ) { $ path = "{$this->_config['path']}/{$key}" ; if ( ! is_file ( $ path ) || ! is_readable ( $ path ) ) { return false ; } if ( ! $ stream = fopen ( $ path , 'rb' ) ) { return false ; } $ header = stream_get_line ( $ stream , static :: MAX_HEADER_LENGTH , "\n" ) ; i... | Reads from file parses its format and returns its expiry and value . |
57,790 | public function describe ( $ entity , $ schema = [ ] , array $ meta = [ ] ) { $ database = $ this -> _config [ 'database' ] ; if ( ! $ this -> _db ) { $ result = $ this -> get ( $ database ) ; if ( isset ( $ result -> db_name ) ) { $ this -> _db = true ; } if ( ! $ this -> _db ) { if ( isset ( $ result -> error ) ) { i... | Describe database create if it does not exist . |
57,791 | public function create ( $ query , array $ options = [ ] ) { $ defaults = [ 'model' => $ query -> model ( ) ] ; $ options += $ defaults ; $ params = compact ( 'query' , 'options' ) ; return Filters :: run ( $ this , __FUNCTION__ , $ params , function ( $ params ) { $ request = [ 'type' => 'json' ] ; $ query = $ params ... | Create new document . |
57,792 | public function read ( $ query , array $ options = [ ] ) { $ defaults = [ 'return' => 'resource' , 'model' => $ query -> model ( ) ] ; $ options += $ defaults ; $ params = compact ( 'query' , 'options' ) ; return Filters :: run ( $ this , __FUNCTION__ , $ params , function ( $ params ) { $ query = $ params [ 'query' ] ... | Read from document . |
57,793 | public function update ( $ query , array $ options = [ ] ) { $ params = compact ( 'query' , 'options' ) ; return Filters :: run ( $ this , __FUNCTION__ , $ params , function ( $ params ) { $ query = $ params [ 'query' ] ; $ options = $ params [ 'options' ] ; $ params = $ query -> export ( $ this ) ; list ( $ _path , $ ... | Update document . |
57,794 | protected function _autoBuild ( $ result ) { $ hasError = ( isset ( $ result [ 'error' ] ) && isset ( $ result [ 'reason' ] ) && $ result [ 'reason' ] === "no_db_file" ) ; if ( $ hasError ) { $ this -> connection -> put ( $ this -> _config [ 'database' ] ) ; return true ; } return false ; } | Helper used for auto building a CouchDB database . |
57,795 | public function delete ( $ query , array $ options = [ ] ) { $ params = compact ( 'query' , 'options' ) ; return Filters :: run ( $ this , __FUNCTION__ , $ params , function ( $ params ) { $ query = $ params [ 'query' ] ; $ params = $ query -> export ( $ this ) ; list ( $ _path , $ conditions ) = $ params [ 'conditions... | Delete document . |
57,796 | public function item ( $ model , array $ data = [ ] , array $ options = [ ] ) { $ defaults = [ 'class' => 'entity' ] ; $ options += $ defaults ; if ( $ options [ 'class' ] === 'entity' ) { return $ model :: create ( $ this -> _format ( $ data ) , $ options ) ; } foreach ( $ data as $ key => $ value ) { if ( isset ( $ v... | Returns a newly - created Document object bound to a model and populated with default data and options . |
57,797 | public function conditions ( $ conditions , $ context ) { $ path = null ; if ( isset ( $ conditions [ 'design' ] ) ) { $ paths = [ 'design' , 'view' ] ; foreach ( $ paths as $ element ) { if ( isset ( $ conditions [ $ element ] ) ) { $ path .= "_{$element}/{$conditions[$element]}/" ; unset ( $ conditions [ $ element ] ... | Handle conditions . |
57,798 | protected function _format ( array $ data ) { foreach ( [ 'id' , 'rev' ] as $ key ) { if ( isset ( $ data [ "_{$key}" ] ) ) { $ data [ $ key ] = $ data [ "_{$key}" ] ; unset ( $ data [ "_{$key}" ] ) ; } } return $ data ; } | Formats a CouchDb result set into a standard result to be passed to item . |
57,799 | public static function translate ( $ id , array $ options = [ ] ) { $ defaults = [ 'count' => 1 , 'locale' => Environment :: get ( 'locale' ) , 'scope' => null , 'context' => null , 'default' => null , 'noop' => false ] ; $ options += $ defaults ; if ( $ options [ 'noop' ] ) { $ result = null ; } else { $ result = stat... | Translates a message according to the current or provided locale and into its correct plural form . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.