40
40
use ApiPlatform \JsonSchema \SchemaFactoryInterface ;
41
41
use ApiPlatform \Laravel \ApiResource \Error ;
42
42
use ApiPlatform \Laravel \Controller \ApiPlatformController ;
43
+ use ApiPlatform \Laravel \Eloquent \Extension \FilterQueryExtension ;
44
+ use ApiPlatform \Laravel \Eloquent \Extension \QueryExtensionInterface ;
45
+ use ApiPlatform \Laravel \Eloquent \Filter \FilterInterface as EloquentFilterInterface ;
46
+ use ApiPlatform \Laravel \Eloquent \Filter \SearchFilter ;
43
47
use ApiPlatform \Laravel \Eloquent \Metadata \Factory \Property \EloquentAttributePropertyMetadataFactory ;
44
48
use ApiPlatform \Laravel \Eloquent \Metadata \Factory \Property \EloquentAttributePropertyNameCollectionFactory ;
45
49
use ApiPlatform \Laravel \Eloquent \Metadata \Factory \Property \EloquentPropertyMetadataFactory ;
66
70
use ApiPlatform \Laravel \State \SwaggerUiProcessor ;
67
71
use ApiPlatform \Laravel \State \ValidateProvider ;
68
72
use ApiPlatform \Metadata \Exception \NotExposedHttpException ;
73
+ use ApiPlatform \Metadata \FilterInterface ;
69
74
use ApiPlatform \Metadata \IdentifiersExtractor ;
70
75
use ApiPlatform \Metadata \IdentifiersExtractorInterface ;
71
76
use ApiPlatform \Metadata \IriConverterInterface ;
90
95
use ApiPlatform \Metadata \Resource \Factory \LinkResourceMetadataCollectionFactory ;
91
96
use ApiPlatform \Metadata \Resource \Factory \NotExposedOperationResourceMetadataCollectionFactory ;
92
97
use ApiPlatform \Metadata \Resource \Factory \OperationNameResourceMetadataCollectionFactory ;
98
+ use ApiPlatform \Metadata \Resource \Factory \ParameterResourceMetadataCollectionFactory ;
93
99
use ApiPlatform \Metadata \Resource \Factory \PhpDocResourceMetadataCollectionFactory ;
94
100
use ApiPlatform \Metadata \Resource \Factory \ResourceMetadataCollectionFactoryInterface ;
95
101
use ApiPlatform \Metadata \Resource \Factory \ResourceNameCollectionFactoryInterface ;
102
108
use ApiPlatform \OpenApi \Factory \OpenApiFactoryInterface ;
103
109
use ApiPlatform \OpenApi \Options ;
104
110
use ApiPlatform \OpenApi \Serializer \OpenApiNormalizer ;
111
+ use ApiPlatform \Serializer \Filter \FilterInterface as SerializerFilterInterface ;
112
+ use ApiPlatform \Serializer \Filter \PropertyFilter ;
105
113
use ApiPlatform \Serializer \ItemNormalizer ;
106
114
use ApiPlatform \Serializer \JsonEncoder ;
107
115
use ApiPlatform \Serializer \Mapping \Factory \ClassMetadataFactory as SerializerClassMetadataFactory ;
116
+ use ApiPlatform \Serializer \Parameter \SerializerFilterParameterProvider ;
108
117
use ApiPlatform \Serializer \SerializerContextBuilder ;
109
118
use ApiPlatform \State \CallableProcessor ;
110
119
use ApiPlatform \State \CallableProvider ;
111
120
use ApiPlatform \State \Pagination \Pagination ;
112
121
use ApiPlatform \State \Pagination \PaginationOptions ;
122
+ use ApiPlatform \State \ParameterProviderInterface ;
113
123
use ApiPlatform \State \Processor \AddLinkHeaderProcessor ;
114
124
use ApiPlatform \State \Processor \RespondProcessor ;
115
125
use ApiPlatform \State \Processor \SerializeProcessor ;
116
126
use ApiPlatform \State \Processor \WriteProcessor ;
117
127
use ApiPlatform \State \ProcessorInterface ;
118
128
use ApiPlatform \State \Provider \ContentNegotiationProvider ;
119
129
use ApiPlatform \State \Provider \DeserializeProvider ;
130
+ use ApiPlatform \State \Provider \ParameterProvider ;
120
131
use ApiPlatform \State \Provider \ReadProvider ;
121
132
use ApiPlatform \State \ProviderInterface ;
122
133
use ApiPlatform \State \SerializerContextBuilderInterface ;
@@ -247,38 +258,42 @@ public function register(): void
247
258
// TODO: add cached metadata factories
248
259
$ this ->app ->singleton (ResourceMetadataCollectionFactoryInterface::class, function (Application $ app ) use ($ config ) {
249
260
return new EloquentResourceCollectionMetadataFactory (
250
- new AlternateUriResourceMetadataCollectionFactory (
251
- new FiltersResourceMetadataCollectionFactory (
252
- new FormatsResourceMetadataCollectionFactory (
253
- new InputOutputResourceMetadataCollectionFactory (
254
- new PhpDocResourceMetadataCollectionFactory (
255
- new OperationNameResourceMetadataCollectionFactory (
256
- new LinkResourceMetadataCollectionFactory (
257
- $ app -> make (LinkFactoryInterface::class),
258
- new UriTemplateResourceMetadataCollectionFactory (
261
+ new ParameterResourceMetadataCollectionFactory (
262
+ $ this -> app -> make (PropertyNameCollectionFactoryInterface::class),
263
+ new AlternateUriResourceMetadataCollectionFactory (
264
+ new FiltersResourceMetadataCollectionFactory (
265
+ new FormatsResourceMetadataCollectionFactory (
266
+ new InputOutputResourceMetadataCollectionFactory (
267
+ new PhpDocResourceMetadataCollectionFactory (
268
+ new OperationNameResourceMetadataCollectionFactory (
269
+ new LinkResourceMetadataCollectionFactory (
259
270
$ app ->make (LinkFactoryInterface::class),
260
- $ app ->make (PathSegmentNameGeneratorInterface::class),
261
- new NotExposedOperationResourceMetadataCollectionFactory (
271
+ new UriTemplateResourceMetadataCollectionFactory (
262
272
$ app ->make (LinkFactoryInterface::class),
263
- new AttributesResourceMetadataCollectionFactory (
264
- null ,
265
- $ app ->make (LoggerInterface::class),
266
- [
267
- 'routePrefix ' => $ config ->get ('api-platform.routes.prefix ' ) ?? '/ ' ,
268
- ],
269
- false
273
+ $ app ->make (PathSegmentNameGeneratorInterface::class),
274
+ new NotExposedOperationResourceMetadataCollectionFactory (
275
+ $ app ->make (LinkFactoryInterface::class),
276
+ new AttributesResourceMetadataCollectionFactory (
277
+ null ,
278
+ $ app ->make (LoggerInterface::class),
279
+ [
280
+ 'routePrefix ' => $ config ->get ('api-platform.routes.prefix ' ) ?? '/ ' ,
281
+ ],
282
+ false
283
+ )
270
284
)
271
285
)
272
286
)
273
287
)
274
288
)
275
- )
276
- ),
277
- $ config ->get ('api-platform.formats ' ),
278
- $ config -> get ( ' api-platform.patch_formats ' ),
289
+ ),
290
+ $ config -> get ( ' api-platform.formats ' ),
291
+ $ config ->get ('api-platform.patch_formats ' ),
292
+ )
279
293
)
280
- )
281
- ),
294
+ ),
295
+ $ app ->make (FilterInterface::class)
296
+ )
282
297
);
283
298
});
284
299
@@ -292,6 +307,22 @@ public function register(): void
292
307
293
308
$ this ->app ->bind (OperationMetadataFactoryInterface::class, OperationMetadataFactory::class);
294
309
310
+ $ this ->app ->tag ([SearchFilter::class], EloquentFilterInterface::class);
311
+ $ this ->app ->tag ([SearchFilter::class, PropertyFilter::class], FilterInterface::class);
312
+ $ this ->app ->singleton (FilterInterface::class, function (Application $ app ) {
313
+ $ tagged = iterator_to_array ($ app ->tagged (FilterInterface::class));
314
+
315
+ return new ServiceLocator ($ tagged );
316
+ });
317
+
318
+ $ this ->app ->bind (FilterQueryExtension::class, function (Application $ app ) {
319
+ $ tagged = iterator_to_array ($ app ->tagged (EloquentFilterInterface::class));
320
+
321
+ return new FilterQueryExtension (new ServiceLocator ($ tagged ));
322
+ });
323
+
324
+ $ this ->app ->tag ([FilterQueryExtension::class], QueryExtensionInterface::class);
325
+
295
326
$ this ->app ->singleton (ItemProvider::class, function (Application $ app ) {
296
327
$ tagged = iterator_to_array ($ app ->tagged (LinksHandlerInterface::class));
297
328
@@ -300,7 +331,7 @@ public function register(): void
300
331
$ this ->app ->singleton (CollectionProvider::class, function (Application $ app ) {
301
332
$ tagged = iterator_to_array ($ app ->tagged (LinksHandlerInterface::class));
302
333
303
- return new CollectionProvider ($ app ->make (Pagination::class), new LinksHandler ($ app ), new ServiceLocator ($ tagged ));
334
+ return new CollectionProvider ($ app ->make (Pagination::class), new LinksHandler ($ app ), $ app -> tagged (QueryExtensionInterface::class), new ServiceLocator ($ tagged ));
304
335
});
305
336
$ this ->app ->tag ([ItemProvider::class, CollectionProvider::class], ProviderInterface::class);
306
337
@@ -326,8 +357,24 @@ public function register(): void
326
357
return new DeserializeProvider ($ app ->make (JsonApiProvider::class), $ app ->make (SerializerInterface::class), $ app ->make (SerializerContextBuilderInterface::class));
327
358
});
328
359
360
+ $ this ->app ->tag ([PropertyFilter::class], SerializerFilterInterface::class);
361
+
362
+ $ this ->app ->singleton (SerializerFilterParameterProvider::class, function (Application $ app ) {
363
+ $ tagged = iterator_to_array ($ app ->tagged (SerializerFilterInterface::class));
364
+
365
+ return new SerializerFilterParameterProvider (new ServiceLocator ($ tagged ));
366
+ });
367
+
368
+ $ this ->app ->tag ([SerializerFilterParameterProvider::class], ParameterProviderInterface::class);
369
+
370
+ $ this ->app ->singleton (ParameterProvider::class, function (Application $ app ) {
371
+ $ tagged = iterator_to_array ($ app ->tagged (ParameterProviderInterface::class));
372
+
373
+ return new ParameterProvider ($ app ->make (DeserializeProvider::class), new ServiceLocator ($ tagged ));
374
+ });
375
+
329
376
$ this ->app ->singleton (AccessCheckerProvider::class, function (Application $ app ) {
330
- return new AccessCheckerProvider ($ app ->make (DeserializeProvider ::class), $ app ->make (ResourceAccessCheckerInterface::class));
377
+ return new AccessCheckerProvider ($ app ->make (ParameterProvider ::class), $ app ->make (ResourceAccessCheckerInterface::class));
331
378
});
332
379
333
380
$ this ->app ->singleton (ContentNegotiationProvider::class, function (Application $ app ) use ($ config ) {
@@ -339,6 +386,7 @@ public function register(): void
339
386
$ this ->app ->tag ([RemoveProcessor::class, PersistProcessor::class], ProcessorInterface::class);
340
387
$ this ->app ->singleton (CallableProcessor::class, function (Application $ app ) {
341
388
$ tagged = iterator_to_array ($ app ->tagged (ProcessorInterface::class));
389
+ // TODO: tag SwaggerUiProcessor instead?
342
390
$ tagged ['api_platform.swagger_ui.processor ' ] = $ app ->make (SwaggerUiProcessor::class);
343
391
344
392
return new CallableProcessor (new ServiceLocator ($ tagged ));
@@ -503,8 +551,6 @@ public function register(): void
503
551
return new DocumentationAction ($ app ->make (ResourceNameCollectionFactoryInterface::class), $ config ->get ('api-platform.title ' ) ?? '' , $ config ->get ('api-platform.description ' ) ?? '' , $ config ->get ('api-platform.version ' ) ?? '' , $ app ->make (OpenApiFactoryInterface::class), $ app ->make (ProviderInterface::class), $ app ->make (ProcessorInterface::class), $ app ->make (Negotiator::class), $ config ->get ('api-platform.docs_formats ' ));
504
552
});
505
553
506
- $ this ->app ->singleton (FilterLocator::class, FilterLocator::class);
507
-
508
554
$ this ->app ->singleton (EntrypointAction::class, function (Application $ app ) {
509
555
return new EntrypointAction ($ app ->make (ResourceNameCollectionFactoryInterface::class), $ app ->make (ProviderInterface::class), $ app ->make (ProcessorInterface::class), ['jsonld ' => ['application/ld+json ' ]]);
510
556
});
@@ -539,7 +585,7 @@ public function register(): void
539
585
$ app ->make (PropertyNameCollectionFactoryInterface::class),
540
586
$ app ->make (PropertyMetadataFactoryInterface::class),
541
587
$ app ->make (SchemaFactoryInterface::class),
542
- $ app ->make (FilterLocator ::class),
588
+ $ app ->make (FilterInterface ::class),
543
589
$ config ->get ('api-platform.formats ' ),
544
590
null , // ?Options $openApiOptions = null,
545
591
$ app ->make (PaginationOptions::class), // ?PaginationOptions $paginationOptions = null,
0 commit comments