14
14
namespace ApiPlatform \Core \Upgrade ;
15
15
16
16
use ApiPlatform \Core \Annotation \ApiFilter as LegacyApiFilter ;
17
- use ApiPlatform \Core \Bridge \Doctrine \Orm \Filter \SearchFilter as LegacySearchFilter ;
18
- use ApiPlatform \Core \Bridge \Doctrine \Orm \Filter \ExistsFilter as LegacyExistsFilter ;
17
+ use ApiPlatform \Core \Bridge \Doctrine \Orm \Filter \BooleanFilter as LegacyBooleanFilter ;
19
18
use ApiPlatform \Core \Bridge \Doctrine \Orm \Filter \DateFilter as LegacyDateFilter ;
20
- use ApiPlatform \Doctrine \Orm \Filter \SearchFilter ;
21
- use ApiPlatform \Doctrine \Orm \Filter \ExistsFilter ;
19
+ use ApiPlatform \Core \Bridge \Doctrine \Orm \Filter \ExistsFilter as LegacyExistsFilter ;
20
+ use ApiPlatform \Core \Bridge \Doctrine \Orm \Filter \NumericFilter as LegacyNumericFilter ;
21
+ use ApiPlatform \Core \Bridge \Doctrine \Orm \Filter \OrderFilter as LegacyOrderFilter ;
22
+ use ApiPlatform \Core \Bridge \Doctrine \Orm \Filter \RangeFilter as LegacyRangeFilter ;
23
+ use ApiPlatform \Core \Bridge \Doctrine \Orm \Filter \SearchFilter as LegacySearchFilter ;
24
+ use ApiPlatform \Doctrine \Orm \Filter \BooleanFilter ;
22
25
use ApiPlatform \Doctrine \Orm \Filter \DateFilter ;
26
+ use ApiPlatform \Doctrine \Orm \Filter \ExistsFilter ;
27
+ use ApiPlatform \Doctrine \Orm \Filter \NumericFilter ;
28
+ use ApiPlatform \Doctrine \Orm \Filter \OrderFilter ;
29
+ use ApiPlatform \Doctrine \Orm \Filter \RangeFilter ;
30
+ use ApiPlatform \Doctrine \Orm \Filter \SearchFilter ;
23
31
use ApiPlatform \Metadata \ApiFilter ;
24
32
use ApiPlatform \Metadata \Resource \DeprecationMetadataTrait ;
25
33
use Doctrine \Common \Annotations \AnnotationReader ;
@@ -51,6 +59,10 @@ public function enterNode(Node $node)
51
59
SearchFilter::class,
52
60
ExistsFilter::class,
53
61
DateFilter::class,
62
+ BooleanFilter::class,
63
+ NumericFilter::class,
64
+ OrderFilter::class,
65
+ RangeFilter::class,
54
66
];
55
67
56
68
foreach ($ node ->stmts as $ k => $ stmt ) {
@@ -76,9 +88,22 @@ public function enterNode(Node $node)
76
88
unset($ node ->stmts [$ k ]);
77
89
continue ;
78
90
}
79
-
80
-
81
-
91
+ if (LegacyBooleanFilter::class === $ useStatement ) {
92
+ unset($ node ->stmts [$ k ]);
93
+ continue ;
94
+ }
95
+ if (LegacyNumericFilter::class === $ useStatement ) {
96
+ unset($ node ->stmts [$ k ]);
97
+ continue ;
98
+ }
99
+ if (LegacyOrderFilter::class === $ useStatement ) {
100
+ unset($ node ->stmts [$ k ]);
101
+ continue ;
102
+ }
103
+ if (LegacyRangeFilter::class === $ useStatement ) {
104
+ unset($ node ->stmts [$ k ]);
105
+ continue ;
106
+ }
82
107
83
108
if (false !== ($ key = array_search ($ useStatement , $ namespaces , true ))) {
84
109
unset($ namespaces [$ key ]);
@@ -96,16 +121,13 @@ public function enterNode(Node $node)
96
121
}
97
122
}
98
123
99
- if ($ node instanceof Node \Stmt \Property || $ node instanceof Node \Stmt \Class_) {
124
+ if ($ node instanceof Node \Stmt \Property || $ node instanceof Node \Stmt \Class_ || $ node instanceof Node \ Stmt \Interface_ ) {
100
125
if ($ node instanceof Node \Stmt \Property) {
101
126
$ reflection = $ this ->reflectionClass ->getProperty ($ node ->props [0 ]->name ->__toString ());
102
127
} else {
103
128
$ reflection = $ this ->reflectionClass ;
104
129
}
105
130
106
- // filter annotation : array
107
- $ filterAnnotations = $ this ->readApiFilters ($ reflection );
108
-
109
131
foreach ($ this ->readApiFilters ($ reflection ) as $ annotation ) {
110
132
[$ filterAnnotation , $ isAnnotation ] = $ annotation ;
111
133
if ($ isAnnotation ) {
@@ -122,19 +144,11 @@ public function enterNode(Node $node)
122
144
'properties ' ,
123
145
'arguments ' ,
124
146
] as $ key ) {
125
- $ value = $ filterAnnotation ->{$ key };
126
- if (null === $ value || [] === $ value ) {
127
- continue ;
128
- }
129
- $ arguments [$ key ] = $ this ->valueToNode ($ value );
147
+ $ value = $ filterAnnotation ->{$ key };
130
148
131
- }
132
- foreach ($ filterAnnotation ->attributes ?? [] as $ key => $ value ) {
133
- if (null === $ value || [] === $ value ) {
149
+ if (!$ value ) {
134
150
continue ;
135
151
}
136
-
137
- [$ key , $ value ] = $ this ->getKeyValue ($ key , $ value );
138
152
$ arguments [$ key ] = $ this ->valueToNode ($ value );
139
153
}
140
154
@@ -146,15 +160,14 @@ public function enterNode(Node $node)
146
160
]));
147
161
}
148
162
}
149
-
150
163
}
151
164
152
- private function readApiFilters (\ReflectionProperty |\ReflectionClass $ reflection ): ?\Generator
165
+ private function readApiFilters (\ReflectionProperty |\ReflectionClass | \ ReflectionInterface $ reflection ): ?\Generator
153
166
{
154
167
if (\PHP_VERSION_ID >= 80000 && $ attributes = $ reflection ->getAttributes (LegacyApiFilter::class)) {
155
- yield from array_map (function ($ attribute ) {
156
- return $ attribute ->newInstance ();
157
- } , $ attributes );
168
+ yield from array_map (function ($ attribute ) {
169
+ return [ $ attribute ->newInstance (), false ] ;
170
+ }, $ attributes );
158
171
}
159
172
160
173
if (null === $ this ->reader ) {
@@ -165,7 +178,6 @@ private function readApiFilters(\ReflectionProperty|\ReflectionClass $reflection
165
178
$ annotations = $ this ->reader ->getPropertyAnnotations ($ reflection );
166
179
} else {
167
180
$ annotations = $ this ->reader ->getClassAnnotations ($ reflection );
168
-
169
181
}
170
182
171
183
foreach ($ annotations as $ annotation ) {
@@ -236,14 +248,14 @@ private function arrayToArguments(array $arguments)
236
248
{
237
249
$ args = [];
238
250
foreach ($ arguments as $ key => $ value ) {
239
- if ($ value )
251
+ if ($ value ) {
240
252
$ args [] = new Node \Arg ($ value , false , false , [], new Node \Identifier ($ key ));
253
+ }
241
254
}
242
255
243
256
return $ args ;
244
257
}
245
258
246
-
247
259
private function getShortName (string $ class ): string
248
260
{
249
261
if (false !== $ pos = strrpos ($ class , '\\' )) {
@@ -252,5 +264,4 @@ private function getShortName(string $class): string
252
264
253
265
return $ class ;
254
266
}
255
-
256
267
}
0 commit comments