private function getOperationMethod(string $resourceClass, string $operationName, bool $collection) : string
{
$resourceMetadata = $this->resourceMetadataFactory->create($resourceClass);
if ($collection) {
$method = $resourceMetadata->getCollectionOperationAttribute($operationName, 'method');
} else {
$method = $resourceMetadata->getItemOperationAttribute($operationName, 'method');
}
if (null !== $method) {
return $method;
}
if (null === ($routeName = $this->getRouteName($resourceMetadata, $operationName, $collection))) {
throw new RuntimeException(sprintf('Either a "route_name" or a "method" operation attribute must exist for the operation "%s" of the resource "%s".', $operationName, $resourceClass));
}
$route = $this->getRoute($routeName);
$methods = $route->getMethods();
if (empty($methods)) {
return 'GET';
}
return $methods[0];
}