1 | <?php |
||
10 | class MultipleValidationWithAnd implements EmailValidation |
||
11 | { |
||
12 | /** |
||
13 | * If one of validations fails, the remaining validations will be skept. |
||
14 | * This means MultipleErrors will only contain a single error, the first found. |
||
15 | */ |
||
16 | const STOP_ON_ERROR = 0; |
||
17 | |||
18 | /** |
||
19 | * All of validations will be invoked even if one of them got failure. |
||
20 | * So MultipleErrors will contain all causes. |
||
21 | */ |
||
22 | const ALLOW_ALL_ERRORS = 1; |
||
23 | |||
24 | /** |
||
25 | * @var EmailValidation[] |
||
26 | */ |
||
27 | private $validations = []; |
||
28 | |||
29 | /** |
||
30 | * @var array |
||
31 | */ |
||
32 | private $warnings = []; |
||
33 | |||
34 | /** |
||
35 | * @var MultipleErrors|null |
||
36 | */ |
||
37 | private $error; |
||
38 | |||
39 | /** |
||
40 | * @var int |
||
41 | */ |
||
42 | private $mode; |
||
43 | |||
44 | /** |
||
45 | * @param EmailValidation[] $validations The validations. |
||
46 | * @param int $mode The validation mode (one of the constants). |
||
47 | */ |
||
48 | public function __construct(array $validations, $mode = self::ALLOW_ALL_ERRORS) |
||
57 | |||
58 | /** |
||
59 | * {@inheritdoc} |
||
60 | */ |
||
61 | public function isValid($email, EmailLexer $emailLexer) |
||
80 | |||
81 | private function initErrorStorage() |
||
87 | |||
88 | private function processError(EmailValidation $validation) |
||
95 | |||
96 | /** |
||
97 | * @param bool $result |
||
98 | * |
||
99 | * @return bool |
||
100 | */ |
||
101 | private function shouldStop($result) |
||
105 | |||
106 | /** |
||
107 | * Returns the validation errors. |
||
108 | * |
||
109 | */ |
||
110 | public function getError() : ?InvalidEmail |
||
114 | |||
115 | /** |
||
116 | * {@inheritdoc} |
||
117 | */ |
||
118 | public function getWarnings() |
||
122 | } |
||
123 |
Let’s assume that you have a directory layout like this:
and let’s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: