public CacheContextsManager::convertTokensToKeys(array $context_tokens)
Converts cache context tokens to cache keys.
A cache context token is either:
string[] $context_tokens: An array of cache context tokens.
\Drupal\Core\Cache\Context\ContextCacheKeys The ContextCacheKeys object containing the converted cache keys and cacheability metadata.
public function convertTokensToKeys(array $context_tokens) { assert('$this->assertValidTokens($context_tokens)'); $cacheable_metadata = new CacheableMetadata(); $optimized_tokens = $this->optimizeTokens($context_tokens); // Iterate over cache contexts that have been optimized away and get their // cacheability metadata. foreach (static::parseTokens(array_diff($context_tokens, $optimized_tokens)) as $context_token) { list($context_id, $parameter) = $context_token; $context = $this->getService($context_id); $cacheable_metadata = $cacheable_metadata->merge($context->getCacheableMetadata($parameter)); } sort($optimized_tokens); $keys = []; foreach (array_combine($optimized_tokens, static::parseTokens($optimized_tokens)) as $context_token => $context) { list($context_id, $parameter) = $context; $keys[] = '[' . $context_token . ']=' . $this->getService($context_id)->getContext($parameter); } // Create the returned object and merge in the cacheability metadata. $context_cache_keys = new ContextCacheKeys($keys); return $context_cache_keys->merge($cacheable_metadata); }
© 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/core!lib!Drupal!Core!Cache!Context!CacheContextsManager.php/function/CacheContextsManager::convertTokensToKeys/8.1.x