/
Areas.php
54 lines (45 loc) · 1.29 KB
/
Areas.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?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
*/
#[\Attribute(\Attribute::TARGET_CLASS | \Attribute::TARGET_METHOD)]
final class Areas
{
/** @var string[] */
private array $areas;
/**
* @param string[]|array{value: string[]} $properties
*/
public function __construct(array $properties)
{
if (!array_key_exists('value', $properties) || !is_array($properties['value'])) {
$properties['value'] = array_values($properties);
}
if ([] === $properties['value']) {
throw new \InvalidArgumentException('An array of areas was expected');
}
$areas = [];
foreach ($properties['value'] as $area) {
if (!is_string($area)) {
throw new \InvalidArgumentException('An area must be given as a string');
}
if (!in_array($area, $areas, true)) {
$areas[] = $area;
}
}
$this->areas = $areas;
}
public function has(string $area): bool
{
return in_array($area, $this->areas, true);
}
}