Mercurial > hg > isophonics-drupal-site
annotate core/lib/Drupal/Core/PageCache/ChainResponsePolicy.php @ 19:fa3358dc1485 tip
Add ndrum files
author | Chris Cannam |
---|---|
date | Wed, 28 Aug 2019 13:14:47 +0100 |
parents | 4c8ae668cc8c |
children |
rev | line source |
---|---|
Chris@0 | 1 <?php |
Chris@0 | 2 |
Chris@0 | 3 namespace Drupal\Core\PageCache; |
Chris@0 | 4 |
Chris@0 | 5 use Symfony\Component\HttpFoundation\Request; |
Chris@0 | 6 use Symfony\Component\HttpFoundation\Response; |
Chris@0 | 7 |
Chris@0 | 8 /** |
Chris@0 | 9 * Implements a compound response policy. |
Chris@0 | 10 * |
Chris@0 | 11 * When evaluating the compound policy, all of the contained rules are applied |
Chris@0 | 12 * to the response. The overall result is computed according to the following |
Chris@0 | 13 * rules: |
Chris@0 | 14 * |
Chris@0 | 15 * <ol> |
Chris@0 | 16 * <li>Returns static::DENY if any of the rules evaluated to static::DENY</li> |
Chris@0 | 17 * <li>Otherwise returns NULL</li> |
Chris@0 | 18 * </ol> |
Chris@0 | 19 */ |
Chris@0 | 20 class ChainResponsePolicy implements ChainResponsePolicyInterface { |
Chris@0 | 21 |
Chris@0 | 22 /** |
Chris@0 | 23 * A list of policy rules to apply when this policy is checked. |
Chris@0 | 24 * |
Chris@0 | 25 * @var \Drupal\Core\PageCache\ResponsePolicyInterface[] |
Chris@0 | 26 */ |
Chris@0 | 27 protected $rules = []; |
Chris@0 | 28 |
Chris@0 | 29 /** |
Chris@0 | 30 * {@inheritdoc} |
Chris@0 | 31 */ |
Chris@0 | 32 public function check(Response $response, Request $request) { |
Chris@0 | 33 foreach ($this->rules as $rule) { |
Chris@0 | 34 $result = $rule->check($response, $request); |
Chris@0 | 35 if ($result === static::DENY) { |
Chris@0 | 36 return $result; |
Chris@0 | 37 } |
Chris@0 | 38 elseif (isset($result)) { |
Chris@0 | 39 throw new \UnexpectedValueException('Return value of ResponsePolicyInterface::check() must be one of ResponsePolicyInterface::DENY or NULL'); |
Chris@0 | 40 } |
Chris@0 | 41 } |
Chris@0 | 42 } |
Chris@0 | 43 |
Chris@0 | 44 /** |
Chris@0 | 45 * {@inheritdoc} |
Chris@0 | 46 */ |
Chris@0 | 47 public function addPolicy(ResponsePolicyInterface $policy) { |
Chris@0 | 48 $this->rules[] = $policy; |
Chris@0 | 49 return $this; |
Chris@0 | 50 } |
Chris@0 | 51 |
Chris@0 | 52 } |