@@ -47,21 +47,21 @@ public function testApiLoader()
47
47
$ resourceMetadata = $ resourceMetadata ->withShortName ('dummy ' );
48
48
//default operation based on OperationResourceMetadataFactory
49
49
$ resourceMetadata = $ resourceMetadata ->withItemOperations ([
50
- 'get ' => ['method ' => 'GET ' ],
50
+ 'get ' => ['method ' => 'GET ' , ' requirements ' => [ ' id ' => ' \d+ ' ] ],
51
51
'put ' => ['method ' => 'PUT ' ],
52
52
'delete ' => ['method ' => 'DELETE ' ],
53
53
]);
54
54
//custom operations
55
55
$ resourceMetadata = $ resourceMetadata ->withCollectionOperations ([
56
- 'my_op ' => ['method ' => 'GET ' , 'controller ' => 'some.service.name ' ], //with controller
56
+ 'my_op ' => ['method ' => 'GET ' , 'controller ' => 'some.service.name ' , ' requirements ' => [ ' _format ' => ' a valid format ' ] ], //with controller
57
57
'my_second_op ' => ['method ' => 'POST ' ], //without controller, takes the default one
58
58
'my_path_op ' => ['method ' => 'GET ' , 'path ' => 'some/custom/path ' ], //custom path
59
59
]);
60
60
61
61
$ routeCollection = $ this ->getApiLoaderWithResourceMetadata ($ resourceMetadata )->load (null );
62
62
63
63
$ this ->assertEquals (
64
- $ this ->getRoute ('/dummies/{id}.{_format} ' , 'api_platform.action.get_item ' , DummyEntity::class, 'get ' , ['GET ' ]),
64
+ $ this ->getRoute ('/dummies/{id}.{_format} ' , 'api_platform.action.get_item ' , DummyEntity::class, 'get ' , ['GET ' ], false , [ ' id ' => ' \d+ ' ] ),
65
65
$ routeCollection ->get ('api_dummies_get_item ' )
66
66
);
67
67
@@ -76,7 +76,7 @@ public function testApiLoader()
76
76
);
77
77
78
78
$ this ->assertEquals (
79
- $ this ->getRoute ('/dummies.{_format} ' , 'some.service.name ' , DummyEntity::class, 'my_op ' , ['GET ' ], true ),
79
+ $ this ->getRoute ('/dummies.{_format} ' , 'some.service.name ' , DummyEntity::class, 'my_op ' , ['GET ' ], true , [ ' _format ' => ' a valid format ' ] ),
80
80
$ routeCollection ->get ('api_dummies_my_op_collection ' )
81
81
);
82
82
@@ -261,7 +261,7 @@ private function getApiLoaderWithResourceMetadata(ResourceMetadata $resourceMeta
261
261
return $ apiLoader ;
262
262
}
263
263
264
- private function getRoute (string $ path , string $ controller , string $ resourceClass , string $ operationName , array $ methods , bool $ collection = false ): Route
264
+ private function getRoute (string $ path , string $ controller , string $ resourceClass , string $ operationName , array $ methods , bool $ collection = false , array $ requirements = [] ): Route
265
265
{
266
266
return new Route (
267
267
$ path ,
@@ -271,15 +271,15 @@ private function getRoute(string $path, string $controller, string $resourceClas
271
271
'_api_resource_class ' => $ resourceClass ,
272
272
sprintf ('_api_%s_operation_name ' , $ collection ? 'collection ' : 'item ' ) => $ operationName ,
273
273
],
274
- [] ,
274
+ $ requirements ,
275
275
[],
276
276
'' ,
277
277
[],
278
278
$ methods
279
279
);
280
280
}
281
281
282
- private function getSubresourceRoute (string $ path , string $ controller , string $ resourceClass , string $ operationName , array $ context ): Route
282
+ private function getSubresourceRoute (string $ path , string $ controller , string $ resourceClass , string $ operationName , array $ context, array $ requirements = [] ): Route
283
283
{
284
284
return new Route (
285
285
$ path ,
@@ -290,7 +290,7 @@ private function getSubresourceRoute(string $path, string $controller, string $r
290
290
'_api_subresource_operation_name ' => $ operationName ,
291
291
'_api_subresource_context ' => $ context ,
292
292
],
293
- [] ,
293
+ $ requirements ,
294
294
[],
295
295
'' ,
296
296
[],
0 commit comments