Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Doctrine: stateOptions IRI now can't be generated with default entity providers #5733

@weaverryan

Description

@weaverryan

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions