1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
namespace AlgoWeb\ODataMetadata\ModelVisitorConcerns; |
7
|
|
|
|
8
|
|
|
use AlgoWeb\ODataMetadata\EdmModelVisitor; |
9
|
|
|
use AlgoWeb\ODataMetadata\Enums\ExpressionKind; |
10
|
|
|
use AlgoWeb\ODataMetadata\Exception\InvalidOperationException; |
11
|
|
|
use AlgoWeb\ODataMetadata\Interfaces\Expressions\IApplyExpression; |
12
|
|
|
use AlgoWeb\ODataMetadata\Interfaces\Expressions\IAssertTypeExpression; |
13
|
|
|
use AlgoWeb\ODataMetadata\Interfaces\Expressions\IBinaryConstantExpression; |
14
|
|
|
use AlgoWeb\ODataMetadata\Interfaces\Expressions\IBooleanConstantExpression; |
15
|
|
|
use AlgoWeb\ODataMetadata\Interfaces\Expressions\ICollectionExpression; |
16
|
|
|
use AlgoWeb\ODataMetadata\Interfaces\Expressions\IDateTimeConstantExpression; |
17
|
|
|
use AlgoWeb\ODataMetadata\Interfaces\Expressions\IDateTimeOffsetConstantExpression; |
18
|
|
|
use AlgoWeb\ODataMetadata\Interfaces\Expressions\IDecimalConstantExpression; |
19
|
|
|
use AlgoWeb\ODataMetadata\Interfaces\Expressions\IEntitySetReferenceExpression; |
20
|
|
|
use AlgoWeb\ODataMetadata\Interfaces\Expressions\IEnumMemberReferenceExpression; |
21
|
|
|
use AlgoWeb\ODataMetadata\Interfaces\Expressions\IExpression; |
22
|
|
|
use AlgoWeb\ODataMetadata\Interfaces\Expressions\IFloatingConstantExpression; |
23
|
|
|
use AlgoWeb\ODataMetadata\Interfaces\Expressions\IFunctionReferenceExpression; |
24
|
|
|
use AlgoWeb\ODataMetadata\Interfaces\Expressions\IGuidConstantExpression; |
25
|
|
|
use AlgoWeb\ODataMetadata\Interfaces\Expressions\IIfExpression; |
26
|
|
|
use AlgoWeb\ODataMetadata\Interfaces\Expressions\IIntegerConstantExpression; |
27
|
|
|
use AlgoWeb\ODataMetadata\Interfaces\Expressions\IIsTypeExpression; |
28
|
|
|
use AlgoWeb\ODataMetadata\Interfaces\Expressions\ILabeledExpression; |
29
|
|
|
use AlgoWeb\ODataMetadata\Interfaces\Expressions\ILabeledExpressionReferenceExpression; |
30
|
|
|
use AlgoWeb\ODataMetadata\Interfaces\Expressions\INullExpression; |
31
|
|
|
use AlgoWeb\ODataMetadata\Interfaces\Expressions\IParameterReferenceExpression; |
32
|
|
|
use AlgoWeb\ODataMetadata\Interfaces\Expressions\IPathExpression; |
33
|
|
|
use AlgoWeb\ODataMetadata\Interfaces\Expressions\IPropertyReferenceExpression; |
34
|
|
|
use AlgoWeb\ODataMetadata\Interfaces\Expressions\IRecordExpression; |
35
|
|
|
use AlgoWeb\ODataMetadata\Interfaces\Expressions\IStringConstantExpression; |
36
|
|
|
use AlgoWeb\ODataMetadata\Interfaces\Expressions\ITimeConstantExpression; |
37
|
|
|
use AlgoWeb\ODataMetadata\Interfaces\Expressions\RecordExpression\IPropertyConstructor; |
38
|
|
|
use AlgoWeb\ODataMetadata\StringConst; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Trait VisitExpressions. |
42
|
|
|
* @package AlgoWeb\ODataMetadata\ModelVisitorConcerns |
43
|
|
|
* @mixin EdmModelVisitor |
44
|
|
|
*/ |
45
|
|
|
trait VisitExpressions |
46
|
|
|
{ |
47
|
|
|
public function visitExpressions(array $expressions): void |
48
|
|
|
{ |
49
|
|
|
/** @var EdmModelVisitor $this */ |
50
|
|
|
self::visitCollection($expressions, [$this, 'visitExpression']); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function visitExpression(IExpression $expression): void |
54
|
|
|
{ |
55
|
|
|
/** @var EdmModelVisitor $this */ |
56
|
|
|
switch ($expression->getExpressionKind()) { |
57
|
|
|
case ExpressionKind::AssertType(): |
58
|
|
|
assert($expression instanceof IAssertTypeExpression); |
59
|
|
|
$this->processAssertTypeExpression($expression); |
60
|
|
|
break; |
61
|
|
|
case ExpressionKind::BinaryConstant(): |
62
|
|
|
assert($expression instanceof IBinaryConstantExpression); |
63
|
|
|
$this->processBinaryConstantExpression($expression); |
64
|
|
|
break; |
65
|
|
|
case ExpressionKind::BooleanConstant(): |
66
|
|
|
assert($expression instanceof IBooleanConstantExpression); |
67
|
|
|
$this->processBooleanConstantExpression($expression); |
68
|
|
|
break; |
69
|
|
|
case ExpressionKind::Collection(): |
70
|
|
|
assert($expression instanceof ICollectionExpression); |
71
|
|
|
$this->processCollectionExpression($expression); |
72
|
|
|
break; |
73
|
|
|
case ExpressionKind::DateTimeConstant(): |
74
|
|
|
assert($expression instanceof IDateTimeConstantExpression); |
75
|
|
|
$this->processDateTimeConstantExpression($expression); |
76
|
|
|
break; |
77
|
|
|
case ExpressionKind::DateTimeOffsetConstant(): |
78
|
|
|
assert($expression instanceof IDateTimeOffsetConstantExpression); |
79
|
|
|
$this->processDateTimeOffsetConstantExpression($expression); |
80
|
|
|
break; |
81
|
|
|
case ExpressionKind::DecimalConstant(): |
82
|
|
|
assert($expression instanceof IDecimalConstantExpression); |
83
|
|
|
$this->processDecimalConstantExpression($expression); |
84
|
|
|
break; |
85
|
|
|
case ExpressionKind::EntitySetReference(): |
86
|
|
|
assert($expression instanceof IEntitySetReferenceExpression); |
87
|
|
|
$this->processEntitySetReferenceExpression($expression); |
88
|
|
|
break; |
89
|
|
|
case ExpressionKind::EnumMemberReference(): |
90
|
|
|
assert($expression instanceof IEnumMemberReferenceExpression); |
91
|
|
|
$this->processEnumMemberReferenceExpression($expression); |
92
|
|
|
break; |
93
|
|
|
case ExpressionKind::FloatingConstant(): |
94
|
|
|
assert($expression instanceof IFloatingConstantExpression); |
95
|
|
|
$this->processFloatingConstantExpression($expression); |
96
|
|
|
break; |
97
|
|
|
case ExpressionKind::FunctionApplication(): |
98
|
|
|
assert($expression instanceof IApplyExpression); |
99
|
|
|
$this->processFunctionApplicationExpression($expression); |
100
|
|
|
break; |
101
|
|
|
case ExpressionKind::FunctionReference(): |
102
|
|
|
assert($expression instanceof IFunctionReferenceExpression); |
103
|
|
|
$this->processFunctionReferenceExpression($expression); |
104
|
|
|
break; |
105
|
|
|
case ExpressionKind::GuidConstant(): |
106
|
|
|
assert($expression instanceof IGuidConstantExpression); |
107
|
|
|
$this->processGuidConstantExpression($expression); |
108
|
|
|
break; |
109
|
|
|
case ExpressionKind::If(): |
110
|
|
|
assert($expression instanceof IIfExpression); |
111
|
|
|
$this->processIfExpression($expression); |
112
|
|
|
break; |
113
|
|
|
case ExpressionKind::IntegerConstant(): |
114
|
|
|
assert($expression instanceof IIntegerConstantExpression); |
115
|
|
|
$this->processIntegerConstantExpression($expression); |
116
|
|
|
break; |
117
|
|
|
case ExpressionKind::IsType(): |
118
|
|
|
assert($expression instanceof IIsTypeExpression); |
119
|
|
|
$this->processIsTypeExpression($expression); |
120
|
|
|
break; |
121
|
|
|
case ExpressionKind::ParameterReference(): |
122
|
|
|
assert($expression instanceof IParameterReferenceExpression); |
123
|
|
|
$this->processParameterReferenceExpression($expression); |
124
|
|
|
break; |
125
|
|
|
case ExpressionKind::LabeledExpressionReference(): |
126
|
|
|
assert($expression instanceof ILabeledExpressionReferenceExpression); |
127
|
|
|
$this->processLabeledExpressionReferenceExpression($expression); |
128
|
|
|
break; |
129
|
|
|
case ExpressionKind::Labeled(): |
130
|
|
|
assert($expression instanceof ILabeledExpression); |
131
|
|
|
$this->processLabeledExpression($expression); |
132
|
|
|
break; |
133
|
|
|
case ExpressionKind::Null(): |
134
|
|
|
assert($expression instanceof INullExpression); |
135
|
|
|
$this->processNullConstantExpression($expression); |
136
|
|
|
break; |
137
|
|
|
case ExpressionKind::Path(): |
138
|
|
|
assert($expression instanceof IPathExpression); |
139
|
|
|
$this->processPathExpression($expression); |
140
|
|
|
break; |
141
|
|
|
case ExpressionKind::PropertyReference(): |
142
|
|
|
assert($expression instanceof IPropertyReferenceExpression); |
143
|
|
|
$this->processPropertyReferenceExpression($expression); |
144
|
|
|
break; |
145
|
|
|
case ExpressionKind::Record(): |
146
|
|
|
assert($expression instanceof IRecordExpression); |
147
|
|
|
$this->processRecordExpression($expression); |
148
|
|
|
break; |
149
|
|
|
case ExpressionKind::StringConstant(): |
150
|
|
|
assert($expression instanceof IStringConstantExpression); |
151
|
|
|
$this->processStringConstantExpression($expression); |
152
|
|
|
break; |
153
|
|
|
case ExpressionKind::TimeConstant(): |
154
|
|
|
assert($expression instanceof ITimeConstantExpression); |
155
|
|
|
$this->processTimeConstantExpression($expression); |
156
|
|
|
break; |
157
|
|
|
case ExpressionKind::ValueTermReference(): |
158
|
|
|
assert($expression instanceof IPropertyReferenceExpression); |
159
|
|
|
$this->processPropertyReferenceExpression($expression); |
160
|
|
|
break; |
161
|
|
|
case ExpressionKind::None(): |
162
|
|
|
$this->processExpression($expression); |
163
|
|
|
break; |
164
|
|
|
default: |
165
|
|
|
throw new InvalidOperationException( |
166
|
|
|
StringConst::UnknownEnumVal_TermKind($expression->getExpressionKind()->getKey()) |
167
|
|
|
); |
168
|
|
|
} |
169
|
|
|
} |
170
|
|
|
/** |
171
|
|
|
* @param IPropertyConstructor[] $constructor |
172
|
|
|
*/ |
173
|
|
|
public function visitPropertyConstructors(array $constructor): void |
174
|
|
|
{ |
175
|
|
|
/** @var EdmModelVisitor $this */ |
176
|
|
|
self::visitCollection($constructor, [$this, 'processPropertyConstructor']); |
177
|
|
|
} |
178
|
|
|
} |
179
|
|
|
|