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\ValueKind; |
10
|
|
|
use AlgoWeb\ODataMetadata\Interfaces\Values\IBinaryValue; |
11
|
|
|
use AlgoWeb\ODataMetadata\Interfaces\Values\IBooleanValue; |
12
|
|
|
use AlgoWeb\ODataMetadata\Interfaces\Values\ICollectionValue; |
13
|
|
|
use AlgoWeb\ODataMetadata\Interfaces\Values\IDateTimeOffsetValue; |
14
|
|
|
use AlgoWeb\ODataMetadata\Interfaces\Values\IDateTimeValue; |
15
|
|
|
use AlgoWeb\ODataMetadata\Interfaces\Values\IDecimalValue; |
16
|
|
|
use AlgoWeb\ODataMetadata\Interfaces\Values\IEnumValue; |
17
|
|
|
use AlgoWeb\ODataMetadata\Interfaces\Values\IFloatingValue; |
18
|
|
|
use AlgoWeb\ODataMetadata\Interfaces\Values\IGuidValue; |
19
|
|
|
use AlgoWeb\ODataMetadata\Interfaces\Values\IIntegerValue; |
20
|
|
|
use AlgoWeb\ODataMetadata\Interfaces\Values\INullValue; |
21
|
|
|
use AlgoWeb\ODataMetadata\Interfaces\Values\IStringValue; |
22
|
|
|
use AlgoWeb\ODataMetadata\Interfaces\Values\IStructuredValue; |
23
|
|
|
use AlgoWeb\ODataMetadata\Interfaces\Values\ITimeValue; |
24
|
|
|
use AlgoWeb\ODataMetadata\Interfaces\Values\IValue; |
25
|
|
|
|
26
|
|
|
class VisitorOfIValue extends VisitorOfT |
27
|
|
|
{ |
28
|
|
|
protected $lookup = []; |
29
|
|
|
|
30
|
|
|
public function __construct() |
31
|
|
|
{ |
32
|
|
|
$this->lookup[ValueKind::Binary()->getValue()] = IBinaryValue::class; |
33
|
|
|
$this->lookup[ValueKind::Boolean()->getValue()] = IBooleanValue::class; |
34
|
|
|
$this->lookup[ValueKind::Collection()->getValue()] = ICollectionValue::class; |
35
|
|
|
$this->lookup[ValueKind::DateTime()->getValue()] = IDateTimeValue::class; |
36
|
|
|
$this->lookup[ValueKind::DateTimeOffset()->getValue()] = IDateTimeOffsetValue::class; |
37
|
|
|
$this->lookup[ValueKind::Decimal()->getValue()] = IDecimalValue::class; |
38
|
|
|
$this->lookup[ValueKind::Enum()->getValue()] = IEnumValue::class; |
39
|
|
|
$this->lookup[ValueKind::Floating()->getValue()] = IFloatingValue::class; |
40
|
|
|
$this->lookup[ValueKind::Guid()->getValue()] = IGuidValue::class; |
41
|
|
|
$this->lookup[ValueKind::Integer()->getValue()] = IIntegerValue::class; |
42
|
|
|
$this->lookup[ValueKind::Null()->getValue()] = INullValue::class; |
43
|
|
|
$this->lookup[ValueKind::String()->getValue()] = IStringValue::class; |
44
|
|
|
$this->lookup[ValueKind::Structured()->getValue()] = IStructuredValue::class; |
45
|
|
|
$this->lookup[ValueKind::Time()->getValue()] = ITimeValue::class; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
protected function VisitT($value, array &$followup, array &$references): ?iterable |
49
|
|
|
{ |
50
|
|
|
assert($value instanceof IValue); |
51
|
|
|
$errors = []; |
52
|
|
|
if (null !== $value->getType()) { |
53
|
|
|
// Value owns its type reference, so it goes as a followup. |
54
|
|
|
$followup[] = $value->getType(); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
$kind = $value->getValueKind(); |
58
|
|
|
if (ValueKind::None()->getValue() === $kind->getValue()) { |
59
|
|
|
return $errors; |
|
|
|
|
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
if (!array_key_exists($kind->getValue(), $this->lookup)) { |
63
|
|
|
InterfaceValidator::CollectErrors( |
64
|
|
|
InterfaceValidator::CreateInterfaceKindValueUnexpectedError( |
65
|
|
|
$value, |
66
|
|
|
$value->getValueKind()->getKey(), |
67
|
|
|
'ValueKind' |
68
|
|
|
), |
69
|
|
|
$errors |
70
|
|
|
); |
71
|
|
|
|
72
|
|
|
return $errors; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
InterfaceValidator::CollectErrors( |
76
|
|
|
InterfaceValidator::CheckForInterfaceKindValueMismatchError( |
77
|
|
|
$value, |
78
|
|
|
$value->getValueKind(), |
79
|
|
|
'ValueKind', |
80
|
|
|
$this->lookup[$kind->getValue()] |
81
|
|
|
), |
82
|
|
|
$errors |
83
|
|
|
); |
84
|
|
|
return $errors; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
public function forType(): string |
88
|
|
|
{ |
89
|
|
|
return IValue::class; |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|