|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
/* |
|
3
|
|
|
* This file is part of FlexPHP. |
|
4
|
|
|
* |
|
5
|
|
|
* (c) Freddie Gar <[email protected]> |
|
6
|
|
|
* |
|
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
8
|
|
|
* file that was distributed with this source code. |
|
9
|
|
|
*/ |
|
10
|
|
|
namespace FlexPHP\Schema\Validators\Logics; |
|
11
|
|
|
|
|
12
|
|
|
use FlexPHP\Schema\Constants\Action; |
|
13
|
|
|
use FlexPHP\Schema\Exception\InvalidSchemaAttributeException; |
|
14
|
|
|
use FlexPHP\Schema\SchemaAttributeInterface; |
|
15
|
|
|
use FlexPHP\Schema\Validations\ValidationInterface; |
|
16
|
|
|
|
|
17
|
|
|
class ActionLogicValidator implements ValidationInterface |
|
18
|
|
|
{ |
|
19
|
|
|
private const ACTIONS = [ |
|
20
|
|
|
Action::ALL, |
|
21
|
|
|
Action::INDEX, |
|
22
|
|
|
Action::CREATE, |
|
23
|
|
|
Action::READ, |
|
24
|
|
|
Action::UPDATE, |
|
25
|
|
|
Action::DELETE, |
|
26
|
|
|
]; |
|
27
|
|
|
|
|
28
|
|
|
private SchemaAttributeInterface $property; |
|
29
|
|
|
|
|
30
|
182 |
|
public function __construct(SchemaAttributeInterface $property) |
|
31
|
|
|
{ |
|
32
|
182 |
|
$this->property = $property; |
|
33
|
182 |
|
} |
|
34
|
|
|
|
|
35
|
182 |
|
public function validate(): void |
|
36
|
|
|
{ |
|
37
|
182 |
|
if ($this->property->usedIn(Action::ALL) && \count($this->property->show()) > 1) { |
|
38
|
|
|
throw new InvalidSchemaAttributeException('Show constraint miss-configuration: ALL option is exclusive'); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
182 |
|
if ($this->property->usedIn(Action::ALL) && \count($this->property->hide()) > 1) { |
|
42
|
|
|
throw new InvalidSchemaAttributeException('Hide constraint miss-configuration: ALL option is exclusive'); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
182 |
|
\array_map(function (string $action): void { |
|
46
|
182 |
|
if (\in_array($action, $this->property->show()) && \in_array($action, $this->property->hide())) { |
|
47
|
6 |
|
throw new InvalidSchemaAttributeException( |
|
48
|
6 |
|
'Show/Hide constraint miss-configuration: (' . $action . ') option is present in both', |
|
49
|
|
|
); |
|
50
|
|
|
} |
|
51
|
182 |
|
}, self::ACTIONS); |
|
52
|
176 |
|
} |
|
53
|
|
|
} |
|
54
|
|
|
|