1 entity.controller.inc protected DefaultEntityController::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

core/modules/entity/entity.controller.inc, line 525
Entity API controller classes and interface.

Class

DefaultEntityController
Defines a base entity controller class.

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;
}