function RulesComponentRepository::getMultiple

Overrides RulesComponentRepositoryInterface::getMultiple

1 call to RulesComponentRepository::getMultiple()
RulesComponentRepository::get in src/Engine/RulesComponentRepository.php
Gets the component for the given ID.

File

src/Engine/RulesComponentRepository.php, line 84

Class

RulesComponentRepository
Provides an implementation of the component repository service.

Namespace

Drupal\rules\Engine

Code

public function getMultiple(array $ids, $provider = 'rules_component') {
    if (!isset($this->resolvers[$provider])) {
        throw new InvalidArgumentException("Invalid component provider {$provider} given.");
    }
    $cids = [];
    foreach ($ids as $id) {
        $cids[$id] = "{$provider}:{$id}:{$this->langcode}";
    }
    $results = array_intersect_key($this->components, array_flip($cids));
    $cids_missing = array_diff_assoc($cids, array_keys($results));
    if ($cids_missing) {
        // Note that the cache backend removes resolved IDs.
        $cache_results = $this->cacheBackend
            ->getMultiple($cids_missing);
        foreach ($cache_results as $cid => $cache_result) {
            $this->components[$cid] = $cache_result->data;
            $results[$cid] = $cache_result->data;
        }
        if ($cids_missing) {
            $resolved_results = $this->resolvers[$provider]
                ->getMultiple(array_keys($cids_missing));
            if ($resolved_results) {
                $cache_items = [];
                foreach ($resolved_results as $id => $component) {
                    $cid = $cids[$id];
                    $this->components[$cid] = $component;
                    $results[$cid] = $component;
                    $cache_items[$cid]['data'] = $component;
                    // Set tags so that we can use invalidateTags later when needed.
                    $cache_items[$cid]['tags'] = [
                        $id,
                    ];
                }
                // Cache entries to speed up future lookups.
                $this->cacheBackend
                    ->setMultiple($cache_items);
            }
        }
    }
    return $results;
}