idx
int64
0
60.3k
question
stringlengths
92
4.62k
target
stringlengths
7
635
57,600
final public function _executeMacroOfTemplate ( $ path , PHPTAL $ local_tpl ) { if ( preg_match ( '/^(.*?)\/([a-z0-9_-]*)$/i' , $ path , $ m ) ) { list ( , $ file , $ macroName ) = $ m ; if ( isset ( $ this -> externalMacroTemplatesCache [ $ file ] ) ) { $ tpl = $ this -> externalMacroTemplatesCache [ $ file ] ; } else...
This is PHPTAL s internal function that handles execution of macros from templates .
57,601
private function setCodeFile ( ) { $ this -> findTemplate ( ) ; $ this -> _codeFile = $ this -> getPhpCodeDestination ( ) . $ this -> getFunctionName ( ) . '.' . $ this -> getPhpCodeExtension ( ) ; }
ensure that getCodePath will return up - to - date path
57,602
public function prepare ( ) { $ this -> externalMacroTemplatesCache = array ( ) ; $ this -> setCodeFile ( ) ; if ( ! function_exists ( $ this -> getFunctionName ( ) ) ) { if ( $ this -> getForceReparse ( ) || ! file_exists ( $ this -> getCodePath ( ) ) ) { if ( $ this -> getCachePurgeFrequency ( ) && mt_rand ( ) % $ th...
Prepare template without executing it .
57,603
public function getFunctionName ( ) { if ( ! $ this -> _functionName ) { $ basename = preg_replace ( '/\.[a-z]{3,5}$/' , '' , basename ( $ this -> _source -> getRealPath ( ) ) ) ; $ basename = substr ( trim ( preg_replace ( '/[^a-zA-Z0-9]+/' , '_' , $ basename ) , "_" ) , 0 , 20 ) ; $ hash = md5 ( PHPTAL_VERSION . PHP_...
Returns the generated template function name .
57,604
protected function parse ( ) { $ data = $ this -> _source -> getData ( ) ; $ prefilters = $ this -> getPreFilterInstances ( ) ; foreach ( $ prefilters as $ prefilter ) { $ data = $ prefilter -> filter ( $ data ) ; } $ realpath = $ this -> _source -> getRealPath ( ) ; $ parser = new PHPTAL_Dom_SaxXmlParser ( $ this -> _...
Parse currently set template prefilter and generate PHP code .
57,605
protected function findTemplate ( ) { if ( $ this -> _path == false ) { throw new PHPTAL_ConfigurationException ( 'No template file specified' ) ; } if ( $ this -> _source ) { return ; } if ( ! $ this -> resolvers && ! $ this -> _repositories ) { $ this -> _source = new PHPTAL_FileSource ( $ this -> _path ) ; } else { ...
Search template source location .
57,606
final public static function autoload ( $ class ) { if ( version_compare ( PHP_VERSION , '5.3' , '>=' ) && __NAMESPACE__ ) { $ class = str_replace ( __NAMESPACE__ , 'PHPTAL' , $ class ) ; $ class = strtr ( $ class , '\\' , '_' ) ; } if ( substr ( $ class , 0 , 7 ) !== 'PHPTAL_' ) return ; $ path = dirname ( __FILE__ ) ...
Suitable for callbacks from SPL autoload
57,607
final public static function autoloadRegister ( ) { $ uses_autoload = function_exists ( '__autoload' ) && ( ! ( $ tmp = spl_autoload_functions ( ) ) || ( $ tmp [ 0 ] === '__autoload' ) ) ; if ( version_compare ( PHP_VERSION , '5.3' , '>=' ) ) { spl_autoload_register ( array ( __CLASS__ , 'autoload' ) , false , true ) ;...
Sets up PHPTAL s autoloader .
57,608
public static function handleException ( Exception $ e , $ encoding ) { if ( PHP_SAPI !== 'cli' && ! headers_sent ( ) ) { $ old_exception_handler = set_exception_handler ( array ( new PHPTAL_ExceptionHandler ( $ encoding ) , '_defaultExceptionHandler' ) ) ; if ( $ old_exception_handler !== NULL ) { restore_exception_ha...
PHP s default exception handler allows error pages to be indexed and can reveal too much information so if possible PHPTAL sets up its own handler to fix this .
57,609
public function _defaultExceptionHandler ( $ e ) { if ( ! headers_sent ( ) ) { header ( 'HTTP/1.1 500 PHPTAL Exception' ) ; header ( 'Content-Type:text/html;charset=' . $ this -> encoding ) ; } $ line = $ e -> getFile ( ) ; if ( $ e -> getLine ( ) ) { $ line .= ' line ' . $ e -> getLine ( ) ; } if ( ini_get ( 'display_...
Generates simple error page . Sets appropriate HTTP status to prevent page being indexed .
57,610
private function generateDefault ( PHPTAL_Php_CodeWriter $ codewriter ) { $ this -> phpelement -> generateSurroundHead ( $ codewriter ) ; $ this -> phpelement -> generateHead ( $ codewriter ) ; $ this -> phpelement -> generateContent ( $ codewriter ) ; $ this -> phpelement -> generateFoot ( $ codewriter ) ; $ this -> p...
don t replace - re - generate default content
57,611
function overwriteValueWithVariable ( $ phpVariable ) { $ this -> replacedState = self :: VALUE_REPLACED ; $ this -> phpVariable = $ phpVariable ; $ this -> setPHPCode ( 'echo ' . $ phpVariable ) ; }
generate value of this attribute from variable
57,612
function overwriteFullWithVariable ( $ phpVariable ) { $ this -> replacedState = self :: FULLY_REPLACED ; $ this -> phpVariable = $ phpVariable ; $ this -> setPHPCode ( 'echo ' . $ phpVariable ) ; }
generate complete syntax of this attribute using variable
57,613
function overwriteValueWithCode ( $ code ) { $ this -> replacedState = self :: VALUE_REPLACED ; $ this -> phpVariable = null ; $ this -> setPHPCode ( $ code ) ; }
use any PHP code to generate this attribute s value
57,614
public function setLanguage ( ) { $ langs = func_get_args ( ) ; $ langCode = $ this -> trySettingLanguages ( LC_ALL , $ langs ) ; if ( $ langCode ) return $ langCode ; if ( defined ( "LC_MESSAGES" ) ) { $ langCode = $ this -> trySettingLanguages ( LC_MESSAGES , $ langs ) ; if ( $ langCode ) return $ langCode ; } throw ...
It expects locale names as arguments . Choses first one that works .
57,615
public function translate ( $ key , $ htmlencode = true ) { if ( $ this -> _canonicalize ) $ key = self :: _canonicalizeKey ( $ key ) ; $ value = gettext ( $ key ) ; if ( $ htmlencode ) { $ value = htmlspecialchars ( $ value , ENT_QUOTES , $ this -> _encoding ) ; } while ( preg_match ( '/\${(.*?)\}/sm' , $ value , $ m ...
translate given key .
57,616
private static function _canonicalizeKey ( $ key_ ) { $ result = "" ; $ key_ = trim ( $ key_ ) ; $ key_ = str_replace ( "\n" , "" , $ key_ ) ; $ key_ = str_replace ( "\r" , "" , $ key_ ) ; for ( $ i = 0 ; $ i < strlen ( $ key_ ) ; $ i ++ ) { $ c = $ key_ [ $ i ] ; $ o = ord ( $ c ) ; if ( $ o < 5 || $ o > 127 ) { $ res...
For backwards compatibility only .
57,617
public function setDocType ( $ doctype , $ called_from_macro ) { if ( ! $ this -> _docType ) { $ this -> _docType = $ doctype ; } if ( $ this -> _parentContext ) { $ this -> _parentContext -> setDocType ( $ doctype , $ called_from_macro ) ; } else if ( $ this -> _echoDeclarations ) { if ( ! $ called_from_macro ) { echo...
Set output document type if not already set .
57,618
public function setXmlDeclaration ( $ xmldec , $ called_from_macro ) { if ( ! $ this -> _xmlDeclaration ) { $ this -> _xmlDeclaration = $ xmldec ; } if ( $ this -> _parentContext ) { $ this -> _parentContext -> setXmlDeclaration ( $ xmldec , $ called_from_macro ) ; } else if ( $ this -> _echoDeclarations ) { if ( ! $ c...
Set output document xml declaration .
57,619
public function hasSlot ( $ key ) { return isset ( $ this -> _slots [ $ key ] ) || ( $ this -> _parentContext && $ this -> _parentContext -> hasSlot ( $ key ) ) ; }
Returns true if specified slot is filled .
57,620
public function getSlot ( $ key ) { if ( isset ( $ this -> _slots [ $ key ] ) ) { if ( is_string ( $ this -> _slots [ $ key ] ) ) { return $ this -> _slots [ $ key ] ; } ob_start ( ) ; call_user_func ( $ this -> _slots [ $ key ] [ 0 ] , $ this -> _slots [ $ key ] [ 1 ] , $ this -> _slots [ $ key ] [ 2 ] ) ; return ob_g...
Returns the content of specified filled slot .
57,621
public function echoSlot ( $ key ) { if ( isset ( $ this -> _slots [ $ key ] ) ) { if ( is_string ( $ this -> _slots [ $ key ] ) ) { echo $ this -> _slots [ $ key ] ; } else { call_user_func ( $ this -> _slots [ $ key ] [ 0 ] , $ this -> _slots [ $ key ] [ 1 ] , $ this -> _slots [ $ key ] [ 2 ] ) ; } } else if ( $ this...
Immediately echoes content of specified filled slot .
57,622
public function fillSlot ( $ key , $ content ) { $ this -> _slots [ $ key ] = $ content ; if ( $ this -> _parentContext ) { $ this -> _parentContext -> _slots [ $ key ] = $ content ; } }
Fill a macro slot .
57,623
public function isValidAttributeNS ( $ namespace_uri , $ local_name ) { if ( ! $ this -> isHandledNamespace ( $ namespace_uri ) ) return false ; $ attrs = $ this -> namespaces_by_uri [ $ namespace_uri ] -> getAttributes ( ) ; return isset ( $ attrs [ $ local_name ] ) ; }
Returns true if the attribute is a valid phptal attribute
57,624
public function getNamespaceAttribute ( $ namespace_uri , $ local_name ) { $ attrs = $ this -> namespaces_by_uri [ $ namespace_uri ] -> getAttributes ( ) ; return $ attrs [ $ local_name ] ; }
return objects that holds information about given TAL attribute
57,625
public function registerNamespace ( PHPTAL_Namespace $ ns ) { $ this -> namespaces_by_uri [ $ ns -> getNamespaceURI ( ) ] = $ ns ; $ this -> prefix_to_uri [ $ ns -> getPrefix ( ) ] = $ ns -> getNamespaceURI ( ) ; $ prefix = strtolower ( $ ns -> getPrefix ( ) ) ; foreach ( $ ns -> getAttributes ( ) as $ name => $ attrib...
Register a PHPTAL_Namespace and its attribute into PHPTAL .
57,626
public function onDocumentStart ( ) { $ this -> documentElement = new PHPTAL_Dom_Element ( 'documentElement' , 'http://xml.zope.org/namespaces/tal' , array ( ) , $ this -> getXmlnsState ( ) ) ; $ this -> documentElement -> setSource ( $ this -> file , $ this -> line ) ; $ this -> _current = $ this -> documentElement ; ...
~~~~~ XmlParser implementation ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
57,627
public function getCallback ( $ prefix ) { if ( $ this -> isRegistered ( $ prefix ) && ! $ this -> _callbacks [ $ prefix ] [ 'is_fallback' ] ) { return $ this -> _callbacks [ $ prefix ] [ 'callback' ] ; } if ( $ callback = $ this -> findUnregisteredCallback ( $ prefix ) ) { return $ callback ; } if ( $ this -> isRegist...
get callback for the prefix
57,628
protected function normalizeAttributes ( PHPTAL_Dom_Element $ element ) { parent :: normalizeAttributes ( $ element ) ; $ attrs_by_qname = array ( ) ; foreach ( $ element -> getAttributeNodes ( ) as $ attrnode ) { $ attrs_by_qname [ $ attrnode -> getQualifiedName ( ) ] = $ attrnode ; } if ( count ( $ attrs_by_qname ) >...
Consistent sorting of attributes might give slightly better gzip performance
57,629
private function elementSpecificOptimizations ( PHPTAL_Dom_Element $ element ) { if ( $ element -> getNamespaceURI ( ) !== 'http://www.w3.org/1999/xhtml' && $ element -> getNamespaceURI ( ) !== '' ) { return ; } if ( $ this -> getPHPTAL ( ) -> getOutputMode ( ) !== PHPTAL :: HTML5 ) { return ; } if ( 'meta' === $ eleme...
HTML5 doesn t care about boilerplate
57,630
public function valid ( ) { $ valid = $ this -> valid || $ this -> validOnNext ; $ this -> validOnNext = $ this -> valid ; return $ valid ; }
Tells if the iteration is over
57,631
public function rewind ( ) { $ this -> index = 0 ; $ this -> length = null ; $ this -> end = false ; $ this -> iterator -> rewind ( ) ; if ( $ this -> iterator -> valid ( ) ) { $ this -> validOnNext = true ; $ this -> prefetch ( ) ; } else { $ this -> validOnNext = false ; } if ( $ this -> uses_groups ) { $ this -> gro...
Restarts the iteration process going back to the first element
57,632
public function next ( ) { $ this -> index ++ ; if ( $ this -> validOnNext ) $ this -> prefetch ( ) ; if ( $ this -> uses_groups ) { $ this -> groups -> reset ( ) ; } }
Fetches the next element in the iteration and advances the pointer
57,633
protected function prefetch ( ) { $ this -> valid = true ; $ this -> current = $ this -> iterator -> current ( ) ; $ this -> key = $ this -> iterator -> key ( ) ; $ this -> iterator -> next ( ) ; if ( ! $ this -> iterator -> valid ( ) ) { $ this -> valid = false ; $ this -> end = true ; } }
Fetches the next element from the source data store and updates the end flag if needed .
57,634
public function htmlchars ( $ php ) { if ( preg_match ( '/^\'((?:[^\'{]+|\\\\.)*)\'$/s' , $ php , $ m ) ) { return "'" . htmlspecialchars ( str_replace ( '\\\'' , "'" , $ m [ 1 ] ) , ENT_QUOTES , $ this -> encoding ) . "'" ; } return 'phptal_escape(' . $ php . ', \'' . $ this -> encoding . '\')' ; }
expects PHP code and returns PHP code that will generate escaped string Optimizes case when PHP string is given .
57,635
private static function convertBytesToEntities ( array $ m ) { $ m = $ m [ 1 ] ; $ out = "" ; for ( $ i = 0 ; $ i < strlen ( $ m ) ; $ i ++ ) { $ out .= '&#X' . strtoupper ( dechex ( ord ( $ m [ $ i ] ) ) ) . ';' ; } return $ out ; }
preg callback Changes all bytes to hexadecimal XML entities
57,636
private function sanitizeEscapedText ( $ str ) { $ str = str_replace ( '&apos;' , '&#39;' , $ str ) ; $ types = version_compare ( PHP_VERSION , '5.4.0' ) < 0 ? ( ini_get ( 'short_open_tag' ) ? 'php|=|' : 'php' ) : 'php|=' ; $ str = preg_replace_callback ( "/<\?($types)(.*?)\?>/" , array ( 'self' , 'convertPHPBlockToTAL...
This is where this parser violates XML and refuses to be an annoying bastard .
57,637
public function last ( $ data ) { if ( ! is_array ( $ data ) && ! is_object ( $ data ) && ! is_null ( $ data ) ) { if ( ! isset ( $ this -> cache [ 'L' ] ) ) { $ hash = md5 ( $ data ) ; if ( empty ( $ this -> dict [ 'L' ] ) ) { $ this -> dict [ 'L' ] = $ hash ; $ res = false ; } elseif ( $ this -> dict [ 'L' ] !== $ ha...
Checks if the data passed is the last one in a group
57,638
private function generateFillSlots ( PHPTAL_Php_CodeWriter $ codewriter , PHPTAL_Dom_Node $ phpelement ) { if ( false == ( $ phpelement instanceof PHPTAL_Dom_Element ) ) { return ; } foreach ( self :: $ ALLOWED_ATTRIBUTES as $ qname => $ uri ) { if ( $ phpelement -> hasAttributeNS ( $ uri , $ qname ) ) { $ phpelement -...
recursively generates code for slots
57,639
public function parseExpression ( $ exp ) { $ defineScope = false ; $ defineVar = false ; $ exp = trim ( $ exp ) ; if ( preg_match ( '/^(local|global)\s+(.*?)$/ism' , $ exp , $ m ) ) { list ( , $ defineScope , $ exp ) = $ m ; $ exp = trim ( $ exp ) ; } list ( $ defineVar , $ exp ) = $ this -> parseSetExpression ( $ exp...
Parse the define expression already splitted in sub parts by ; .
57,640
public function process ( ) { $ args = $ this -> getArgs ( ) ; $ map = $ this -> getConfig ( 'map' ) ; foreach ( $ map as $ to => $ from ) { $ args [ $ to ] = isset ( $ args [ $ from ] ) ? $ args [ $ from ] : null ; } $ options = $ this -> getConfig ( 'options' ) ; $ args += $ options ; $ this -> getQuery ( ) -> find (...
Add a condition based on a custom finder .
57,641
public function findSearch ( QueryInterface $ query , array $ options ) { if ( ! isset ( $ options [ 'search' ] ) ) { throw new Exception ( 'Custom finder "search" expects search arguments ' . 'to be nested under key "search" in find() options.' ) ; } $ filters = $ this -> _getFilters ( Hash :: get ( $ options , 'colle...
Callback fired from the controller .
57,642
public function searchManager ( ) { if ( $ this -> _manager === null ) { $ this -> _manager = new Manager ( $ this -> _repository ( ) , $ this -> _collectionClass ) ; } return $ this -> _manager ; }
Returns the search filter manager .
57,643
protected function _extractParams ( $ params , FilterCollectionInterface $ filters ) { $ emptyValues = $ this -> _emptyValues ( ) ; $ nonEmptyParams = Hash :: filter ( $ params , function ( $ val ) use ( $ emptyValues ) { return ! in_array ( $ val , $ emptyValues , true ) ; } ) ; return array_intersect_key ( $ nonEmpty...
Extracts all parameters for which a filter with a matching field name exists .
57,644
protected function _flattenParams ( array $ params , FilterCollectionInterface $ filters ) { $ flattened = [ ] ; foreach ( $ params as $ key => $ value ) { if ( ! is_array ( $ value ) || ( ! empty ( $ filters [ $ key ] ) && $ filters [ $ key ] -> getConfig ( 'flatten' ) === false ) ) { $ flattened [ $ key ] = $ value ;...
Flattens a parameters array so that possible aliased parameter keys that are provided in a nested fashion are being grouped using flat keys .
57,645
protected function _processFilters ( FilterCollectionInterface $ filters , $ params , $ query ) { $ this -> _searchParams = $ params ; $ this -> _isSearch = false ; foreach ( $ filters as $ filter ) { $ filter -> setArgs ( $ params ) ; $ filter -> setQuery ( $ query ) ; if ( $ filter -> skip ( ) ) { continue ; } $ resu...
Processes the given filters .
57,646
public function getFilters ( $ collection = self :: DEFAULT_COLLECTION ) { if ( ! isset ( $ this -> _collections [ $ collection ] ) ) { $ this -> _collections [ $ collection ] = $ this -> _loadCollection ( $ collection ) ; } return $ this -> _collections [ $ collection ] ; }
Gets all filters in a given collection .
57,647
protected function _loadCollection ( $ name ) { if ( $ name === self :: DEFAULT_COLLECTION ) { $ class = $ this -> _collectionClass ; } else { $ class = Inflector :: camelize ( str_replace ( '-' , '_' , $ name ) ) ; } $ className = App :: className ( $ class , 'Model/Filter' , 'Collection' ) ; if ( ! $ className ) { th...
Loads a filter collection .
57,648
protected function _collection ( ) { if ( ! isset ( $ this -> _collections [ $ this -> _collection ] ) ) { $ this -> _collections [ $ this -> _collection ] = new $ this -> _collectionClass ( $ this ) ; } return $ this -> _collections [ $ this -> _collection ] ; }
Get instance for current collection .
57,649
public function add ( $ name , $ filter , array $ options = [ ] ) { $ this -> _collection ( ) -> add ( $ name , $ filter , $ options ) ; return $ this ; }
Adds a new filter to the active collection .
57,650
protected function _aliasColTypes ( $ colTypes ) { $ repository = $ this -> manager ( ) -> getRepository ( ) ; if ( ! method_exists ( $ repository , 'aliasField' ) ) { return $ colTypes ; } $ return = [ ] ; foreach ( $ colTypes as $ field => $ colType ) { $ return [ $ repository -> aliasField ( $ field ) ] = $ colType ...
Alias the column type fields to match the field aliases of the conditions .
57,651
protected function _wildcards ( $ value ) { if ( ! is_string ( $ value ) ) { return false ; } $ value = $ this -> _formatWildcards ( $ value ) ; if ( $ this -> getConfig ( 'before' ) ) { $ value = $ this -> _formatWildcards ( $ this -> getConfig ( 'wildcardAny' ) ) . $ value ; } if ( $ this -> getConfig ( 'after' ) ) {...
Wrap wild cards around the value .
57,652
protected function _setEscaper ( ) { if ( $ this -> getConfig ( 'escaper' ) === null ) { $ query = $ this -> getQuery ( ) ; if ( ! $ query instanceof Query ) { throw new RuntimeException ( '$query must be instance of Cake\ORM\Query to be able to check driver name.' ) ; } $ driver = get_class ( $ query -> getConnection ...
set configuration for escape driver name
57,653
public function field ( ) { $ field = $ this -> getConfig ( 'field' ) ; if ( ! $ this -> getConfig ( 'aliasField' ) ) { return $ field ; } $ repository = $ this -> manager ( ) -> getRepository ( ) ; if ( ! method_exists ( $ repository , 'aliasField' ) ) { return $ field ; } if ( is_string ( $ field ) ) { return $ repos...
Get the database field name .
57,654
public function skip ( ) { return ! $ this -> present ( ) || ( $ this -> filterEmpty ( ) && empty ( $ this -> _args [ $ this -> name ( ) ] ) && ! is_numeric ( $ this -> _args [ $ this -> name ( ) ] ) ) ; }
Checks whether this finder should be skipped .
57,655
public function value ( ) { $ value = $ this -> _config [ 'defaultValue' ] ; $ passedValue = $ this -> passedValue ( ) ; if ( $ passedValue === null ) { return $ value ; } return $ passedValue ; }
Get the value of the name from HTTP GET arguments .
57,656
public function add ( $ name , $ filter , array $ options = [ ] ) { $ this -> _filters [ $ name ] = $ this -> _loadFilter ( $ name , $ filter , $ options ) ; return $ this ; }
Adds filter to the collection .
57,657
protected function _loadFilter ( $ name , $ filter , array $ options = [ ] ) { if ( empty ( $ options [ 'className' ] ) ) { $ class = $ filter ; } else { $ class = $ options [ 'className' ] ; unset ( $ options [ 'className' ] ) ; } $ className = App :: className ( $ class , 'Model/Filter' ) ; if ( ! $ className ) { thr...
Loads a search filter .
57,658
public function initialize ( array $ config ) { parent :: initialize ( $ config ) ; if ( isset ( $ config [ 'emptyValues' ] ) ) { $ this -> setConfig ( 'emptyValues' , $ config [ 'emptyValues' ] , false ) ; } $ collectionClass = $ this -> getConfig ( 'collectionClass' ) ; if ( $ collectionClass ) { $ this -> _collectio...
Overwrite emptyValues config value
57,659
public function startup ( ) { if ( ! $ this -> request -> is ( 'post' ) || ! $ this -> _actionCheck ( ) ) { return null ; } list ( $ url ) = explode ( '?' , $ this -> request -> getRequestTarget ( ) ) ; $ params = $ this -> _filterParams ( ) ; if ( $ params ) { $ url .= '?' . http_build_query ( $ params ) ; } return $ ...
Checks if the current request has posted data and redirects the users to the same action after converting the post data into GET params
57,660
protected function _filterParams ( ) { $ params = Hash :: filter ( ( array ) $ this -> request -> getData ( ) ) ; foreach ( ( array ) $ this -> getConfig ( 'queryStringBlacklist' ) as $ field ) { unset ( $ params [ $ field ] ) ; } foreach ( ( array ) $ this -> getConfig ( 'emptyValues' ) as $ field => $ value ) { if ( ...
Filters the params from POST data and merges in the whitelisted query string ones .
57,661
public function process ( ) { $ ret = call_user_func ( $ this -> getConfig ( 'callback' ) , $ this -> getQuery ( ) , $ this -> getArgs ( ) , $ this ) ; if ( $ ret === null ) { return true ; } return $ ret ; }
Modify query using callback .
57,662
public function resetLink ( $ label , array $ options = [ ] ) { return $ this -> Html -> link ( $ label , $ this -> resetUrl ( ) , $ options ) ; }
Returns a reset link for the search form .
57,663
public function resetUrl ( ) { $ query = $ this -> request -> getQuery ( ) ; $ searchParams = ( array ) $ this -> _View -> get ( '_searchParams' ) ; $ query = array_diff_key ( $ query , $ searchParams ) ; $ additionalBlacklist = ( array ) $ this -> getConfig ( 'additionalBlacklist' ) ; foreach ( $ additionalBlacklist a...
Returns the cleaned URL .
57,664
public function formatWildcards ( $ value ) { $ from = $ to = $ substFrom = $ substTo = [ ] ; if ( $ this -> getConfig ( 'wildcardAny' ) !== '%' ) { $ from [ ] = $ this -> getConfig ( 'fromWildCardAny' ) ; $ to [ ] = $ this -> getConfig ( 'toWildCardAny' ) ; $ substFrom [ ] = $ this -> getConfig ( 'wildcardAny' ) ; $ s...
Replace substitutions with original wildcards but first escape the original wildcards in the text to use them as normal search text
57,665
public function send ( $ message = null , array $ options = [ ] ) { $ defaults = [ 'response' => $ this -> _classes [ 'response' ] ] ; $ options += $ defaults ; if ( $ this -> write ( $ message ) ) { $ config = [ 'message' => $ this -> read ( ) ] + $ this -> _config ; return $ this -> _instance ( $ options [ 'response'...
Aggregates read and write methods into a coherent request response
57,666
public function invokeMethod ( $ method , $ params = [ ] ) { switch ( count ( $ params ) ) { case 0 : return $ this -> { $ method } ( ) ; case 1 : return $ this -> { $ method } ( $ params [ 0 ] ) ; case 2 : return $ this -> { $ method } ( $ params [ 0 ] , $ params [ 1 ] ) ; case 3 : return $ this -> { $ method } ( $ pa...
Calls a method on this object with the given parameters . Provides an OO wrapper for call_user_func_array and improves performance by using straight method calls in most cases .
57,667
protected function _filter ( $ method , $ params , $ callback , $ filters = [ ] ) { $ message = '`' . __METHOD__ . '()` has been deprecated in favor of ' ; $ message .= '`\lithium\aop\Filters::run()` and `::apply()`.' ; trigger_error ( $ message , E_USER_DEPRECATED ) ; list ( , $ method ) = explode ( '::' , $ method ) ...
Executes a set of filters against a method by taking a method s main implementation as a callback and iteratively wrapping the filters around it . This along with the Filters class is the core of Lithium s filters system . This system allows you to reach into an object s methods which are marked as _filterable_ and int...
57,668
public static function write ( $ priority , $ message , array $ options = [ ] ) { $ defaults = [ 'name' => null ] ; $ options += $ defaults ; $ result = true ; if ( isset ( static :: $ _configurations [ $ options [ 'name' ] ] ) ) { $ name = $ options [ 'name' ] ; $ methods = [ $ name => static :: adapter ( $ name ) -> ...
Writes a message to one or more log adapters where the adapters that are written to are the ones that respond to the given priority level .
57,669
protected static function _configsByPriority ( $ priority , $ message , array $ options = [ ] ) { $ configs = [ ] ; $ key = 'priority' ; foreach ( array_keys ( static :: $ _configurations ) as $ name ) { $ config = static :: config ( $ name ) ; $ nameMatch = ( $ config [ $ key ] === true || $ config [ $ key ] === $ pri...
Gets the names of the adapter configurations that respond to a specific priority . The list of adapter configurations returned will be used to write a message with the given priority .
57,670
protected function _init ( ) { parent :: _init ( ) ; $ config = & $ this -> _config ; if ( ! $ config [ 'to' ] ) { $ assoc = preg_replace ( "/\\w+$/" , "" , $ config [ 'from' ] ) . $ config [ 'name' ] ; $ config [ 'to' ] = Libraries :: locate ( 'models' , $ assoc ) ; } elseif ( ! strpos ( $ config [ 'to' ] , '\\' ) ) {...
Initializes the Relationship object by attempting to automatically generate any values that were not provided in the constructor configuration .
57,671
public function data ( $ key = null ) { if ( ! $ key ) { return $ this -> _config ; } return isset ( $ this -> _config [ $ key ] ) ? $ this -> _config [ $ key ] : null ; }
Returns the named configuration item or all configuration data if no parameter is given .
57,672
public function foreignKey ( $ primaryKey ) { $ result = [ ] ; $ entity = $ this -> _classes [ 'entity' ] ; $ keys = ( $ this -> type ( ) === 'belongsTo' ) ? array_flip ( $ this -> key ( ) ) : $ this -> key ( ) ; $ primaryKey = ( $ primaryKey instanceof $ entity ) ? $ primaryKey -> to ( 'array' ) : $ primaryKey ; forea...
Build foreign keys from primary keys array .
57,673
protected function _keys ( $ keys ) { if ( ! $ keys ) { return [ ] ; } $ config = $ this -> _config ; $ hasType = ( $ config [ 'type' ] === 'hasOne' || $ config [ 'type' ] === 'hasMany' ) ; $ related = Libraries :: locate ( 'models' , $ config [ $ hasType ? 'from' : 'to' ] ) ; if ( ! class_exists ( $ related ) ) { thro...
Generates an array of relationship key pairs where the keys are fields on the origin model and values are fields on the lniked model .
57,674
protected function _strategies ( ) { return [ static :: LINK_EMBEDDED => function ( $ object , $ relationship ) { $ fieldName = $ relationship -> fieldName ( ) ; return $ object -> { $ fieldName } ; } , static :: LINK_CONTAINED => function ( $ object , $ relationship ) { $ isArray = ( $ relationship -> type ( ) === "ha...
Strategies used to query related objects indexed by key .
57,675
protected function _init ( ) { parent :: _init ( ) ; $ this -> request = $ this -> _config [ 'request' ] ; if ( ! is_object ( $ this -> request ) || ! $ this -> request -> params ) { return ; } $ default = [ 'command' => null , 'action' => null , 'args' => null ] ; $ params = array_diff_key ( ( array ) $ this -> reques...
Command Initializer .
57,676
protected function _help ( ) { $ help = new Help ( [ 'request' => $ this -> request , 'response' => $ this -> response , 'classes' => $ this -> _classes ] ) ; return $ help -> run ( get_class ( $ this ) ) ; }
Invokes the Help command .
57,677
public function header ( $ text , $ line = null ) { if ( ! $ line ) { $ line = strlen ( $ text ) ; } $ this -> hr ( $ line ) ; $ this -> out ( $ text , 'heading' ) ; $ this -> hr ( $ line ) ; }
Writes a header to the output stream . In addition to the actual text horizontal lines before and afterwards are written . The lines will have the same length as the text . This behavior can be modified by providing the length of lines as a second paramerter .
57,678
public function columns ( $ rows , $ options = [ ] ) { $ defaults = [ 'separator' => "\t" , "error" => false ] ; $ options += $ defaults ; $ lengths = array_reduce ( $ rows , function ( $ columns , $ row ) { foreach ( ( array ) $ row as $ key => $ val ) { if ( ! isset ( $ columns [ $ key ] ) || strlen ( $ val ) > $ col...
Writes rows of columns .
57,679
public function stop ( $ status = 0 , $ message = null ) { if ( $ message ) { ( $ status == 0 ) ? $ this -> out ( $ message ) : $ this -> error ( $ message ) ; } exit ( $ status ) ; }
Stop execution by exiting the script .
57,680
protected function _response ( $ type , $ string , $ options ) { $ defaults = [ 'nl' => 1 , 'style' => null ] ; if ( ! is_array ( $ options ) ) { if ( is_bool ( $ options ) ) { $ options = [ 'nl' => ( integer ) $ options ] ; } elseif ( is_int ( $ options ) ) { $ options = [ 'nl' => $ options ] ; } elseif ( is_string ( ...
Handles the response that is sent to the stream .
57,681
public function render ( ) { $ code = null ; if ( isset ( $ this -> headers [ 'location' ] ) || isset ( $ this -> headers [ 'Location' ] ) ) { if ( $ this -> status [ 'code' ] === 200 ) { $ this -> status ( 302 ) ; } $ code = $ this -> status [ 'code' ] ; } if ( $ cookies = $ this -> _cookies ( ) ) { $ this -> headers ...
Render a response by writing headers and output . Output is echoed in chunks because of an issue where echo time increases exponentially on long message bodies .
57,682
protected function _writeHeaders ( $ headers , $ code = null ) { foreach ( ( array ) $ headers as $ header ) { $ code ? header ( $ header , false , $ code ) : header ( $ header , false ) ; } }
Writes raw headers to output .
57,683
public function is ( $ condition , $ field ) { if ( ! isset ( $ this -> _fields [ $ field ] ) ) { return null ; } return isset ( $ this -> _fields [ $ field ] [ $ condition ] ) && $ this -> _fields [ $ field ] [ $ condition ] ; }
Detects properties of a field i . e . if it supports arrays .
57,684
public static function paths ( $ path = null ) { if ( empty ( $ path ) ) { return static :: $ _paths ; } if ( is_string ( $ path ) ) { return isset ( static :: $ _paths [ $ path ] ) ? static :: $ _paths [ $ path ] : null ; } static :: $ _paths = array_filter ( array_merge ( static :: $ _paths , ( array ) $ path ) ) ; }
Accessor method for the class path templates which Libraries uses to look up and load classes . Using this method you can define your own types of classes or modify the default organization of built - in class types .
57,685
public static function add ( $ name , array $ config = [ ] ) { $ defaults = [ 'name' => $ name , 'path' => null , 'prefix' => $ name . "\\" , 'suffix' => '.php' , 'loader' => null , 'includePath' => false , 'transform' => null , 'bootstrap' => true , 'defer' => false , 'default' => false ] ; if ( $ name === 'lithium' )...
Adds a class library from which files can be loaded .
57,686
protected static function _configure ( $ config ) { if ( $ config [ 'includePath' ] ) { $ path = ( $ config [ 'includePath' ] === true ) ? $ config [ 'path' ] : $ config [ 'includePath' ] ; set_include_path ( get_include_path ( ) . PATH_SEPARATOR . $ path ) ; } if ( $ config [ 'bootstrap' ] === true ) { $ path = "{$con...
Configures the application environment based on a library s settings including appending to the include path loading a bootstrap file and registering a loader with SPL s autoloading system .
57,687
public static function remove ( $ name ) { foreach ( ( array ) $ name as $ library ) { if ( isset ( static :: $ _configurations [ $ library ] ) ) { if ( static :: $ _configurations [ $ library ] [ 'loader' ] ) { spl_autoload_unregister ( static :: $ _configurations [ $ library ] [ 'loader' ] ) ; } unset ( static :: $ _...
Removes a registered library and unregister s the library s autoloader if it has one .
57,688
public static function map ( array $ classes ) { foreach ( $ classes as $ key => $ value ) { unset ( static :: $ _cachedPaths [ $ key ] ) ; } static :: $ _map = array_merge ( static :: $ _map , $ classes ) ; }
Associtates fully - namespaced class names to their corresponding paths on the file system .
57,689
public static function path ( $ class , array $ options = [ ] ) { $ defaults = [ 'dirs' => false ] ; $ options += $ defaults ; $ class = ltrim ( $ class , '\\' ) ; if ( isset ( static :: $ _cachedPaths [ $ class ] ) && ! $ options [ 'dirs' ] ) { return static :: $ _cachedPaths [ $ class ] ; } if ( isset ( static :: $ _...
Get the corresponding physical file path for a class or namespace name .
57,690
protected static function _locateDeferred ( $ defer , $ paths , $ params , array $ options = [ ] ) { $ libraries = static :: $ _configurations ; if ( isset ( $ options [ 'library' ] ) ) { $ libraries = static :: get ( ( array ) $ options [ 'library' ] ) ; } foreach ( $ libraries as $ library => $ config ) { if ( $ conf...
Performs service location lookups by library based on the library s defer flag . Libraries with defer set to true will be searched last when looking up services .
57,691
protected static function _searchPaths ( $ paths , $ library ) { $ result = [ ] ; foreach ( $ paths as $ tpl => $ opts ) { if ( is_int ( $ tpl ) ) { $ tpl = $ opts ; $ opts = [ ] ; } if ( isset ( $ opts [ 'libraries' ] ) && ! in_array ( $ library , ( array ) $ opts [ 'libraries' ] ) ) { continue ; } $ result [ ] = $ tp...
Returns the list of valid search path templates for the given service location lookup .
57,692
protected static function _locateAll ( array $ params , array $ options = [ ] ) { $ defaults = [ 'libraries' => null , 'recursive' => true , 'namespaces' => false ] ; $ options += $ defaults ; $ paths = ( array ) static :: $ _paths [ $ params [ 'type' ] ] ; $ libraries = $ options [ 'library' ] ? $ options [ 'library' ...
Locates all possible classes for given set of parameters .
57,693
protected static function _locatePath ( $ type , $ params ) { if ( ! isset ( static :: $ _paths [ $ type ] ) ) { return null ; } $ params += [ 'app' => LITHIUM_APP_PATH , 'root' => LITHIUM_LIBRARY_PATH ] ; foreach ( static :: $ _paths [ $ type ] as $ path ) { if ( is_dir ( $ path = str_replace ( '\\' , '/' , Text :: in...
Helper function for returning known paths given a certain type .
57,694
protected static function _search ( $ config , $ options , $ name = null ) { $ defaults = [ 'path' => null , 'suffix' => null , 'namespaces' => false , 'recursive' => false , 'preFilter' => '/[A-Z][A-Za-z0-9]+\./' , 'filter' => false , 'exclude' => false , 'format' => function ( $ file , $ config ) { $ trim = [ strlen ...
Search file system .
57,695
protected static function _filter ( $ libs , array $ config , array $ options = [ ] ) { if ( is_callable ( $ options [ 'format' ] ) ) { foreach ( $ libs as $ i => $ file ) { $ libs [ $ i ] = $ options [ 'format' ] ( $ file , $ config ) ; } $ libs = $ options [ 'name' ] ? preg_grep ( "/{$options['name']}$/" , $ libs ) :...
Filters a list of library search results by the given set of options .
57,696
protected static function _params ( $ type , $ name = "*" ) { if ( ! $ name ) { $ name = '*' ; } $ library = $ namespace = $ class = '*' ; if ( strpos ( $ type , '.' ) !== false ) { $ parts = explode ( '.' , $ type ) ; $ type = array_shift ( $ parts ) ; switch ( count ( $ parts ) ) { case 1 : list ( $ class ) = $ parts...
Get params from type .
57,697
public static function applyFilter ( $ method , $ filter = null ) { $ message = '`' . __METHOD__ . '()` has been deprecated in favor of ' ; $ message .= '`\lithium\aop\Filters::apply()` and `::clear()`.' ; trigger_error ( $ message , E_USER_DEPRECATED ) ; $ class = get_called_class ( ) ; if ( $ method === false ) { Fil...
Apply a closure to a method in Libraries .
57,698
public static function check ( array $ values , array $ rules , array $ options = [ ] ) { $ defaults = [ 'notEmpty' , 'message' => null , 'required' => true , 'skipEmpty' => false , 'format' => 'any' , 'on' => null , 'last' => false ] ; $ options += $ defaults ; $ params = compact ( 'values' , 'rules' , 'options' ) ; r...
Checks a set of values against a specified rules list . This method may be used to validate any arbitrary array of data against a set of validation rules .
57,699
public static function rule ( $ rule , $ value , $ format = 'any' , array $ options = [ ] ) { if ( ! isset ( static :: $ _rules [ $ rule ] ) ) { throw new InvalidArgumentException ( "Rule `{$rule}` is not a validation rule." ) ; } $ defaults = isset ( static :: $ _options [ $ rule ] ) ? static :: $ _options [ $ rule ] ...
Checks a single value against a single validation rule in one or more formats .