laravel-doctrine / orm

A drop-in Doctrine ORM 2 implementation for Laravel 5+ and Lumen
http://laraveldoctrine.org
MIT License
827 stars 179 forks source link

[PROPOSAL] Remove memory caching of entity listeners #277

Open zquintana opened 7 years ago

zquintana commented 7 years ago

In the current version of this package the EntityListenerResolver memory caches instances of resolved listeners. This overrides the current behavior of the Laravel container. For example if a develop defines a listener as a factory (bind in Laravel) then it's turned into a singleton via this resolver. This breaks the container definition and forces developers to treat listeners as singletons. Where performance is an issue a developer can still define the listener as a singleton in container via singleton method in the container. Which also means that these checks at https://github.com/laravel-doctrine/orm/blob/1.4/src/Resolvers/EntityListenerResolver.php#L51 are a duplication of what already happens in the make method of the container.

For these reasons my proposal is that the resolve method of the listener be simplified to not cache instances created by the containers make method. It should still check to see if there is an instance in instances property for listeners that have been registered via register method.

patrickbrouwers commented 6 years ago

Feel free to PR it