|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
|
|
6
|
|
|
namespace AlgoWeb\ODataMetadata\Edm\Validation\Internal\InterfaceValidator; |
|
7
|
|
|
|
|
8
|
|
|
use AlgoWeb\ODataMetadata\Edm\Validation\Internal\InterfaceValidator; |
|
9
|
|
|
use AlgoWeb\ODataMetadata\Enums\SchemaElementKind; |
|
10
|
|
|
use AlgoWeb\ODataMetadata\Interfaces\IEntityContainer; |
|
11
|
|
|
use AlgoWeb\ODataMetadata\Interfaces\IFunction; |
|
12
|
|
|
use AlgoWeb\ODataMetadata\Interfaces\ISchemaElement; |
|
13
|
|
|
use AlgoWeb\ODataMetadata\Interfaces\ISchemaType; |
|
14
|
|
|
use AlgoWeb\ODataMetadata\Interfaces\IValueTerm; |
|
15
|
|
|
|
|
16
|
|
|
final class VisitorOfISchemaElement extends VisitorOfT |
|
17
|
|
|
{ |
|
18
|
|
|
protected $lookup = []; |
|
19
|
|
|
|
|
20
|
|
|
public function __construct() |
|
21
|
|
|
{ |
|
22
|
|
|
$this->lookup[SchemaElementKind::TypeDefinition()->getKey()] = ISchemaType::class; |
|
23
|
|
|
$this->lookup[SchemaElementKind::Function()->getKey()] = IFunction::class; |
|
24
|
|
|
$this->lookup[SchemaElementKind::ValueTerm()->getKey()] = IValueTerm::class; |
|
25
|
|
|
$this->lookup[SchemaElementKind::EntityContainer()->getKey()] = IEntityContainer::class; |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
protected function VisitT($item, array &$followup, array &$references): iterable |
|
29
|
|
|
{ |
|
30
|
|
|
assert($item instanceof ISchemaElement); |
|
31
|
|
|
$errors = []; |
|
32
|
|
|
|
|
33
|
|
|
if (null === $item->getNamespace()) { |
|
34
|
|
|
InterfaceValidator::CollectErrors( |
|
35
|
|
|
InterfaceValidator::CreatePropertyMustNotBeNullError( |
|
36
|
|
|
$item, |
|
37
|
|
|
'Namespace' |
|
38
|
|
|
), |
|
39
|
|
|
$errors |
|
40
|
|
|
); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
$kind = $item->getSchemaElementKind(); |
|
44
|
|
|
$key = $kind->getKey(); |
|
45
|
|
|
|
|
46
|
|
|
if (array_key_exists($key, $this->lookup)) { |
|
47
|
|
|
InterfaceValidator::CollectErrors( |
|
48
|
|
|
InterfaceValidator::CheckForInterfaceKindValueMismatchError( |
|
49
|
|
|
$item, |
|
50
|
|
|
$item->getSchemaElementKind(), |
|
51
|
|
|
'SchemaElementKind', |
|
52
|
|
|
$this->lookup[$key] |
|
53
|
|
|
), |
|
54
|
|
|
$errors |
|
55
|
|
|
); |
|
56
|
|
|
} else { |
|
57
|
|
|
switch ($kind) { |
|
58
|
|
|
case SchemaElementKind::None(): |
|
59
|
|
|
break; |
|
60
|
|
|
|
|
61
|
|
|
default: |
|
62
|
|
|
InterfaceValidator::CollectErrors( |
|
63
|
|
|
InterfaceValidator::CreateEnumPropertyOutOfRangeError( |
|
64
|
|
|
$item, |
|
65
|
|
|
$item->getSchemaElementKind(), |
|
66
|
|
|
'SchemaElementKind' |
|
67
|
|
|
), |
|
68
|
|
|
$errors |
|
69
|
|
|
); |
|
70
|
|
|
break; |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
return $errors ?? []; |
|
|
|
|
|
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
public function forType(): string |
|
78
|
|
|
{ |
|
79
|
|
|
return ISchemaElement::class; |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
|