Skip to content

[Doctrine] Invokable event listeners #11992

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

Merged
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
8 changes: 7 additions & 1 deletion doctrine/event_listeners_subscribers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ Creating the Listener Class

In the previous example, a ``SearchIndexer`` service was configured as a Doctrine
listener on the event ``postPersist``. The class behind that service must have
a ``postPersist()`` method, which will be called when the event is dispatched::
a ``postPersist()`` or an ``__invoke()`` method, which will be called when the
event is dispatched::

// src/EventListener/SearchIndexer.php
namespace App\EventListener;
Expand All @@ -123,6 +124,11 @@ a ``postPersist()`` method, which will be called when the event is dispatched::
}
}

.. versionadded:: 4.4

The support of the ``__invoke()`` method to create invokable event listeners
was introduced in Symfony 4.4.

In each event, you have access to a ``LifecycleEventArgs`` object, which
gives you access to both the entity object of the event and the entity manager
itself.
Expand Down