From 736d96c9ba5d57a5546f6732038050428437e87e Mon Sep 17 00:00:00 2001 From: fancyweb Date: Fri, 19 Jul 2019 09:42:34 +0200 Subject: [PATCH] [Doctrine] Invokable event listeners --- doctrine/event_listeners_subscribers.rst | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/doctrine/event_listeners_subscribers.rst b/doctrine/event_listeners_subscribers.rst index de27feecb26..35a351bb675 100644 --- a/doctrine/event_listeners_subscribers.rst +++ b/doctrine/event_listeners_subscribers.rst @@ -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; @@ -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.