Skip to content

Commit 2cefabb

Browse files
committed
fix(symfony): use skolem iri when no identifier is found
1 parent f82d343 commit 2cefabb

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

src/Api/IdentifiersExtractor.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,11 @@ public function getIdentifiersFromItem(object $item, Operation $operation = null
8787
private function getIdentifierValue(object $item, string $class, string $property, string $parameterName): float|bool|int|string
8888
{
8989
if ($item instanceof $class) {
90-
return $this->resolveIdentifierValue($this->propertyAccessor->getValue($item, $property), $parameterName);
90+
try {
91+
return $this->resolveIdentifierValue($this->propertyAccessor->getValue($item, $property), $parameterName);
92+
} catch (NoSuchPropertyException $e) {
93+
throw new RuntimeException('Not able to retrieve identifiers.', $e->getCode(), $e);
94+
}
9195
}
9296

9397
$resourceClass = $this->getResourceClass($item, true);

src/Symfony/Routing/IriConverter.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,10 @@ public function getIriFromResource(object|string $resource, int $referenceType =
138138
}
139139
}
140140

141+
if (!$operation->getName() || ($operation instanceof HttpOperation && SkolemIriConverter::$skolemUriTemplate === $operation->getUriTemplate())) {
142+
return $this->generateSkolemIri($resource, $referenceType, $operation, $context, $resourceClass);
143+
}
144+
141145
$identifiers = $context['uri_variables'] ?? [];
142146

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

154-
if (!$operation->getName() || ($operation instanceof HttpOperation && SkolemIriConverter::$skolemUriTemplate === $operation->getUriTemplate())) {
155-
return $this->generateSkolemIri($resource, $referenceType, $operation, $context, $resourceClass);
156-
}
157-
158158
try {
159159
return $this->router->generate($operation->getName(), $identifiers, $operation->getUrlGenerationStrategy() ?? $referenceType);
160160
} catch (RoutingExceptionInterface $e) {

0 commit comments

Comments
 (0)