3 namespace Drupal\Core\PageCache;
5 use Symfony\Component\HttpFoundation\Request;
8 * Implements a compound request policy.
10 * When evaluating the compound policy, all of the contained rules are applied
11 * to the request. The overall result is computed according to the following
15 * <li>Returns static::DENY if any of the rules evaluated to static::DENY</li>
16 * <li>Returns static::ALLOW if at least one of the rules evaluated to
17 * static::ALLOW and none to static::DENY</li>
18 * <li>Otherwise returns NULL</li>
21 class ChainRequestPolicy implements ChainRequestPolicyInterface {
24 * A list of policy rules to apply when this policy is evaluated.
26 * @var \Drupal\Core\PageCache\RequestPolicyInterface[]
28 protected $rules = [];
33 public function check(Request $request) {
36 foreach ($this->rules as $rule) {
37 $result = $rule->check($request);
38 if ($result === static::DENY) {
41 elseif ($result === static::ALLOW) {
42 $final_result = $result;
44 elseif (isset($result)) {
45 throw new \UnexpectedValueException('Return value of RequestPolicyInterface::check() must be one of RequestPolicyInterface::ALLOW, RequestPolicyInterface::DENY or NULL');
55 public function addPolicy(RequestPolicyInterface $policy) {
56 $this->rules[] = $policy;