You are here

public function CacheContextsManager::assertValidTokens in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 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.

File

core/lib/Drupal/Core/Cache/Context/CacheContextsManager.php, line 314
Contains \Drupal\Core\Cache\Context\CacheContextsManager.

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