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

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions doctrine/events.rst
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,30 @@ with the ``doctrine.orm.entity_listener`` tag:
;
};


Doctrine Entity Listeners may also be defined using PHP attributes. When using PHP attributes it is not necessary to create a service for the listener.

.. code-block:: php

// src/EventListener/UserChangedNotifier.php
namespace App\EventListener;

use App\Entity\User;
use Doctrine\Persistence\Event\LifecycleEventArgs;
use Doctrine\Bundle\DoctrineBundle\Attribute\AsEntityListener;

#[AsEntityListener(event:'postUpdate', method:'postUpdate', entity:User::class)]
class UserChangedNotifier
{
// the entity listener methods receive two arguments:
// the entity instance and the lifecycle event
public function postUpdate(User $user, LifecycleEventArgs $event): void
{
// ... do something to notify the changes
}
}


Doctrine Lifecycle Subscribers
------------------------------

Expand Down