protected function DrupalDefaultEntityController::cacheGet
protected DrupalDefaultEntityController::cacheGet($ids, $conditions = array())
Gets entities from the static cache.
Parameters
$ids: If not empty, return entities that match these IDs.
$conditions: If set, return entities that match all of these conditions.
Return value
Array of entities from the entity cache.
File
- includes/entity.inc, line 383
Class
- DrupalDefaultEntityController
- Default implementation of DrupalEntityControllerInterface.
Code
protected function cacheGet($ids, $conditions = array()) { $entities = array(); // Load any available entities from the internal cache. if (!empty($this->entityCache)) { if ($ids) { $entities += array_intersect_key($this->entityCache, array_flip($ids)); } // If loading entities only by conditions, fetch all available entities // from the cache. Entities which don't match are removed later. elseif ($conditions) { $entities = $this->entityCache; } } // Exclude any entities loaded from cache if they don't match $conditions. // This ensures the same behavior whether loading from memory or database. if ($conditions) { foreach ($entities as $entity) { // Iterate over all conditions and compare them to the entity // properties. We cannot use array_diff_assoc() here since the // conditions can be nested arrays, too. foreach ($conditions as $property_name => $condition) { if (is_array($condition)) { // Multiple condition values for one property are treated as OR // operation: only if the value is not at all in the condition array // we remove the entity. if (!in_array($entity->{$property_name}, $condition)) { unset($entities[$entity->{$this->idKey}]); continue 2; } } elseif ($condition != $entity->{$property_name}) { unset($entities[$entity->{$this->idKey}]); continue 2; } } } } return $entities; }
© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/includes!entity.inc/function/DrupalDefaultEntityController::cacheGet/7.x