private function addRoute(RouteCollection $routeCollection, string $resourceClass, string $operationName, array $operation, string $resourceShortName, bool $collection)
{
if (isset($operation['route_name'])) {
return;
}
if (!isset($operation['method'])) {
throw new RuntimeException('Either a "route_name" or a "method" operation attribute must exist.');
}
$controller = $operation['controller'] ?? null;
$collectionType = $collection ? 'collection' : 'item';
$actionName = sprintf('%s_%s', strtolower($operation['method']), $collectionType);
if (null === $controller) {
$controller = self::DEFAULT_ACTION_PATTERN . $actionName;
if (!$this->container->has($controller)) {
throw new RuntimeException(sprintf('There is no builtin action for the %s %s operation. You need to define the controller yourself.', $collectionType, $operation['method']));
}
}
if ($operationName !== strtolower($operation['method'])) {
$actionName = sprintf('%s_%s', $operationName, $collection ? 'collection' : 'item');
}
$path = $this->operationPathResolver->resolveOperationPath($resourceShortName, $operation, $collection);
$resourceRouteName = Inflector::pluralize(Inflector::tableize($resourceShortName));
$routeName = sprintf('%s%s_%s', self::ROUTE_NAME_PREFIX, $resourceRouteName, $actionName);
$route = new Route($path, ['_controller' => $controller, '_format' => null, '_api_resource_class' => $resourceClass, sprintf('_api_%s_operation_name', $collection ? 'collection' : 'item') => $operationName], [], [], '', [], [$operation['method']]);
$routeCollection->add($routeName, $route);
}