Enable attaching an entity listener without specifying an event #1560
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Requires doctrine/orm#10122
Currently, when registering an entity listener the event name needs to be specified, eg:
If the event is not specified, it's not registered. This is because of the following check:
DoctrineBundle/DependencyInjection/Compiler/EntityListenerPass.php
Lines 56 to 58 in 23c23c7
However, when the
EntityListeners
attribute is used the events get read from the listener class by matching the method names to the names of possible events, eg:The following code is triggers this behavior:
https://github.com/doctrine/orm/blob/06c77cebb5aa7ee3cb57f8cc0d2224538de154d7/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php#L527-L529
The problem with this approach is that it's not very intuitive since the configuration is split across multiple files making it hard to use.
With this PR, the events will attempt to be auto-mapped in the
AttachEntityListenersListener
ifnull
is passed as the event name (see doctrine/orm#10122), eg: