private function getHydraOperation(string $resourceClass, ResourceMetadata $resourceMetadata, string $operationName, array $operation, string $prefixedShortName, bool $collection) : array
{
if ($collection) {
$method = $this->operationMethodResolver->getCollectionOperationMethod($resourceClass, $operationName);
} else {
$method = $this->operationMethodResolver->getItemOperationMethod($resourceClass, $operationName);
}
$hydraOperation = $operation['hydra_context'] ?? [];
$shortName = $resourceMetadata->getShortName();
if ('GET' === $method && $collection) {
$hydraOperation = ['hydra:title' => sprintf('Retrieves the collection of %s resources.', $shortName), 'returns' => 'hydra:PagedCollection'] + $hydraOperation;
} elseif ('GET' === $method) {
$hydraOperation = ['hydra:title' => sprintf('Retrieves %s resource.', $shortName), 'returns' => $prefixedShortName] + $hydraOperation;
} elseif ('POST' === $method) {
$hydraOperation = ['@type' => 'hydra:CreateResourceOperation', 'hydra:title' => sprintf('Creates a %s resource.', $shortName), 'returns' => $prefixedShortName, 'expects' => $prefixedShortName] + $hydraOperation;
} elseif ('PUT' === $method) {
$hydraOperation = ['@type' => 'hydra:ReplaceResourceOperation', 'hydra:title' => sprintf('Replaces the %s resource.', $shortName), 'returns' => $prefixedShortName, 'expects' => $prefixedShortName] + $hydraOperation;
} elseif ('DELETE' === $method) {
$hydraOperation = ['hydra:title' => sprintf('Deletes the %s resource.', $shortName), 'returns' => 'owl:Nothing'] + $hydraOperation;
}
$hydraOperation['@type'] ?? ($hydraOperation['@type'] = 'hydra:Operation');
$hydraOperation['hydra:method'] ?? ($hydraOperation['hydra:method'] = $method);
if (!isset($hydraOperation['rdfs:label']) && isset($hydraOperation['hydra:title'])) {
$hydraOperation['rdfs:label'] = $hydraOperation['hydra:title'];
}
ksort($hydraOperation);
return $hydraOperation;
}