API Platform version(s) affected: 3.1-dev (unreleased)
Description
@soyuka is helping me out BIG time to get stateOptions: new Options(entityClass: User::class), working nicely. #5726 fixed a bug where IRI generation would fail if you implemented a custom provider that returned your DTO objects. That seems to work great!
However, now the default case looks broken in the same way. Consider:
#[ApiResource(
stateOptions: new Options(entityClass: User::class),
)]
class UserApi
This will now fail with Unable to generate an IRI for the item of type "App\ApiResource\UserApi. It's the opposite problem as before: IdentifiersExtractor will not grab the id because here -
|
if ($item instanceof $class) { |
-
$item will be the entity (
User) but
$class will be
UserApi.
How to reproduce
I have an easy reproducer here: https://github.com/symfonycasts/api-platform3/tree/playing-with-stateOptions
You can see it working, at first, with a custom provider that returns the DTOs. Then, by commenting-out the provider option, you can see it fail when the core provider returns the entity objects.
Thanks for your attention - this is all nearly working perfectly.
API Platform version(s) affected: 3.1-dev (unreleased)
Description
@soyuka is helping me out BIG time to get
stateOptions: new Options(entityClass: User::class),working nicely. #5726 fixed a bug where IRI generation would fail if you implemented a custom provider that returned your DTO objects. That seems to work great!However, now the default case looks broken in the same way. Consider:
#[ApiResource( stateOptions: new Options(entityClass: User::class), )] class UserApiThis will now fail with
Unable to generate an IRI for the item of type "App\ApiResource\UserApi. It's the opposite problem as before:IdentifiersExtractorwill not grab theidbecause here -core/src/Api/IdentifiersExtractor.php
Line 98 in 92a81f0
$itemwill be the entity (User) but$classwill beUserApi.How to reproduce
I have an easy reproducer here: https://github.com/symfonycasts/api-platform3/tree/playing-with-stateOptions
You can see it working, at first, with a custom provider that returns the DTOs. Then, by commenting-out the
provideroption, you can see it fail when the core provider returns the entity objects.Thanks for your attention - this is all nearly working perfectly.