doctrine / instantiator

https://www.doctrine-project.org/projects/instantiator.html
MIT License
10.94k stars 60 forks source link

Fail nicely on enum FQCNs #90

Closed derrabus closed 2 years ago

derrabus commented 2 years ago

When being presented with an enum FQCN, the Instantiator currently tries to create an instance via reflection and triggers an Error. This PR turns this error into a nice Doctrine\Instantiator\Exception\InvalidArgumentException which is the same exception we already get for interfaces, traits and abstract classes.

An alternative could be to simply return the first case of the enum. The problem with that approach is that the instantiator currently guarantees that each call will yield a different instance. That wouldn't be the case for enums then.