"Fossies" - the Fresh Open Source Software Archive

Member "drupal-8.9.10/core/lib/Drupal/Core/PageCache/ChainRequestPolicy.php" (26 Nov 2020, 1545 Bytes) of package /linux/www/drupal-8.9.10.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "ChainRequestPolicy.php" see the Fossies "Dox" file reference documentation.

    1 <?php
    2 
    3 namespace Drupal\Core\PageCache;
    4 
    5 use Symfony\Component\HttpFoundation\Request;
    6 
    7 /**
    8  * Implements a compound request policy.
    9  *
   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
   12  * rules:
   13  *
   14  * <ol>
   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>
   19  * </ol>
   20  */
   21 class ChainRequestPolicy implements ChainRequestPolicyInterface {
   22 
   23   /**
   24    * A list of policy rules to apply when this policy is evaluated.
   25    *
   26    * @var \Drupal\Core\PageCache\RequestPolicyInterface[]
   27    */
   28   protected $rules = [];
   29 
   30   /**
   31    * {@inheritdoc}
   32    */
   33   public function check(Request $request) {
   34     $final_result = NULL;
   35 
   36     foreach ($this->rules as $rule) {
   37       $result = $rule->check($request);
   38       if ($result === static::DENY) {
   39         return $result;
   40       }
   41       elseif ($result === static::ALLOW) {
   42         $final_result = $result;
   43       }
   44       elseif (isset($result)) {
   45         throw new \UnexpectedValueException('Return value of RequestPolicyInterface::check() must be one of RequestPolicyInterface::ALLOW, RequestPolicyInterface::DENY or NULL');
   46       }
   47     }
   48 
   49     return $final_result;
   50   }
   51 
   52   /**
   53    * {@inheritdoc}
   54    */
   55   public function addPolicy(RequestPolicyInterface $policy) {
   56     $this->rules[] = $policy;
   57     return $this;
   58   }
   59 
   60 }