18
18
use ApiPlatform \Core \Exception \RuntimeException ;
19
19
use ApiPlatform \Core \Metadata \Resource \Factory \ResourceMetadataFactoryInterface ;
20
20
use ApiPlatform \Core \Metadata \Resource \Factory \ResourceNameCollectionFactoryInterface ;
21
+ use ApiPlatform \Core \Metadata \Resource \ResourceMetadata ;
21
22
use ApiPlatform \Core \Operation \Factory \SubresourceOperationFactoryInterface ;
22
23
use ApiPlatform \Core \PathResolver \OperationPathResolverInterface ;
23
24
use Symfony \Component \Config \FileLocator ;
@@ -91,13 +92,13 @@ public function load($data, $type = null): RouteCollection
91
92
92
93
if (null !== $ collectionOperations = $ resourceMetadata ->getCollectionOperations ()) {
93
94
foreach ($ collectionOperations as $ operationName => $ operation ) {
94
- $ this ->addRoute ($ routeCollection , $ resourceClass , $ operationName , $ operation , $ resourceShortName , OperationType::COLLECTION );
95
+ $ this ->addRoute ($ routeCollection , $ resourceClass , $ operationName , $ operation , $ resourceMetadata , OperationType::COLLECTION );
95
96
}
96
97
}
97
98
98
99
if (null !== $ itemOperations = $ resourceMetadata ->getItemOperations ()) {
99
100
foreach ($ itemOperations as $ operationName => $ operation ) {
100
- $ this ->addRoute ($ routeCollection , $ resourceClass , $ operationName , $ operation , $ resourceShortName , OperationType::ITEM );
101
+ $ this ->addRoute ($ routeCollection , $ resourceClass , $ operationName , $ operation , $ resourceMetadata , OperationType::ITEM );
101
102
}
102
103
}
103
104
@@ -170,17 +171,12 @@ private function loadExternalFiles(RouteCollection $routeCollection)
170
171
/**
171
172
* Creates and adds a route for the given operation to the route collection.
172
173
*
173
- * @param RouteCollection $routeCollection
174
- * @param string $resourceClass
175
- * @param string $operationName
176
- * @param array $operation
177
- * @param string $resourceShortName
178
- * @param string $operationType
179
- *
180
174
* @throws RuntimeException
181
175
*/
182
- private function addRoute (RouteCollection $ routeCollection , string $ resourceClass , string $ operationName , array $ operation , string $ resourceShortName , string $ operationType )
176
+ private function addRoute (RouteCollection $ routeCollection , string $ resourceClass , string $ operationName , array $ operation , ResourceMetadata $ resourceMetadata , string $ operationType )
183
177
{
178
+ $ resourceShortName = $ resourceMetadata ->getShortName ();
179
+
184
180
if (isset ($ operation ['route_name ' ])) {
185
181
return ;
186
182
}
@@ -197,8 +193,11 @@ private function addRoute(RouteCollection $routeCollection, string $resourceClas
197
193
}
198
194
}
199
195
196
+ $ path = trim (trim ($ resourceMetadata ->getAttribute ('routePrefix ' , '' )), '/ ' );
197
+ $ path .= $ this ->operationPathResolver ->resolveOperationPath ($ resourceShortName , $ operation , $ operationType , $ operationName );
198
+
200
199
$ route = new Route (
201
- $ this -> operationPathResolver -> resolveOperationPath ( $ resourceShortName , $ operation , $ operationType , $ operationName ) ,
200
+ $ path ,
202
201
[
203
202
'_controller ' => $ controller ,
204
203
'_format ' => null ,
0 commit comments