Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Doctrine] Adds information on AsEntityListener attribute to the Doctrine event … #17644

Conversation

ericfernance
Copy link

Doctrine Entity Listeners can also now be defined using the AsEntityListener attribute.

This does not require the additional step of creating a service.

Documentation about this is missing from the documentation here (https://symfony.com/doc/current/doctrine/events.html#doctrine-entity-listeners).

This PR adds this to the Doctrine Entity Listeners documentation.

@carsonbot carsonbot changed the title Adds information on AsEntityListener attribute to the Doctrine event … [Doctrine] Adds information on AsEntityListener attribute to the Doctrine event … Jan 3, 2023
@javiereguiluz javiereguiluz added this to the 6.0 milestone Jan 3, 2023
@javiereguiluz javiereguiluz changed the base branch from 6.2 to 6.0 January 3, 2023 16:44
@javiereguiluz javiereguiluz requested a review from xabbuh as a code owner January 3, 2023 16:44
@javiereguiluz javiereguiluz force-pushed the add-doctrine-event-listener-as-attribute branch from f9e6def to 565e0e3 Compare January 3, 2023 16:44
@javiereguiluz javiereguiluz merged commit 3759d16 into symfony:6.0 Jan 3, 2023
@javiereguiluz
Copy link
Member

Eric, thanks for adding these missing contents ... and congrats on your first Symfony Docs contribution 🎉

While merging I did some changes (see 7b93c1f) to make it consistent with existing docs:

@ericfernance
Copy link
Author

ericfernance commented Jan 4, 2023

Hi Javier (@javiereguiluz ),

It appears that the AsDoctrineListener and as AsEntityListener attributes are slightly different.

AsEntityListener allows passing a method, entity, and event as parameters. The method being called when the specified event occurs on the specified entity.

AsDoctrineListener allows passing an event, priority, and connection only as parameters. The resulting class being invoked for the specified event on all entities.

Reviewing the parameters in the Doctrine Lifecycle Subscriber yaml section makes me think that AsDoctrineListener is creating a Lifecycle Subscriber (https://symfony.com/doc/current/doctrine/events.html#doctrine-lifecycle-subscribers). While AsEntityListener is creating an Entity Listener (https://symfony.com/doc/current/doctrine/events.html#doctrine-entity-listeners). Presumably, this is why AsEntityListener accepts an entity parameter while AsDoctrineListener does not.

If this is correct, then the section in the Doctrine Entity Listener will need to use the AsEntityListener attribute and a new section added to the Doctrine Lifecycle Subscriber showing how to use the PHP attribute in the lifecycle subscriber.

I'm relatively new to Symfony so if you wouldn't mind double checking whether this is correct or not. If it is then I am happy to add the AsDoctrineListener section as well. I've been wanting to get a bit more involved in the Symfony community and docs seems to be a good way to get to know the framework better.

Eric.

@javiereguiluz
Copy link
Member

@ericfernance I'm sorry about this 🙏 Thanks for the explanation! This error was fixed in #17661

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants