2019-01-05 16:37:43 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This file is part of the NelmioApiDocBundle package.
|
|
|
|
*
|
|
|
|
* (c) Nelmio
|
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Nelmio\ApiDocBundle\Annotation;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Annotation
|
|
|
|
*/
|
2021-12-21 17:16:14 +02:00
|
|
|
#[\Attribute(\Attribute::TARGET_METHOD)]
|
2019-01-05 16:37:43 +01:00
|
|
|
final class Areas
|
|
|
|
{
|
|
|
|
/** @var string[] */
|
|
|
|
private $areas;
|
|
|
|
|
|
|
|
public function __construct(array $properties)
|
|
|
|
{
|
2022-01-28 07:37:28 -08:00
|
|
|
if (!array_key_exists('value', $properties) || !is_array($properties['value'])) {
|
2022-01-28 07:40:09 -08:00
|
|
|
$properties['value'] = array_values($properties);
|
2022-01-28 07:37:28 -08:00
|
|
|
}
|
|
|
|
|
2022-02-02 08:47:26 -08:00
|
|
|
if ([] === $properties['value']) {
|
2019-01-05 16:37:43 +01:00
|
|
|
throw new \InvalidArgumentException('An array of areas was expected');
|
|
|
|
}
|
|
|
|
|
|
|
|
$areas = [];
|
2022-01-28 07:37:28 -08:00
|
|
|
foreach ($properties['value'] as $area) {
|
2019-01-05 16:37:43 +01:00
|
|
|
if (!is_string($area)) {
|
|
|
|
throw new \InvalidArgumentException('An area must be given as a string');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!in_array($area, $areas)) {
|
|
|
|
$areas[] = $area;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (0 === count($areas)) {
|
|
|
|
throw new \LogicException('At least one area is expected');
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->areas = $areas;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function has(string $area): bool
|
|
|
|
{
|
|
|
|
return in_array($area, $this->areas, true);
|
|
|
|
}
|
|
|
|
}
|