Skip to content

Commit 0b14455

Browse files
committed
Implement ability to define the controller for a subresource
1 parent 905ac01 commit 0b14455

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/Bridge/Symfony/Routing/ApiLoader.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,18 @@ public function load($data, $type = null): RouteCollection
106106
}
107107

108108
foreach ($this->subresourceOperationFactory->create($resourceClass) as $operationId => $operation) {
109+
if (null === $controller = $operation['controller'] ?? null) {
110+
$controller = self::DEFAULT_ACTION_PATTERN.'get_subresource';
111+
112+
if (!$this->container->has($controller)) {
113+
throw new RuntimeException(sprintf('There is no builtin action for the %s %s operation. You need to define the controller yourself.', OperationType::SUBRESOURCE, 'GET'));
114+
}
115+
}
116+
109117
$routeCollection->add($operation['route_name'], new Route(
110118
$operation['path'],
111119
[
112-
'_controller' => self::DEFAULT_ACTION_PATTERN.'get_subresource',
120+
'_controller' => $controller,
113121
'_format' => null,
114122
'_api_resource_class' => $operation['resource_class'],
115123
'_api_subresource_operation_name' => $operation['route_name'],

src/Operation/Factory/SubresourceOperationFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ final class SubresourceOperationFactory implements SubresourceOperationFactoryIn
2626
{
2727
const SUBRESOURCE_SUFFIX = '_subresource';
2828
const FORMAT_SUFFIX = '.{_format}';
29-
const ROUTE_OPTIONS = ['defaults' => [], 'requirements' => [], 'options' => [], 'host' => '', 'schemes' => [], 'condition' => ''];
29+
const ROUTE_OPTIONS = ['defaults' => [], 'requirements' => [], 'options' => [], 'host' => '', 'schemes' => [], 'condition' => '', 'controller' => ''];
3030

3131
private $resourceMetadataFactory;
3232
private $propertyNameCollectionFactory;

0 commit comments

Comments
 (0)