comparison core/lib/Drupal/Core/PageCache/ChainResponsePolicy.php @ 0:4c8ae668cc8c

Initial import (non-working)
author Chris Cannam
date Wed, 29 Nov 2017 16:09:58 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:4c8ae668cc8c
1 <?php
2
3 namespace Drupal\Core\PageCache;
4
5 use Symfony\Component\HttpFoundation\Request;
6 use Symfony\Component\HttpFoundation\Response;
7
8 /**
9 * Implements a compound response policy.
10 *
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
13 * rules:
14 *
15 * <ol>
16 * <li>Returns static::DENY if any of the rules evaluated to static::DENY</li>
17 * <li>Otherwise returns NULL</li>
18 * </ol>
19 */
20 class ChainResponsePolicy implements ChainResponsePolicyInterface {
21
22 /**
23 * A list of policy rules to apply when this policy is checked.
24 *
25 * @var \Drupal\Core\PageCache\ResponsePolicyInterface[]
26 */
27 protected $rules = [];
28
29 /**
30 * {@inheritdoc}
31 */
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) {
36 return $result;
37 }
38 elseif (isset($result)) {
39 throw new \UnexpectedValueException('Return value of ResponsePolicyInterface::check() must be one of ResponsePolicyInterface::DENY or NULL');
40 }
41 }
42 }
43
44 /**
45 * {@inheritdoc}
46 */
47 public function addPolicy(ResponsePolicyInterface $policy) {
48 $this->rules[] = $policy;
49 return $this;
50 }
51
52 }