vendor/sulu/sulu/src/Sulu/Component/Webspace/Analyzer/Attributes/RequestAttributes.php line 17

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of Sulu.
  4.  *
  5.  * (c) Sulu GmbH
  6.  *
  7.  * This source file is subject to the MIT license that is bundled
  8.  * with this source code in the file LICENSE.
  9.  */
  10. namespace Sulu\Component\Webspace\Analyzer\Attributes;
  11. /**
  12.  * Container for request attributes.
  13.  */
  14. class RequestAttributes
  15. {
  16.     /**
  17.      * @var array
  18.      */
  19.     private $attributes;
  20.     public function __construct(array $attributes = [])
  21.     {
  22.         $this->attributes \array_filter($attributes);
  23.     }
  24.     /**
  25.      * Returns attribute with given name.
  26.      *
  27.      * @param string $name
  28.      * @param mixed|null $default
  29.      */
  30.     public function getAttribute($name$default null)
  31.     {
  32.         if (!\array_key_exists($name$this->attributes)) {
  33.             return $default;
  34.         }
  35.         return $this->attributes[$name];
  36.     }
  37.     /**
  38.      * Merges this and the given attributes and returns a new instance.
  39.      *
  40.      * @param RequestAttributes $requestAttributes
  41.      *
  42.      * @return RequestAttributes
  43.      */
  44.     public function merge(self $requestAttributes)
  45.     {
  46.         return new self(\array_merge($requestAttributes->attributes$this->attributes));
  47.     }
  48. }