Skip to content

Commit 5cadcb3

Browse files
committed
chore(deprecation): remove identifiers complexity
1 parent 5a6d7c8 commit 5cadcb3

File tree

5 files changed

+21
-29
lines changed

5 files changed

+21
-29
lines changed

src/Api/IdentifiersExtractor.php

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -141,38 +141,10 @@ private function resolveIdentifierValue($identifierValue, string $parameterName)
141141
return $identifierValue;
142142
}
143143

144-
// TODO: php 8 remove method_exists
145-
if (method_exists($identifierValue, '__toString') || $identifierValue instanceof \Stringable) {
144+
if ($identifierValue instanceof \Stringable) {
146145
return (string) $identifierValue;
147146
}
148147

149-
// TODO: remove this in 3.0
150-
// we could recurse to find correct identifiers until there it is a scalar but this is not really supported and adds a lot of complexity
151-
// instead we're deprecating this behavior in favor of something that can be transformed to a string
152-
if ($this->isResourceClass($relatedResourceClass = $this->getObjectClass($identifierValue))) {
153-
trigger_deprecation('api-platform/core', '2.7', 'Using a resource class as identifier is deprecated, please make this identifier Stringable');
154-
$relatedOperation = $this->resourceMetadataFactory->create($relatedResourceClass)->getOperation();
155-
156-
$relatedLinks = [];
157-
if ($relatedOperation instanceof GraphQlOperation) {
158-
$relatedLinks = $relatedOperation->getLinks();
159-
} elseif ($relatedOperation instanceof HttpOperation) {
160-
$relatedLinks = $relatedOperation->getUriVariables();
161-
}
162-
163-
if (1 === \count($relatedLinks)) {
164-
$identifierValue = $this->getIdentifierValue($identifierValue, $relatedResourceClass, current($relatedLinks)->getIdentifiers()[0], $parameterName);
165-
166-
if (\is_scalar($identifierValue)) {
167-
return $identifierValue;
168-
}
169-
170-
if ($identifierValue instanceof \Stringable || method_exists($identifierValue, '__toString')) {
171-
return (string) $identifierValue;
172-
}
173-
}
174-
}
175-
176148
throw new RuntimeException(sprintf('We were not able to resolve the identifier matching parameter "%s".', $parameterName));
177149
}
178150
}

tests/Fixtures/TestBundle/Document/DummyFriend.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,9 @@ public function setName(string $name)
7979
{
8080
$this->name = $name;
8181
}
82+
83+
public function __toString()
84+
{
85+
return (string) $this->getId();
86+
}
8287
}

tests/Fixtures/TestBundle/Document/RelatedDummy.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,4 +178,9 @@ public function setEmbeddedDummy(EmbeddableDummy $embeddedDummy)
178178
{
179179
$this->embeddedDummy = $embeddedDummy;
180180
}
181+
182+
public function __toString()
183+
{
184+
return (string) $this->getId();
185+
}
181186
}

tests/Fixtures/TestBundle/Entity/DummyFriend.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,9 @@ public function setName(string $name)
8181
{
8282
$this->name = $name;
8383
}
84+
85+
public function __toString()
86+
{
87+
return (string) $this->getId();
88+
}
8489
}

tests/Fixtures/TestBundle/Entity/RelatedDummy.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,4 +188,9 @@ public function setEmbeddedDummy(EmbeddableDummy $embeddedDummy)
188188
{
189189
$this->embeddedDummy = $embeddedDummy;
190190
}
191+
192+
public function __toString()
193+
{
194+
return (string) $this->getId();
195+
}
191196
}

0 commit comments

Comments
 (0)