3 namespace Drupal\Core\PageCache;
5 use Symfony\Component\HttpFoundation\Request;
6 use Symfony\Component\HttpFoundation\Response;
9 * Implements a compound response policy.
11 * When evaluating the compound policy, all of the contained rules are applied
12 * to the response. The overall result is computed according to the following
16 * <li>Returns static::DENY if any of the rules evaluated to static::DENY</li>
17 * <li>Otherwise returns NULL</li>
20 class ChainResponsePolicy implements ChainResponsePolicyInterface {
23 * A list of policy rules to apply when this policy is checked.
25 * @var \Drupal\Core\PageCache\ResponsePolicyInterface[]
27 protected $rules = [];
32 public function check(Response $response, Request $request) {
33 foreach ($this->rules as $rule) {
34 $result = $rule->check($response, $request);
35 if ($result === static::DENY) {
38 elseif (isset($result)) {
39 throw new \UnexpectedValueException('Return value of ResponsePolicyInterface::check() must be one of ResponsePolicyInterface::DENY or NULL');
47 public function addPolicy(ResponsePolicyInterface $policy) {
48 $this->rules[] = $policy;