vendor/nelmio/api-doc-bundle/src/Attribute/Areas.php line 29

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the NelmioApiDocBundle package.
  4.  *
  5.  * (c) Nelmio
  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 Nelmio\ApiDocBundle\Attribute;
  11. /**
  12.  * @final
  13.  */
  14. #[\Attribute(\Attribute::TARGET_CLASS \Attribute::TARGET_METHOD)]
  15. class Areas
  16. {
  17.     /** @var string[] */
  18.     private array $areas;
  19.     /**
  20.      * @param string[]|array{value: string[]} $properties
  21.      */
  22.     public function __construct(array $properties)
  23.     {
  24.         if (array_key_exists('value'$properties) && is_array($properties['value'])) {
  25.             trigger_deprecation('nelmio/api-doc-bundle''4.36.1''Passing an array with key "value" to "%s" is deprecated, pass the list of strings directly.'__METHOD__);
  26.             $this->areas array_values($properties['value']);
  27.         } else {
  28.             $this->areas = [];
  29.             foreach ($properties as $area) {
  30.                 if (!is_string($area)) {
  31.                     throw new \InvalidArgumentException('An area must be given as a string');
  32.                 }
  33.                 if (!in_array($area$this->areastrue)) {
  34.                     $this->areas[] = $area;
  35.                 }
  36.             }
  37.         }
  38.         if ([] === $this->areas) {
  39.             throw new \InvalidArgumentException('A list of areas was expected');
  40.         }
  41.     }
  42.     public function has(string $area): bool
  43.     {
  44.         return in_array($area$this->areastrue);
  45.     }
  46. }