@@ -48,21 +48,21 @@ public function testApiLoader()
48
48
$ resourceMetadata = $ resourceMetadata ->withShortName ('dummy ' );
49
49
//default operation based on OperationResourceMetadataFactory
50
50
$ resourceMetadata = $ resourceMetadata ->withItemOperations ([
51
- 'get ' => ['method ' => 'GET ' , 'requirements ' => ['id ' => '\d+ ' ]],
51
+ 'get ' => ['method ' => 'GET ' , 'requirements ' => ['id ' => '\d+ ' ], ' defaults ' => [ ' my_default ' => ' default_value ' , ' _controller ' => ' should_not_be_overriden ' ] ],
52
52
'put ' => ['method ' => 'PUT ' ],
53
53
'delete ' => ['method ' => 'DELETE ' ],
54
54
]);
55
55
//custom operations
56
56
$ resourceMetadata = $ resourceMetadata ->withCollectionOperations ([
57
- 'my_op ' => ['method ' => 'GET ' , 'controller ' => 'some.service.name ' , 'requirements ' => ['_format ' => 'a valid format ' ]], //with controller
58
- 'my_second_op ' => ['method ' => 'POST ' ], //without controller, takes the default one
57
+ 'my_op ' => ['method ' => 'GET ' , 'controller ' => 'some.service.name ' , 'requirements ' => ['_format ' => 'a valid format ' ], ' defaults ' => [ ' my_default ' => ' default_value ' ], ' condition ' => " request.headers.get('User-Agent') matches '/firefox/i' " ], //with controller
58
+ 'my_second_op ' => ['method ' => 'POST ' , ' options ' => [ ' option ' => ' option_value ' ], ' host ' => ' {subdomain}.api-platform.com ' , ' schemes ' => [ ' https ' ] ], //without controller, takes the default one
59
59
'my_path_op ' => ['method ' => 'GET ' , 'path ' => 'some/custom/path ' ], //custom path
60
60
]);
61
61
62
62
$ routeCollection = $ this ->getApiLoaderWithResourceMetadata ($ resourceMetadata )->load (null );
63
63
64
64
$ this ->assertEquals (
65
- $ this ->getRoute ('/dummies/{id}.{_format} ' , 'api_platform.action.get_item ' , DummyEntity::class, 'get ' , ['GET ' ], false , ['id ' => '\d+ ' ]),
65
+ $ this ->getRoute ('/dummies/{id}.{_format} ' , 'api_platform.action.get_item ' , DummyEntity::class, 'get ' , ['GET ' ], false , ['id ' => '\d+ ' ], [ ' my_default ' => ' default_value ' ] ),
66
66
$ routeCollection ->get ('api_dummies_get_item ' )
67
67
);
68
68
@@ -77,12 +77,12 @@ public function testApiLoader()
77
77
);
78
78
79
79
$ this ->assertEquals (
80
- $ this ->getRoute ('/dummies.{_format} ' , 'some.service.name ' , DummyEntity::class, 'my_op ' , ['GET ' ], true , ['_format ' => 'a valid format ' ]),
80
+ $ this ->getRoute ('/dummies.{_format} ' , 'some.service.name ' , DummyEntity::class, 'my_op ' , ['GET ' ], true , ['_format ' => 'a valid format ' ], [ ' my_default ' => ' default_value ' ], [], '' , [], " request.headers.get('User-Agent') matches '/firefox/i' " ),
81
81
$ routeCollection ->get ('api_dummies_my_op_collection ' )
82
82
);
83
83
84
84
$ this ->assertEquals (
85
- $ this ->getRoute ('/dummies.{_format} ' , 'api_platform.action.post_collection ' , DummyEntity::class, 'my_second_op ' , ['POST ' ], true ),
85
+ $ this ->getRoute ('/dummies.{_format} ' , 'api_platform.action.post_collection ' , DummyEntity::class, 'my_second_op ' , ['POST ' ], true , [], [], [ ' option ' => ' option_value ' ], ' {subdomain}.api-platform.com ' , [ ' https ' ] ),
86
86
$ routeCollection ->get ('api_dummies_my_second_op_collection ' )
87
87
);
88
88
@@ -262,7 +262,7 @@ private function getApiLoaderWithResourceMetadata(ResourceMetadata $resourceMeta
262
262
return $ apiLoader ;
263
263
}
264
264
265
- private function getRoute (string $ path , string $ controller , string $ resourceClass , string $ operationName , array $ methods , bool $ collection = false , array $ requirements = []): Route
265
+ private function getRoute (string $ path , string $ controller , string $ resourceClass , string $ operationName , array $ methods , bool $ collection = false , array $ requirements = [], array $ extraDefaults = [], array $ options = [], string $ host = '' , array $ schemes = [], string $ condition = '' ): Route
266
266
{
267
267
return new Route (
268
268
$ path ,
@@ -271,12 +271,13 @@ private function getRoute(string $path, string $controller, string $resourceClas
271
271
'_format ' => null ,
272
272
'_api_resource_class ' => $ resourceClass ,
273
273
sprintf ('_api_%s_operation_name ' , $ collection ? 'collection ' : 'item ' ) => $ operationName ,
274
- ],
274
+ ] + $ extraDefaults ,
275
275
$ requirements ,
276
- [],
277
- '' ,
278
- [],
279
- $ methods
276
+ $ options ,
277
+ $ host ,
278
+ $ schemes ,
279
+ $ methods ,
280
+ $ condition
280
281
);
281
282
}
282
283
0 commit comments