Skip to content

BC break: api-platform/state 4.2.3 doesn't work with symfony/object-mapper 7.3 #7504

@andreasferber

Description

@andreasferber

API Platform version(s) affected: 4.2.3

Description

PR #7486 added ObjectMapperAwareInterface to ApiPlatform\State\ObjectMapper. However this interface doesn't exist yet in symfony/object-mapper version 7.3.*, it's only about to be introduced in the (as of now unreleased) version 7.4/8.0.

Note that the use of ObjectMapperAwareInterface in the instanceof check in the constructor that already existed before the PR is fine because PHP doesn't consider it an error to check for an interface that isn't defined. However adding the interface to the implements list does require the interface to actually exist.

Possible Solution
api-platform/state should probably provide its own version of ObjectMapperAwareInterface conditionally inheriting from object-mapper's interface only if it's available. ObjectMapper should then implement this interface.

And withObjectMapper shouldn't throw an exception if the decorated object mapper doesn't implement ObjectMapperAwareInterface, instead it should just silently skip the call to $this->decorated->withObjectMapper(). I don't think there's any harm in doing that even with object-mapper 7.4, as in this case the downstream ObjectMapper clearly doesn't expect to be passed down the outer decorator in the first place (eg. because it may not have any need to call into ObjectMapper recursively).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions