rekalogika / mapper

An object mapper for PHP and Symfony. Maps an object to another object. Primarily used for transforming an entity to a DTO and vice versa.
MIT License
26 stars 1 forks source link

Can't map object to abstract|interface with AsObjectMapper #241

Closed Norbytus closed 3 days ago

Norbytus commented 3 days ago

I try manually map object to interface impl, with AsObjectMapper, but always get error Trying to instantiate "TargetInterface", but it is not instantiable. You might solve this problem by adding an "InheritanceMap" to the class, so the mapper will know which concrete class to instantiate.

Norbytus commented 3 days ago

It's then you try SourceInterface class map to certain class like

final readonly class Mapper
{
    public function map(SourceInterface $source): Target
    {
        /*....*/
     }
}

But get error on opposite direction

final readonly class Mapper
{
    public function map(Source $source): TargetInterface
    {
        /*....*/
     }
}
priyadi commented 3 days ago

The bug is there, and should be fixed by the related PR. However, I got a different error message here. Try clearing your cache, and try again, my guess you will now get "Target class ... is not a valid class". If correct, then we have a cache invalidation bug that should be fixed for dev environment.