1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | namespace JMS\Serializer\Annotation; |
||
6 | |||
7 | use JMS\Serializer\Exception\RuntimeException; |
||
8 | |||
9 | /** |
||
10 | * @Annotation |
||
11 | * @Target("CLASS") |
||
12 | */ |
||
13 | #[\Attribute(\Attribute::TARGET_CLASS)] |
||
14 | final class ExclusionPolicy implements SerializerAttribute |
||
15 | { |
||
16 | use AnnotationUtilsTrait; |
||
17 | |||
18 | public const NONE = 'NONE'; |
||
19 | public const ALL = 'ALL'; |
||
20 | 25 | ||
21 | /** |
||
22 | 25 | * @var string|null |
|
23 | */ |
||
24 | public $policy = 'NONE'; |
||
25 | |||
26 | 25 | public function __construct($values = [], ?string $policy = null) |
|
27 | { |
||
28 | 25 | $this->loadAnnotationParameters(get_defined_vars()); |
|
29 | |||
30 | $this->policy = strtoupper($this->policy); |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
31 | 25 | ||
32 | if (self::NONE !== $this->policy && self::ALL !== $this->policy) { |
||
33 | throw new RuntimeException('Exclusion policy must either be "ALL", or "NONE".'); |
||
34 | } |
||
35 | } |
||
36 | } |
||
37 |