1 | <?php |
||
13 | abstract class Specification |
||
14 | { |
||
15 | /** |
||
16 | * @var string |
||
17 | */ |
||
18 | protected $label; |
||
19 | |||
20 | /** |
||
21 | * @return null|string |
||
22 | */ |
||
23 | final public function getLabel(): ?string |
||
27 | |||
28 | /** |
||
29 | * @param null|string $label |
||
30 | * @return Specification |
||
31 | */ |
||
32 | final public function withLabel(?string $label): Specification |
||
38 | |||
39 | /** |
||
40 | * @param $specification |
||
41 | * @param null|string $label |
||
42 | * @return Specification |
||
43 | * @throws \RuntimeException |
||
44 | */ |
||
45 | final public function and($specification, ?string $label = null): Specification |
||
49 | |||
50 | /** |
||
51 | * @param $specification |
||
52 | * @param null|string $label |
||
53 | * @return Specification |
||
54 | * @throws \RuntimeException |
||
55 | */ |
||
56 | final public function or($specification, ?string $label = null): Specification |
||
60 | |||
61 | /** |
||
62 | * @param null|string $label |
||
63 | * @return Specification |
||
64 | */ |
||
65 | final public function negate(?string $label = null): Specification |
||
69 | |||
70 | /** |
||
71 | * @param null|string $label |
||
72 | * @return Specification |
||
73 | */ |
||
74 | final public function asGroup(?string $label = null): Specification |
||
78 | |||
79 | /** |
||
80 | * Validate the specification. |
||
81 | * If the specification is unmet the implementation MUST throw an UnmetSpecificationException. |
||
82 | * |
||
83 | * @throws UnmetSpecificationException |
||
84 | */ |
||
85 | abstract public function validate(): void; |
||
86 | |||
87 | /** |
||
88 | * @return bool |
||
89 | */ |
||
90 | final public function isSatisfied(): bool |
||
99 | |||
100 | /** |
||
101 | * @param $specification |
||
102 | * @param null|string $label |
||
103 | * @return Specification |
||
104 | * @throws \RuntimeException |
||
105 | */ |
||
106 | final public static function factory($specification, ?string $label = null): Specification |
||
119 | } |
||
120 |