Skip to content

feat(metadata): get URI variables from an IRI without loading the item - #8841

Open
ViPErCZ wants to merge 1 commit into
api-platform:mainfrom
ViPErCZ:feat/iri-converter-uri-variables-from-iri
Open

ViPErCZ wants to merge 1 commit into
api-platform:mainfrom
ViPErCZ:feat/iri-converter-uri-variables-from-iri

Conversation

@ViPErCZ

@ViPErCZ ViPErCZ commented Nov 12, 2026

Copy link
Copy Markdown
Contributor
Q A
Branch? main
Tickets -
License MIT
Doc PR api-platform/docs#...

Adds UriVariablesFromIriInterface::getUriVariablesFromIri(), which matches an IRI against the router and returns the URI variables of the item it references, without calling the state
provider. It lives in a separate interface, so IriConverterInterface is untouched and existing implementations and decorators keep working.

Functional test (tests/Functional/UriVariablesFromIriTest.php), the resource's provider throws, so getting a result proves the item is not loaded:

public function testGetUriVariablesFromIriWithoutCallingTheProvider(): void
{
    $this->assertSame(['id' => 1], $this->getIriConverter()->getUriVariablesFromIri('/uri_variables_from_iri_resources/1'));
}

public function testGetUriVariablesFromCollectionIri(): void
{
    $this->expectException(InvalidArgumentException::class);
    $this->expectExceptionMessage('The iri "/uri_variables_from_iri_resources" references a collection not an item.');

    $this->getIriConverter()->getUriVariablesFromIri('/uri_variables_from_iri_resources');
}

public function testGetUriVariablesFromUnknownIri(): void
{
    $this->expectException(InvalidArgumentException::class);
    $this->expectExceptionMessage('No route matches "/does_not_exist/1".');

    $this->getIriConverter()->getUriVariablesFromIri('/does_not_exist/1');
}

Unit tests cover the Symfony, Laravel and MCP converters (tests/Symfony/Routing/IriConverterTest.php, src/Laravel/Tests/Unit/Routing/IriConverterTest.php,
src/Mcp/Tests/Routing/IriConverterTest.php).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant