You are here

public function ChainResponsePolicy::check in Drupal 10

Same name in this branch
  1. 10 core/lib/Drupal/Core/PageCache/ChainResponsePolicy.php \Drupal\Core\PageCache\ChainResponsePolicy::check()
  2. 10 core/lib/Drupal/Core/ProxyClass/PageCache/ChainResponsePolicy.php \Drupal\Core\ProxyClass\PageCache\ChainResponsePolicy::check()
Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/PageCache/ChainResponsePolicy.php \Drupal\Core\PageCache\ChainResponsePolicy::check()
  2. 9 core/lib/Drupal/Core/PageCache/ChainResponsePolicy.php \Drupal\Core\PageCache\ChainResponsePolicy::check()

Determines whether it is save to store a page in the cache.

Parameters

\Symfony\Component\HttpFoundation\Response $response: The response which is about to be sent to the client.

\Symfony\Component\HttpFoundation\Request $request: The request object.

Return value

string|null Either static::DENY or NULL. Calling code may attempt to store a page in the cache unless static::DENY is returned. Returns NULL if the policy policy is not specified for the given response.

Overrides ResponsePolicyInterface::check

File

core/lib/Drupal/Core/PageCache/ChainResponsePolicy.php, line 32

Class

ChainResponsePolicy
Implements a compound response policy.

Namespace

Drupal\Core\PageCache

Code

public function check(Response $response, Request $request) {
  foreach ($this->rules as $rule) {
    $result = $rule
      ->check($response, $request);
    if ($result === static::DENY) {
      return $result;
    }
    elseif (isset($result)) {
      throw new \UnexpectedValueException('Return value of ResponsePolicyInterface::check() must be one of ResponsePolicyInterface::DENY or NULL');
    }
  }
}