vendor/friendsofsymfony/http-cache-bundle/src/Configuration/Tag.php line 23

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the FOSHttpCacheBundle package.
  4.  *
  5.  * (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace FOS\HttpCacheBundle\Configuration;
  11. use FOS\HttpCacheBundle\Exception\InvalidTagException;
  12. use Sensio\Bundle\FrameworkExtraBundle\Configuration\ConfigurationAnnotation;
  13. use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
  14. use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
  15. /**
  16.  * @Annotation
  17.  */
  18. #[\Attribute(\Attribute::IS_REPEATABLE \Attribute::TARGET_CLASS \Attribute::TARGET_METHOD)]
  19. class Tag extends ConfigurationAnnotation
  20. {
  21.     private $tags;
  22.     private $expression;
  23.     public function __construct(
  24.         $data = [],
  25.         $expression null
  26.     ) {
  27.         $values = [];
  28.         if (is_string($data)) {
  29.             $values['value'] = $data;
  30.         } else {
  31.             $values $data;
  32.         }
  33.         $values['expression'] = $values['expression'] ?? $expression;
  34.         parent::__construct($values);
  35.     }
  36.     /**
  37.      * Handle tags given without explicit key.
  38.      *
  39.      * @param string|array $data
  40.      */
  41.     public function setValue($data)
  42.     {
  43.         $this->setTags(is_array($data) ? $data : [$data]);
  44.     }
  45.     /**
  46.      * @param mixed $expression
  47.      */
  48.     public function setExpression($expression)
  49.     {
  50.         // @codeCoverageIgnoreStart
  51.         if (!class_exists(ExpressionLanguage::class)) {
  52.             throw new InvalidConfigurationException('@Tag param uses an expression but the ExpressionLanguage is not available.');
  53.         }
  54.         // @codeCoverageIgnoreEnd
  55.         $this->expression $expression;
  56.     }
  57.     /**
  58.      * @return mixed
  59.      */
  60.     public function getExpression()
  61.     {
  62.         return $this->expression;
  63.     }
  64.     public function setTags(array $tags)
  65.     {
  66.         foreach ($tags as $tag) {
  67.             if (false !== \strpos($tag',')) {
  68.                 throw new InvalidTagException($tag',');
  69.             }
  70.         }
  71.         $this->tags $tags;
  72.     }
  73.     public function getTags()
  74.     {
  75.         return $this->tags;
  76.     }
  77.     /**
  78.      * {@inheritdoc}
  79.      */
  80.     public function getAliasName()
  81.     {
  82.         return 'tag';
  83.     }
  84.     /**
  85.      * {@inheritdoc}
  86.      */
  87.     public function allowArray()
  88.     {
  89.         return true;
  90.     }
  91. }