function DrupalDefaultEntityController::cacheGet

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.

2 calls to DrupalDefaultEntityController::cacheGet()
DrupalDefaultEntityController::load in includes/entity.inc
Implements DrupalEntityControllerInterface::load().
TaxonomyTermController::cacheGet in modules/taxonomy/taxonomy.module
Gets entities from the static cache.
1 method overrides DrupalDefaultEntityController::cacheGet()
TaxonomyTermController::cacheGet in modules/taxonomy/taxonomy.module
Gets entities from the static cache.

File

includes/entity.inc, line 386

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

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.