Skip to content

Commit

Permalink
fix(symfony): use skolem iri when no identifier is found
Browse files Browse the repository at this point in the history
  • Loading branch information
soyuka committed Sep 8, 2022
1 parent f82d343 commit 2cefabb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
6 changes: 5 additions & 1 deletion src/Api/IdentifiersExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,11 @@ public function getIdentifiersFromItem(object $item, Operation $operation = null
private function getIdentifierValue(object $item, string $class, string $property, string $parameterName): float|bool|int|string
{
if ($item instanceof $class) {
return $this->resolveIdentifierValue($this->propertyAccessor->getValue($item, $property), $parameterName);
try {
return $this->resolveIdentifierValue($this->propertyAccessor->getValue($item, $property), $parameterName);
} catch (NoSuchPropertyException $e) {
throw new RuntimeException('Not able to retrieve identifiers.', $e->getCode(), $e);
}
}

$resourceClass = $this->getResourceClass($item, true);
Expand Down
8 changes: 4 additions & 4 deletions src/Symfony/Routing/IriConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ public function getIriFromResource(object|string $resource, int $referenceType =
}
}

if (!$operation->getName() || ($operation instanceof HttpOperation && SkolemIriConverter::$skolemUriTemplate === $operation->getUriTemplate())) {
return $this->generateSkolemIri($resource, $referenceType, $operation, $context, $resourceClass);
}

$identifiers = $context['uri_variables'] ?? [];

if (\is_object($resource)) {
Expand All @@ -151,10 +155,6 @@ public function getIriFromResource(object|string $resource, int $referenceType =
}
}

if (!$operation->getName() || ($operation instanceof HttpOperation && SkolemIriConverter::$skolemUriTemplate === $operation->getUriTemplate())) {
return $this->generateSkolemIri($resource, $referenceType, $operation, $context, $resourceClass);
}

try {
return $this->router->generate($operation->getName(), $identifiers, $operation->getUrlGenerationStrategy() ?? $referenceType);
} catch (RoutingExceptionInterface $e) {
Expand Down

0 comments on commit 2cefabb

Please sign in to comment.