vendor/pimcore/pimcore/lib/Controller/Configuration/ResponseHeader.php line 33

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4.  * Pimcore
  5.  *
  6.  * This source file is available under two different licenses:
  7.  * - GNU General Public License version 3 (GPLv3)
  8.  * - Pimcore Commercial License (PCL)
  9.  * Full copyright and license information is available in
  10.  * LICENSE.md which is distributed with this source code.
  11.  *
  12.  *  @copyright  Copyright (c) Pimcore GmbH (http://www.pimcore.org)
  13.  *  @license    http://www.pimcore.org/license     GPLv3 and PCL
  14.  */
  15. namespace Pimcore\Controller\Configuration;
  16. use Sensio\Bundle\FrameworkExtraBundle\Configuration\ConfigurationAnnotation;
  17. /**
  18.  * Allows to set HTTP headers on the response via annotation/attributes. The annotation/attribute will
  19.  * be processed by ResponseHeaderListener which will set the HTTP headers on the
  20.  * response.
  21.  *
  22.  * See ResponseHeaderBag for documentation on the fields.
  23.  *
  24.  * @Annotation
  25.  *
  26.  * @deprecated use Pimcore\Controller\Attribute\ResponseHeader instead.
  27.  */
  28. class ResponseHeader extends ConfigurationAnnotation
  29. {
  30.     /**
  31.      * @var string
  32.      */
  33.     protected $key;
  34.     /**
  35.      * @var string|array
  36.      */
  37.     protected $values;
  38.     /**
  39.      * @var bool
  40.      */
  41.     protected $replace false;
  42.     /**
  43.      * @param string|array|null $key
  44.      * @param string|array $values
  45.      * @param bool $replace
  46.      */
  47.     public function __construct($key null$values ''$replace false)
  48.     {
  49.         if (is_array($key)) {
  50.             // value is the default key if attribute was called without assignment
  51.             // e.g. #[ResponseHeader("X-Foo")] instead of #[ResponseHeader(key="X-Foo")]
  52.             if (isset($key['value'])) {
  53.                 $key['key'] = $key['value'];
  54.                 unset($key['value']);
  55.             }
  56.             parent::__construct($key);
  57.         } else {
  58.             $this->key $key;
  59.             $this->values $values;
  60.             $this->replace $replace;
  61.         }
  62.         if (empty($this->key)) {
  63.             throw new \InvalidArgumentException('The ResponseHeader Annotation/Attribute needs at least a key to be set');
  64.         }
  65.     }
  66.     /**
  67.      * {@inheritdoc}
  68.      */
  69.     public function getAliasName(): string
  70.     {
  71.         return 'response_header';
  72.     }
  73.     /**
  74.      * {@inheritdoc}
  75.      */
  76.     public function allowArray(): bool
  77.     {
  78.         return true;
  79.     }
  80.     /**
  81.      * @return string
  82.      */
  83.     public function getKey(): string
  84.     {
  85.         return $this->key;
  86.     }
  87.     /**
  88.      * @param string $key
  89.      */
  90.     public function setKey(string $key)
  91.     {
  92.         $this->key $key;
  93.     }
  94.     /**
  95.      * @return array|string
  96.      */
  97.     public function getValues()
  98.     {
  99.         return $this->values;
  100.     }
  101.     /**
  102.      * @param array|string $values
  103.      */
  104.     public function setValues($values)
  105.     {
  106.         $this->values $values;
  107.     }
  108.     /**
  109.      * @return bool
  110.      */
  111.     public function getReplace(): bool
  112.     {
  113.         return $this->replace;
  114.     }
  115.     /**
  116.      * @param bool $replace
  117.      */
  118.     public function setReplace(bool $replace)
  119.     {
  120.         $this->replace $replace;
  121.     }
  122. }