function CacheContextsManager::assertValidTokens

Same name in other branches
  1. 8.9.x core/lib/Drupal/Core/Cache/Context/CacheContextsManager.php \Drupal\Core\Cache\Context\CacheContextsManager::assertValidTokens()
  2. 10 core/lib/Drupal/Core/Cache/Context/CacheContextsManager.php \Drupal\Core\Cache\Context\CacheContextsManager::assertValidTokens()
  3. 11.x core/lib/Drupal/Core/Cache/Context/CacheContextsManager.php \Drupal\Core\Cache\Context\CacheContextsManager::assertValidTokens()

Asserts the context tokens are valid.

Similar to ::validateTokens, this method returns boolean TRUE when the context tokens are valid, and FALSE when they are not instead of returning NULL when they are valid and throwing a \LogicException when they are not. This function should be used with the assert() statement.

Parameters

mixed $context_tokens: Variable to be examined - should be array of context_tokens.

Return value

bool TRUE if context_tokens is an array of valid tokens.

1 call to CacheContextsManager::assertValidTokens()
CacheContextsManager::convertTokensToKeys in core/lib/Drupal/Core/Cache/Context/CacheContextsManager.php
Converts cache context tokens to cache keys.

File

core/lib/Drupal/Core/Cache/Context/CacheContextsManager.php, line 315

Class

CacheContextsManager
Converts cache context tokens into cache keys.

Namespace

Drupal\Core\Cache\Context

Code

public function assertValidTokens($context_tokens) {
    if (!is_array($context_tokens)) {
        return FALSE;
    }
    try {
        $this->validateTokens($context_tokens);
    } catch (\LogicException $e) {
        return FALSE;
    }
    return TRUE;
}

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