idx
int64
0
60.3k
question
stringlengths
92
4.62k
target
stringlengths
7
635
25,600
public function increaseMemoryLimit ( $ additionalKb ) { $ limit = ini_get ( 'memory_limit' ) ; if ( ! strlen ( $ limit ) || $ limit === '-1' ) { return ; } $ limit = trim ( $ limit ) ; $ units = strtoupper ( substr ( $ limit , - 1 ) ) ; $ current = ( int ) substr ( $ limit , 0 , strlen ( $ limit ) - 1 ) ; if ( $ units...
Increases the PHP memory_limit ini setting by the specified amount in kilobytes
25,601
protected function _getMessage ( Exception $ exception ) { $ message = $ this -> getMessageForException ( $ exception ) ; $ request = Router :: getRequest ( ) ; if ( $ request ) { $ message .= $ this -> _requestContext ( $ request ) ; } return $ message ; }
Generates a formatted error message
25,602
public static function mapErrorCode ( $ code ) { $ levelMap = [ E_PARSE => 'error' , E_ERROR => 'error' , E_CORE_ERROR => 'error' , E_COMPILE_ERROR => 'error' , E_USER_ERROR => 'error' , E_WARNING => 'warning' , E_USER_WARNING => 'warning' , E_COMPILE_WARNING => 'warning' , E_RECOVERABLE_ERROR => 'warning' , E_NOTICE =...
Map an error code into an Error word and log location .
25,603
protected function _bindValue ( $ value , $ generator , $ type ) { $ placeholder = $ generator -> placeholder ( 'c' ) ; $ generator -> bind ( $ placeholder , $ value , $ type ) ; return $ placeholder ; }
Registers a value in the placeholder generator and returns the generated placeholder
25,604
protected function bootstrap ( ) { $ this -> app -> bootstrap ( ) ; if ( $ this -> app instanceof PluginApplicationInterface ) { $ this -> app -> pluginBootstrap ( ) ; } }
Application bootstrap wrapper .
25,605
public function emit ( ResponseInterface $ response , EmitterInterface $ emitter = null ) { if ( ! $ emitter ) { $ emitter = new ResponseEmitter ( ) ; } $ emitter -> emit ( $ response ) ; }
Emit the response using the PHP SAPI .
25,606
protected function _findUser ( $ username , $ password = null ) { $ result = $ this -> _query ( $ username ) -> first ( ) ; if ( empty ( $ result ) ) { if ( $ password !== null ) { $ hasher = $ this -> passwordHasher ( ) ; $ hasher -> hash ( $ password ) ; } return false ; } $ passwordField = $ this -> _config [ 'field...
Find a user record using the username and password provided .
25,607
public static function load ( $ plugin , array $ config = [ ] ) { deprecationWarning ( 'Plugin::load() is deprecated. ' . 'Use Application::addPlugin() instead. ' . 'This method will be removed in 4.0.0.' ) ; if ( is_array ( $ plugin ) ) { foreach ( $ plugin as $ name => $ conf ) { list ( $ name , $ conf ) = is_numeric...
Loads a plugin and optionally loads bootstrapping routing files or runs an initialization function .
25,608
public static function loadAll ( array $ options = [ ] ) { $ plugins = [ ] ; foreach ( App :: path ( 'Plugin' ) as $ path ) { if ( ! is_dir ( $ path ) ) { continue ; } $ dir = new DirectoryIterator ( $ path ) ; foreach ( $ dir as $ dirPath ) { if ( $ dirPath -> isDir ( ) && ! $ dirPath -> isDot ( ) ) { $ plugins [ ] = ...
Will load all the plugins located in the default plugin folder .
25,609
public static function bootstrap ( $ name ) { deprecationWarning ( 'Plugin::bootstrap() is deprecated. ' . 'This method will be removed in 4.0.0.' ) ; $ plugin = static :: getCollection ( ) -> get ( $ name ) ; if ( ! $ plugin -> isEnabled ( 'bootstrap' ) ) { return false ; } $ plugin -> disable ( 'bootstrap' ) ; return...
Loads the bootstrapping files for a plugin or calls the initialization setup in the configuration
25,610
public static function routes ( $ name = null ) { deprecationWarning ( 'You no longer need to call `Plugin::routes()` after upgrading to use Http\Server. ' . 'See https://book.cakephp.org/3.0/en/development/application.html#adding-the-new-http-stack-to-an-existing-application ' . 'for upgrade information.' ) ; if ( $ n...
Loads the routes file for a plugin or all plugins configured to load their respective routes file .
25,611
public static function loaded ( $ plugin = null ) { if ( $ plugin !== null ) { deprecationWarning ( 'Checking a single plugin with Plugin::loaded() is deprecated. ' . 'Use Plugin::isLoaded() instead.' ) ; return static :: getCollection ( ) -> has ( $ plugin ) ; } $ names = [ ] ; foreach ( static :: getCollection ( ) as...
Return a list of loaded plugins .
25,612
public static function unload ( $ plugin = null ) { deprecationWarning ( 'Plugin::unload() will be removed in 4.0. Use PluginCollection::remove() or clear()' ) ; if ( $ plugin === null ) { static :: getCollection ( ) -> clear ( ) ; } else { static :: getCollection ( ) -> remove ( $ plugin ) ; } }
Forgets a loaded plugin or all of them if first parameter is null
25,613
protected function buildRouteCollection ( ) { if ( Cache :: enabled ( ) && $ this -> cacheConfig !== null ) { return Cache :: remember ( static :: ROUTE_COLLECTION_CACHE_KEY , function ( ) { return $ this -> prepareRouteCollection ( ) ; } , $ this -> cacheConfig ) ; } return $ this -> prepareRouteCollection ( ) ; }
Check if route cache is enabled and use the configured Cache to remember the route collection
25,614
protected function prepareRouteCollection ( ) { $ builder = Router :: createRouteBuilder ( '/' ) ; $ this -> app -> routes ( $ builder ) ; if ( $ this -> app instanceof PluginApplicationInterface ) { $ this -> app -> pluginRoutes ( $ builder ) ; } return Router :: getRouteCollection ( ) ; }
Generate the route collection using the builder
25,615
public function getChildren ( ) { $ property = $ this -> _propertyExtractor ( $ this -> _nestKey ) ; return new static ( $ property ( $ this -> current ( ) ) , $ this -> _nestKey ) ; }
Returns a traversable containing the children for the current item
25,616
public function hasChildren ( ) { $ property = $ this -> _propertyExtractor ( $ this -> _nestKey ) ; $ children = $ property ( $ this -> current ( ) ) ; if ( is_array ( $ children ) ) { return ! empty ( $ children ) ; } return $ children instanceof Traversable ; }
Returns true if there is an array or a traversable object stored under the configured nestKey for the current item
25,617
protected function makePlugin ( $ name , array $ config ) { $ className = $ name ; if ( strpos ( $ className , '\\' ) === false ) { $ className = str_replace ( '/' , '\\' , $ className ) . '\\' . 'Plugin' ; } if ( class_exists ( $ className ) ) { return new $ className ( $ config ) ; } if ( ! isset ( $ config [ 'path' ...
Create a plugin instance from a classname and configuration
25,618
public function addParser ( array $ types , callable $ parser ) { foreach ( $ types as $ type ) { $ type = strtolower ( $ type ) ; $ this -> parsers [ $ type ] = $ parser ; } return $ this ; }
Add a parser .
25,619
protected function decodeXml ( $ body ) { try { $ xml = Xml :: build ( $ body , [ 'return' => 'domdocument' , 'readFile' => false ] ) ; if ( ( int ) $ xml -> childNodes -> length > 0 ) { return Xml :: toArray ( $ xml ) ; } return [ ] ; } catch ( XmlException $ e ) { return [ ] ; } }
Decode XML into an array .
25,620
protected function _rotateFile ( $ filename ) { $ filePath = $ this -> _path . $ filename ; clearstatcache ( true , $ filePath ) ; if ( ! file_exists ( $ filePath ) || filesize ( $ filePath ) < $ this -> _size ) { return null ; } $ rotate = $ this -> _config [ 'rotate' ] ; if ( $ rotate === 0 ) { $ result = unlink ( $ ...
Rotate log file if size specified in config is reached . Also if rotate count is reached oldest file is removed .
25,621
public function contain ( $ associations = [ ] , callable $ queryBuilder = null ) { if ( empty ( $ associations ) ) { deprecationWarning ( 'Using EagerLoader::contain() as getter is deprecated. ' . 'Use getContain() instead.' ) ; return $ this -> getContain ( ) ; } if ( $ queryBuilder ) { if ( ! is_string ( $ associati...
Sets the list of associations that should be eagerly loaded along for a specific table using when a query is provided . The list of associated tables passed to this method must have been previously set as associations using the Table API .
25,622
public function clearContain ( ) { $ this -> _containments = [ ] ; $ this -> _normalized = null ; $ this -> _loadExternal = [ ] ; $ this -> _aliasList = [ ] ; }
Remove any existing non - matching based containments .
25,623
public function normalized ( Table $ repository ) { if ( $ this -> _normalized !== null || empty ( $ this -> _containments ) ) { return ( array ) $ this -> _normalized ; } $ contain = [ ] ; foreach ( $ this -> _containments as $ alias => $ options ) { if ( ! empty ( $ options [ 'instance' ] ) ) { $ contain = ( array ) ...
Returns the fully normalized array of associations that should be eagerly loaded for a table . The normalized array will restructure the original array by sorting all associations under one key and special options under another .
25,624
protected function _reformatContain ( $ associations , $ original ) { $ result = $ original ; foreach ( ( array ) $ associations as $ table => $ options ) { $ pointer = & $ result ; if ( is_int ( $ table ) ) { $ table = $ options ; $ options = [ ] ; } if ( $ options instanceof EagerLoadable ) { $ options = $ options ->...
Formats the containments array so that associations are always set as keys in the array . This function merges the original associations array with the new associations provided
25,625
public function attachAssociations ( Query $ query , Table $ repository , $ includeFields ) { if ( empty ( $ this -> _containments ) && $ this -> _matching === null ) { return ; } $ attachable = $ this -> attachableAssociations ( $ repository ) ; $ processed = [ ] ; do { foreach ( $ attachable as $ alias => $ loadable ...
Modifies the passed query to apply joins or any other transformation required in order to eager load the associations described in the contain array . This method will not modify the query for loading external associations i . e . those that cannot be loaded without executing a separate query .
25,626
public function attachableAssociations ( Table $ repository ) { $ contain = $ this -> normalized ( $ repository ) ; $ matching = $ this -> _matching ? $ this -> _matching -> normalized ( $ repository ) : [ ] ; $ this -> _fixStrategies ( ) ; $ this -> _loadExternal = [ ] ; return $ this -> _resolveJoins ( $ contain , $ ...
Returns an array with the associations that can be fetched using a single query the array keys are the association aliases and the values will contain an array with Cake \ ORM \ EagerLoadable objects .
25,627
public function externalAssociations ( Table $ repository ) { if ( $ this -> _loadExternal ) { return $ this -> _loadExternal ; } $ this -> attachableAssociations ( $ repository ) ; return $ this -> _loadExternal ; }
Returns an array with the associations that need to be fetched using a separate query each array value will contain a Cake \ ORM \ EagerLoadable object .
25,628
protected function _fixStrategies ( ) { foreach ( $ this -> _aliasList as $ aliases ) { foreach ( $ aliases as $ configs ) { if ( count ( $ configs ) < 2 ) { continue ; } foreach ( $ configs as $ loadable ) { if ( strpos ( $ loadable -> aliasPath ( ) , '.' ) ) { $ this -> _correctStrategy ( $ loadable ) ; } } } } }
Iterates over the joinable aliases list and corrects the fetching strategies in order to avoid aliases collision in the generated queries .
25,629
protected function _correctStrategy ( $ loadable ) { $ config = $ loadable -> getConfig ( ) ; $ currentStrategy = isset ( $ config [ 'strategy' ] ) ? $ config [ 'strategy' ] : 'join' ; if ( ! $ loadable -> canBeJoined ( ) || $ currentStrategy !== 'join' ) { return ; } $ config [ 'strategy' ] = Association :: STRATEGY_S...
Changes the association fetching strategy if required because of duplicate under the same direct associations chain
25,630
protected function _resolveJoins ( $ associations , $ matching = [ ] ) { $ result = [ ] ; foreach ( $ matching as $ table => $ loadable ) { $ result [ $ table ] = $ loadable ; $ result += $ this -> _resolveJoins ( $ loadable -> associations ( ) , [ ] ) ; } foreach ( $ associations as $ table => $ loadable ) { $ inMatch...
Helper function used to compile a list of all associations that can be joined in the query .
25,631
public function loadExternal ( $ query , $ statement ) { $ external = $ this -> externalAssociations ( $ query -> getRepository ( ) ) ; if ( empty ( $ external ) ) { return $ statement ; } $ driver = $ query -> getConnection ( ) -> getDriver ( ) ; list ( $ collected , $ statement ) = $ this -> _collectKeys ( $ external...
Decorates the passed statement object in order to inject data from associations that cannot be joined directly .
25,632
public function associationsMap ( $ table ) { $ map = [ ] ; if ( ! $ this -> getMatching ( ) && ! $ this -> getContain ( ) && empty ( $ this -> _joinsMap ) ) { return $ map ; } $ map = $ this -> _buildAssociationsMap ( $ map , $ this -> _matching -> normalized ( $ table ) , true ) ; $ map = $ this -> _buildAssociations...
Returns an array having as keys a dotted path of associations that participate in this eager loader . The values of the array will contain the following keys
25,633
public function addToJoinsMap ( $ alias , Association $ assoc , $ asMatching = false , $ targetProperty = null ) { $ this -> _joinsMap [ $ alias ] = new EagerLoadable ( $ alias , [ 'aliasPath' => $ alias , 'instance' => $ assoc , 'canBeJoined' => true , 'forMatching' => $ asMatching , 'targetProperty' => $ targetProper...
Registers a table alias typically loaded as a join in a query as belonging to an association . This helps hydrators know what to do with the columns coming from such joined table .
25,634
protected function _collectKeys ( $ external , $ query , $ statement ) { $ collectKeys = [ ] ; foreach ( $ external as $ meta ) { $ instance = $ meta -> instance ( ) ; if ( ! $ instance -> requiresKeys ( $ meta -> getConfig ( ) ) ) { continue ; } $ source = $ instance -> getSource ( ) ; $ keys = $ instance -> type ( ) ...
Helper function used to return the keys from the query records that will be used to eagerly load associations .
25,635
public function repository ( RepositoryInterface $ table = null ) { if ( $ table === null ) { deprecationWarning ( 'Using Query::repository() as getter is deprecated. ' . 'Use getRepository() instead.' ) ; return $ this -> getRepository ( ) ; } $ this -> _repository = $ table ; return $ this ; }
Returns the default table object that will be used by this query that is the table that will appear in the from clause .
25,636
public function cache ( $ key , $ config = 'default' ) { if ( $ key === false ) { $ this -> _cache = null ; return $ this ; } $ this -> _cache = new QueryCacher ( $ key , $ config ) ; return $ this ; }
Enable result caching for this query .
25,637
public function eagerLoaded ( $ value = null ) { if ( $ value === null ) { deprecationWarning ( 'Using ' . get_called_class ( ) . '::eagerLoaded() as a getter is deprecated. ' . 'Use isEagerLoaded() instead.' ) ; return $ this -> _eagerLoaded ; } $ this -> _eagerLoaded = $ value ; return $ this ; }
Sets the query instance to be an eager loaded query . If no argument is passed the current configured query _eagerLoaded value is returned .
25,638
public function all ( ) { if ( $ this -> _results !== null ) { return $ this -> _results ; } if ( $ this -> _cache ) { $ results = $ this -> _cache -> fetch ( $ this ) ; } if ( ! isset ( $ results ) ) { $ results = $ this -> _decorateResults ( $ this -> _execute ( ) ) ; if ( $ this -> _cache ) { $ this -> _cache -> sto...
Fetch the results for this query .
25,639
public function mapReduce ( callable $ mapper = null , callable $ reducer = null , $ overwrite = false ) { if ( $ overwrite ) { $ this -> _mapReduce = [ ] ; } if ( $ mapper === null ) { if ( ! $ overwrite ) { deprecationWarning ( 'Using QueryTrait::mapReduce() as a getter is deprecated. ' . 'Use getMapReducers() instea...
Register a new MapReduce routine to be executed on top of the database results Both the mapper and caller callable should be invokable objects .
25,640
public function formatResults ( callable $ formatter = null , $ mode = 0 ) { if ( $ mode === self :: OVERWRITE ) { $ this -> _formatters = [ ] ; } if ( $ formatter === null ) { if ( $ mode !== self :: OVERWRITE ) { deprecationWarning ( 'Using QueryTrait::formatResults() as a getter is deprecated. ' . 'Use getResultForm...
Registers a new formatter callback function that is to be executed when trying to fetch the results from the database .
25,641
public function nice ( $ timezone = null , $ locale = null ) { return $ this -> i18nFormat ( static :: $ niceFormat , $ timezone , $ locale ) ; }
Returns a nicely formatted date string for this object .
25,642
public static function listTimezones ( $ filter = null , $ country = null , $ options = [ ] ) { if ( is_bool ( $ options ) ) { $ options = [ 'group' => $ options , ] ; } $ defaults = [ 'group' => true , 'abbr' => false , 'before' => ' - ' , 'after' => null , ] ; $ options += $ defaults ; $ group = $ options [ 'group' ]...
Get list of timezone identifiers
25,643
public function wasWithinLast ( $ timeInterval ) { $ tmp = trim ( $ timeInterval ) ; if ( is_numeric ( $ tmp ) ) { deprecationWarning ( 'Passing int/numeric string into Time::wasWithinLast() is deprecated. ' . 'Pass strings including interval eg. "6 days"' ) ; $ timeInterval = $ tmp . ' days' ; } return parent :: wasWi...
Returns true this instance will happen within the specified interval
25,644
public function locale ( $ locale = null ) { deprecationWarning ( get_called_class ( ) . '::locale() is deprecated. ' . 'Use setLocale()/getLocale() instead.' ) ; if ( $ locale !== null ) { $ this -> setLocale ( $ locale ) ; } return $ this -> getLocale ( ) ; }
Sets all future finds for the bound table to also fetch translated fields for the passed locale . If no value is passed it returns the currently configured locale
25,645
public function findTranslations ( Query $ query , array $ options ) { $ locales = isset ( $ options [ 'locales' ] ) ? $ options [ 'locales' ] : [ ] ; $ targetAlias = $ this -> _translationTable -> getAlias ( ) ; return $ query -> contain ( [ $ targetAlias => function ( $ query ) use ( $ locales , $ targetAlias ) { if ...
Custom finder method used to retrieve all translations for the found records . Fetched translations can be filtered by locale by passing the locales key in the options array .
25,646
protected function _unsetEmptyFields ( EntityInterface $ entity ) { $ translations = ( array ) $ entity -> get ( '_translations' ) ; foreach ( $ translations as $ locale => $ translation ) { $ fields = $ translation -> extract ( $ this -> _config [ 'fields' ] , false ) ; foreach ( $ fields as $ field => $ value ) { if ...
Unset empty translations to avoid persistence .
25,647
protected function _findExistingTranslations ( $ ruleSet ) { $ association = $ this -> _table -> getAssociation ( $ this -> _translationTable -> getAlias ( ) ) ; $ query = $ association -> find ( ) -> select ( [ 'id' , 'num' => 0 ] ) -> where ( current ( $ ruleSet ) ) -> disableHydration ( ) -> disableBufferedResults (...
Returns the ids found for each of the condition arrays passed for the translations table . Each records is indexed by the corresponding position to the conditions array
25,648
protected function ensureValidKeys ( $ keys ) { if ( ! is_array ( $ keys ) && ! ( $ keys instanceof \ Traversable ) ) { throw new InvalidArgumentException ( 'A cache key set must be either an array or a Traversable.' ) ; } foreach ( $ keys as $ key ) { $ this -> ensureValidKey ( $ key ) ; } }
Ensure the validity of the given cache keys .
25,649
public function get ( $ key , $ default = null ) { $ this -> ensureValidKey ( $ key ) ; $ result = $ this -> innerEngine -> read ( $ key ) ; if ( $ result === false ) { return $ default ; } return $ result ; }
Fetches the value for a given key from the cache .
25,650
public function set ( $ key , $ value , $ ttl = null ) { $ this -> ensureValidKey ( $ key ) ; if ( $ ttl !== null ) { $ restore = $ this -> innerEngine -> getConfig ( 'duration' ) ; $ this -> innerEngine -> setConfig ( 'duration' , $ ttl ) ; } try { $ result = $ this -> innerEngine -> write ( $ key , $ value ) ; return...
Persists data in the cache uniquely referenced by the given key with an optional expiration TTL time .
25,651
public function create ( ) { $ dir = $ this -> Folder -> pwd ( ) ; if ( is_dir ( $ dir ) && is_writable ( $ dir ) && ! $ this -> exists ( ) && touch ( $ this -> path ) ) { return true ; } return false ; }
Creates the file .
25,652
public function read ( $ bytes = false , $ mode = 'rb' , $ force = false ) { if ( $ bytes === false && $ this -> lock === null ) { return file_get_contents ( $ this -> path ) ; } if ( $ this -> open ( $ mode , $ force ) === false ) { return false ; } if ( $ this -> lock !== null && flock ( $ this -> handle , LOCK_SH ) ...
Return the contents of this file as a string .
25,653
public function offset ( $ offset = false , $ seek = SEEK_SET ) { if ( $ offset === false ) { if ( is_resource ( $ this -> handle ) ) { return ftell ( $ this -> handle ) ; } } elseif ( $ this -> open ( ) === true ) { return fseek ( $ this -> handle , $ offset , $ seek ) === 0 ; } return false ; }
Sets or gets the offset for the currently opened file .
25,654
public static function prepare ( $ data , $ forceWindows = false ) { $ lineBreak = "\n" ; if ( DIRECTORY_SEPARATOR === '\\' || $ forceWindows === true ) { $ lineBreak = "\r\n" ; } return strtr ( $ data , [ "\r\n" => $ lineBreak , "\n" => $ lineBreak , "\r" => $ lineBreak ] ) ; }
Prepares an ASCII string for writing . Converts line endings to the correct terminator for the current platform . If Windows \ r \ n will be used all other platforms will use \ n
25,655
public function write ( $ data , $ mode = 'w' , $ force = false ) { $ success = false ; if ( $ this -> open ( $ mode , $ force ) === true ) { if ( $ this -> lock !== null && flock ( $ this -> handle , LOCK_EX ) === false ) { return false ; } if ( fwrite ( $ this -> handle , $ data ) !== false ) { $ success = true ; } i...
Write given data to this file .
25,656
public function md5 ( $ maxsize = 5 ) { if ( $ maxsize === true ) { return md5_file ( $ this -> path ) ; } $ size = $ this -> size ( ) ; if ( $ size && $ size < ( $ maxsize * 1024 ) * 1024 ) { return md5_file ( $ this -> path ) ; } return false ; }
Get md5 Checksum of file with previous check of Filesize
25,657
public function replaceText ( $ search , $ replace ) { if ( ! $ this -> open ( 'r+' ) ) { return false ; } if ( $ this -> lock !== null && flock ( $ this -> handle , LOCK_EX ) === false ) { return false ; } $ replaced = $ this -> write ( str_replace ( $ search , $ replace , $ this -> read ( ) ) , 'w' , true ) ; if ( $ ...
Searches for a given text and replaces the text if found .
25,658
public function beforeSave ( Event $ event , EntityInterface $ entity , $ options ) { if ( isset ( $ options [ 'ignoreCounterCache' ] ) && $ options [ 'ignoreCounterCache' ] === true ) { return ; } foreach ( $ this -> _config as $ assoc => $ settings ) { $ assoc = $ this -> _table -> getAssociation ( $ assoc ) ; foreac...
beforeSave callback .
25,659
public function afterSave ( Event $ event , EntityInterface $ entity , $ options ) { if ( isset ( $ options [ 'ignoreCounterCache' ] ) && $ options [ 'ignoreCounterCache' ] === true ) { return ; } $ this -> _processAssociations ( $ event , $ entity ) ; $ this -> _ignoreDirty = [ ] ; }
afterSave callback .
25,660
public function afterDelete ( Event $ event , EntityInterface $ entity , $ options ) { if ( isset ( $ options [ 'ignoreCounterCache' ] ) && $ options [ 'ignoreCounterCache' ] === true ) { return ; } $ this -> _processAssociations ( $ event , $ entity ) ; }
afterDelete callback .
25,661
protected function _processAssociations ( Event $ event , EntityInterface $ entity ) { foreach ( $ this -> _config as $ assoc => $ settings ) { $ assoc = $ this -> _table -> getAssociation ( $ assoc ) ; $ this -> _processAssociation ( $ event , $ entity , $ assoc , $ settings ) ; } }
Iterate all associations and update counter caches .
25,662
protected function _processAssociation ( Event $ event , EntityInterface $ entity , Association $ assoc , array $ settings ) { $ foreignKeys = ( array ) $ assoc -> getForeignKey ( ) ; $ primaryKeys = ( array ) $ assoc -> getBindingKey ( ) ; $ countConditions = $ entity -> extract ( $ foreignKeys ) ; $ updateConditions ...
Updates counter cache for a single association
25,663
protected function _getCount ( array $ config , array $ conditions ) { $ finder = 'all' ; if ( ! empty ( $ config [ 'finder' ] ) ) { $ finder = $ config [ 'finder' ] ; unset ( $ config [ 'finder' ] ) ; } if ( ! isset ( $ config [ 'conditions' ] ) ) { $ config [ 'conditions' ] = [ ] ; } $ config [ 'conditions' ] = array...
Fetches and returns the count for a single field in an association
25,664
public function selectAllExcept ( $ table , array $ excludedFields , $ overwrite = false ) { if ( $ table instanceof Association ) { $ table = $ table -> getTarget ( ) ; } if ( ! ( $ table instanceof Table ) ) { throw new \ InvalidArgumentException ( 'You must provide either an Association or a Table object' ) ; } $ fi...
All the fields associated with the passed table except the excluded fields will be added to the select clause of the query . Passed excluded fields should not be aliased . After the first call to this method a second call cannot be used to remove fields that have already been added to the query by the first . If you ne...
25,665
public function addDefaultTypes ( Table $ table ) { $ alias = $ table -> getAlias ( ) ; $ map = $ table -> getSchema ( ) -> typeMap ( ) ; $ fields = [ ] ; foreach ( $ map as $ f => $ type ) { $ fields [ $ f ] = $ fields [ $ alias . '.' . $ f ] = $ fields [ $ alias . '__' . $ f ] = $ type ; } $ this -> getTypeMap ( ) ->...
Hints this object to associate the correct types when casting conditions for the database . This is done by extracting the field types from the schema associated to the passed table object . This prevents the user from repeating themselves when specifying conditions .
25,666
public function eagerLoader ( EagerLoader $ instance = null ) { deprecationWarning ( 'Query::eagerLoader() is deprecated. ' . 'Use setEagerLoader()/getEagerLoader() instead.' ) ; if ( $ instance !== null ) { return $ this -> setEagerLoader ( $ instance ) ; } return $ this -> getEagerLoader ( ) ; }
Sets the instance of the eager loader class to use for loading associations and storing containments . If called with no arguments it will return the currently configured instance .
25,667
public function contain ( $ associations = null , $ override = false ) { $ loader = $ this -> getEagerLoader ( ) ; if ( $ override === true ) { $ this -> clearContain ( ) ; } if ( $ associations === null ) { deprecationWarning ( 'Using Query::contain() as getter is deprecated. ' . 'Use getContain() instead.' ) ; return...
Sets the list of associations that should be eagerly loaded along with this query . The list of associated tables passed must have been previously set as associations using the Table API .
25,668
protected function _addAssociationsToTypeMap ( $ table , $ typeMap , $ associations ) { foreach ( $ associations as $ name => $ nested ) { if ( ! $ table -> hasAssociation ( $ name ) ) { continue ; } $ association = $ table -> getAssociation ( $ name ) ; $ target = $ association -> getTarget ( ) ; $ primary = ( array )...
Used to recursively add contained association column types to the query .
25,669
public function matching ( $ assoc , callable $ builder = null ) { $ result = $ this -> getEagerLoader ( ) -> setMatching ( $ assoc , $ builder ) -> getMatching ( ) ; $ this -> _addAssociationsToTypeMap ( $ this -> getRepository ( ) , $ this -> getTypeMap ( ) , $ result ) ; $ this -> _dirty ( ) ; return $ this ; }
Adds filtering conditions to this query to only bring rows that have a relation to another from an associated table based on conditions in the associated table .
25,670
public function leftJoinWith ( $ assoc , callable $ builder = null ) { $ result = $ this -> getEagerLoader ( ) -> setMatching ( $ assoc , $ builder , [ 'joinType' => QueryInterface :: JOIN_TYPE_LEFT , 'fields' => false ] ) -> getMatching ( ) ; $ this -> _addAssociationsToTypeMap ( $ this -> getRepository ( ) , $ this -...
Creates a LEFT JOIN with the passed association table while preserving the foreign key matching and the custom conditions that were originally set for it .
25,671
public function innerJoinWith ( $ assoc , callable $ builder = null ) { $ result = $ this -> getEagerLoader ( ) -> setMatching ( $ assoc , $ builder , [ 'joinType' => QueryInterface :: JOIN_TYPE_INNER , 'fields' => false ] ) -> getMatching ( ) ; $ this -> _addAssociationsToTypeMap ( $ this -> getRepository ( ) , $ this...
Creates an INNER JOIN with the passed association table while preserving the foreign key matching and the custom conditions that were originally set for it .
25,672
public function cleanCopy ( ) { $ clone = clone $ this ; $ clone -> setEagerLoader ( clone $ this -> getEagerLoader ( ) ) ; $ clone -> triggerBeforeFind ( ) ; $ clone -> enableAutoFields ( false ) ; $ clone -> limit ( null ) ; $ clone -> order ( [ ] , true ) ; $ clone -> offset ( null ) ; $ clone -> mapReduce ( null , ...
Creates a copy of this current query triggers beforeFind and resets some state .
25,673
protected function _execute ( ) { $ this -> triggerBeforeFind ( ) ; if ( $ this -> _results ) { $ decorator = $ this -> _decoratorClass ( ) ; return new $ decorator ( $ this -> _results ) ; } $ statement = $ this -> getEagerLoader ( ) -> loadExternal ( $ this , $ this -> execute ( ) ) ; return new ResultSet ( $ this , ...
Executes this query and returns a ResultSet object containing the results . This will also setup the correct statement class in order to eager load deep associations .
25,674
protected function _transformQuery ( ) { if ( ! $ this -> _dirty || $ this -> _type !== 'select' ) { return ; } $ repository = $ this -> getRepository ( ) ; if ( empty ( $ this -> _parts [ 'from' ] ) ) { $ this -> from ( [ $ repository -> getAlias ( ) => $ repository -> getTable ( ) ] ) ; } $ this -> _addDefaultFields ...
Applies some defaults to the query object before it is executed .
25,675
protected function _addDefaultFields ( ) { $ select = $ this -> clause ( 'select' ) ; $ this -> _hasFields = true ; $ repository = $ this -> getRepository ( ) ; if ( ! count ( $ select ) || $ this -> _autoFields === true ) { $ this -> _hasFields = false ; $ this -> select ( $ repository -> getSchema ( ) -> columns ( ) ...
Inspects if there are any set fields for selecting otherwise adds all the fields for the default table .
25,676
protected function _addDefaultSelectTypes ( ) { $ typeMap = $ this -> getTypeMap ( ) -> getDefaults ( ) ; $ select = $ this -> clause ( 'select' ) ; $ types = [ ] ; foreach ( $ select as $ alias => $ value ) { if ( isset ( $ typeMap [ $ alias ] ) ) { $ types [ $ alias ] = $ typeMap [ $ alias ] ; continue ; } if ( is_st...
Sets the default types for converting the fields in the select clause
25,677
public function toDatabase ( $ value , Driver $ driver ) { if ( $ value === null || is_string ( $ value ) ) { return $ value ; } if ( is_object ( $ value ) && method_exists ( $ value , '__toString' ) ) { return $ value -> __toString ( ) ; } if ( is_scalar ( $ value ) ) { return ( string ) $ value ; } throw new InvalidA...
Convert string data into the database format .
25,678
public function add ( $ title , $ url = null , array $ options = [ ] ) { if ( is_array ( $ title ) ) { foreach ( $ title as $ crumb ) { $ this -> crumbs [ ] = $ crumb + [ 'title' => '' , 'url' => null , 'options' => [ ] ] ; } return $ this ; } $ this -> crumbs [ ] = compact ( 'title' , 'url' , 'options' ) ; return $ th...
Add a crumb to the end of the trail .
25,679
public function prepend ( $ title , $ url = null , array $ options = [ ] ) { if ( is_array ( $ title ) ) { $ crumbs = [ ] ; foreach ( $ title as $ crumb ) { $ crumbs [ ] = $ crumb + [ 'title' => '' , 'url' => null , 'options' => [ ] ] ; } array_splice ( $ this -> crumbs , 0 , 0 , $ crumbs ) ; return $ this ; } array_un...
Prepend a crumb to the start of the queue .
25,680
public function insertAt ( $ index , $ title , $ url = null , array $ options = [ ] ) { if ( ! isset ( $ this -> crumbs [ $ index ] ) ) { throw new LogicException ( sprintf ( "No crumb could be found at index '%s'" , $ index ) ) ; } array_splice ( $ this -> crumbs , $ index , 0 , [ compact ( 'title' , 'url' , 'options'...
Insert a crumb at a specific index .
25,681
public function insertBefore ( $ matchingTitle , $ title , $ url = null , array $ options = [ ] ) { $ key = $ this -> findCrumb ( $ matchingTitle ) ; if ( $ key === null ) { throw new LogicException ( sprintf ( "No crumb matching '%s' could be found." , $ matchingTitle ) ) ; } return $ this -> insertAt ( $ key , $ titl...
Insert a crumb before the first matching crumb with the specified title .
25,682
public function render ( array $ attributes = [ ] , array $ separator = [ ] ) { if ( ! $ this -> crumbs ) { return '' ; } $ crumbs = $ this -> crumbs ; $ crumbsCount = count ( $ crumbs ) ; $ templater = $ this -> templater ( ) ; $ separatorString = '' ; if ( $ separator ) { if ( isset ( $ separator [ 'innerAttrs' ] ) )...
Renders the breadcrumbs trail .
25,683
protected function findCrumb ( $ title ) { foreach ( $ this -> crumbs as $ key => $ crumb ) { if ( $ crumb [ 'title' ] === $ title ) { return $ key ; } } return null ; }
Search a crumb in the current stack which title matches the one provided as argument . If found the index of the matching crumb will be returned .
25,684
public function read ( $ id ) { $ result = $ this -> _table -> find ( 'all' ) -> select ( [ 'data' ] ) -> where ( [ $ this -> _table -> getPrimaryKey ( ) => $ id ] ) -> disableHydration ( ) -> first ( ) ; if ( empty ( $ result ) ) { return '' ; } if ( is_string ( $ result [ 'data' ] ) ) { return $ result [ 'data' ] ; }...
Method used to read from a database session .
25,685
public function write ( $ id , $ data ) { if ( ! $ id ) { return false ; } $ expires = time ( ) + $ this -> _timeout ; $ record = compact ( 'data' , 'expires' ) ; $ record [ $ this -> _table -> getPrimaryKey ( ) ] = $ id ; $ result = $ this -> _table -> save ( new Entity ( $ record ) ) ; return ( bool ) $ result ; }
Helper function called on write for database sessions .
25,686
public function destroy ( $ id ) { $ this -> _table -> delete ( new Entity ( [ $ this -> _table -> getPrimaryKey ( ) => $ id ] , [ 'markNew' => false ] ) ) ; return true ; }
Method called on the destruction of a database session .
25,687
public function dispatch ( ServerRequest $ request , Response $ response ) { if ( Router :: getRequest ( true ) !== $ request ) { Router :: pushRequest ( $ request ) ; } $ beforeEvent = $ this -> dispatchEvent ( 'Dispatcher.beforeDispatch' , compact ( 'request' , 'response' ) ) ; $ request = $ beforeEvent -> getData ( ...
Dispatches a Request & Response
25,688
protected function _invoke ( Controller $ controller ) { $ this -> dispatchEvent ( 'Dispatcher.invokeController' , [ 'controller' => $ controller ] ) ; $ result = $ controller -> startupProcess ( ) ; if ( $ result instanceof Response ) { return $ result ; } $ response = $ controller -> invokeAction ( ) ; if ( $ respons...
Invoke a controller s action and wrapping methods .
25,689
public function addFilter ( EventListenerInterface $ filter ) { deprecationWarning ( 'ActionDispatcher::addFilter() is deprecated. ' . 'This is only available for backwards compatibility with DispatchFilters' ) ; $ this -> filters [ ] = $ filter ; $ this -> getEventManager ( ) -> on ( $ filter ) ; }
Add a filter to this dispatcher .
25,690
public function compile ( Query $ query , ValueBinder $ generator ) { $ sql = '' ; $ type = $ query -> type ( ) ; $ query -> traverse ( $ this -> _sqlCompiler ( $ sql , $ query , $ generator ) , $ this -> { '_' . $ type . 'Parts' } ) ; if ( $ query -> getValueBinder ( ) !== $ generator ) { foreach ( $ query -> getValue...
Returns the SQL representation of the provided query after generating the placeholders for the bound values using the provided generator
25,691
protected function _sqlCompiler ( & $ sql , $ query , $ generator ) { return function ( $ parts , $ name ) use ( & $ sql , $ query , $ generator ) { if ( ! isset ( $ parts ) || ( ( is_array ( $ parts ) || $ parts instanceof \ Countable ) && ! count ( $ parts ) ) ) { return ; } if ( $ parts instanceof ExpressionInterfac...
Returns a callable object that can be used to compile a SQL string representation of this query .
25,692
protected function _buildSelectPart ( $ parts , $ query , $ generator ) { $ driver = $ query -> getConnection ( ) -> getDriver ( ) ; $ select = 'SELECT%s %s%s' ; if ( $ this -> _orderedUnion && $ query -> clause ( 'union' ) ) { $ select = '(SELECT%s %s%s' ; } $ distinct = $ query -> clause ( 'distinct' ) ; $ modifiers ...
Helper function used to build the string representation of a SELECT clause it constructs the field list taking care of aliasing and converting expression objects to string . This function also constructs the DISTINCT clause for the query .
25,693
protected function _buildFromPart ( $ parts , $ query , $ generator ) { $ select = ' FROM %s' ; $ normalized = [ ] ; $ parts = $ this -> _stringifyExpressions ( $ parts , $ generator ) ; foreach ( $ parts as $ k => $ p ) { if ( ! is_numeric ( $ k ) ) { $ p = $ p . ' ' . $ k ; } $ normalized [ ] = $ p ; } return sprintf...
Helper function used to build the string representation of a FROM clause it constructs the tables list taking care of aliasing and converting expression objects to string .
25,694
protected function _buildJoinPart ( $ parts , $ query , $ generator ) { $ joins = '' ; foreach ( $ parts as $ join ) { $ subquery = $ join [ 'table' ] instanceof Query || $ join [ 'table' ] instanceof QueryExpression ; if ( $ join [ 'table' ] instanceof ExpressionInterface ) { $ join [ 'table' ] = $ join [ 'table' ] ->...
Helper function used to build the string representation of multiple JOIN clauses it constructs the joins list taking care of aliasing and converting expression objects to string in both the table to be joined and the conditions to be used .
25,695
protected function _buildSetPart ( $ parts , $ query , $ generator ) { $ set = [ ] ; foreach ( $ parts as $ part ) { if ( $ part instanceof ExpressionInterface ) { $ part = $ part -> sql ( $ generator ) ; } if ( $ part [ 0 ] === '(' ) { $ part = substr ( $ part , 1 , - 1 ) ; } $ set [ ] = $ part ; } return ' SET ' . im...
Helper function to generate SQL for SET expressions .
25,696
protected function _buildUnionPart ( $ parts , $ query , $ generator ) { $ parts = array_map ( function ( $ p ) use ( $ generator ) { $ p [ 'query' ] = $ p [ 'query' ] -> sql ( $ generator ) ; $ p [ 'query' ] = $ p [ 'query' ] [ 0 ] === '(' ? trim ( $ p [ 'query' ] , '()' ) : $ p [ 'query' ] ; $ prefix = $ p [ 'all' ] ...
Builds the SQL string for all the UNION clauses in this query when dealing with query objects it will also transform them using their configured SQL dialect .
25,697
protected function _buildUpdatePart ( $ parts , $ query , $ generator ) { $ table = $ this -> _stringifyExpressions ( $ parts , $ generator ) ; $ modifiers = $ this -> _buildModifierPart ( $ query -> clause ( 'modifier' ) , $ query , $ generator ) ; return sprintf ( 'UPDATE%s %s' , $ modifiers , implode ( ',' , $ table...
Builds the SQL fragment for UPDATE .
25,698
protected function _buildModifierPart ( $ parts , $ query , $ generator ) { if ( $ parts === [ ] ) { return '' ; } return ' ' . implode ( ' ' , $ this -> _stringifyExpressions ( $ parts , $ generator , false ) ) ; }
Builds the SQL modifier fragment
25,699
protected function _stringifyExpressions ( $ expressions , $ generator , $ wrap = true ) { $ result = [ ] ; foreach ( $ expressions as $ k => $ expression ) { if ( $ expression instanceof ExpressionInterface ) { $ value = $ expression -> sql ( $ generator ) ; $ expression = $ wrap ? '(' . $ value . ')' : $ value ; } $ ...
Helper function used to covert ExpressionInterface objects inside an array into their string representation .