8000 minor #15599 [Doctrine] Document EventSubscriberInterface (W0rma) · symfony/symfony-docs@4982d4f · GitHub
[go: up one dir, main page]

Skip to content

Commit 4982d4f

Browse files
committed
minor #15599 [Doctrine] Document EventSubscriberInterface (W0rma)
This PR was merged into the 4.4 branch. Discussion ---------- [Doctrine] Document EventSubscriberInterface `Doctrine\Bundle\DoctrineBundle\EventSubscriber\EventSubscriberInterface` was introduced in doctrine/DoctrineBundle#1119 Fixes #15234 Commits ------- e8b3b04 Add note about EventSubscriberInterface introduced in DoctrineBundle 2.1
2 parents ca90be0 + e8b3b04 commit 4982d4f

File tree

1 file changed

+10
-40
lines changed

1 file changed

+10
-40
lines changed

doctrine/events.rst

Lines changed: 10 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -357,11 +357,11 @@ want to log all the database activity. To do so, define a subscriber for the
357357
namespace App\EventListener;
358358

359359
use App\Entity\Product;
360-
use Doctrine\Common\EventSubscriber;
360+
use Doctrine\Bundle\DoctrineBundle\EventSubscriber\EventSubscriberInterface;
361361
use Doctrine\ORM\Events;
362362
use Doctrine\Persistence\Event\LifecycleEventArgs;
363363

364-
class DatabaseActivitySubscriber implements EventSubscriber
364+
class DatabaseActivitySubscriber implements EventSubscriberInterface
365365
{
366366
// this method can only return the event names; you cannot define a
367367
// custom method name to execute when each event triggers
@@ -406,45 +406,15 @@ want to log all the database activity. To do so, define a subscriber for the
406406
}
407407
}
408408

409-
The next step is to enable the Doctrine subscriber in the Symfony application by
410-
creating a new service for it and :doc:`tagging it </service_container/tags>`
411-
with the ``doctrine.event_subscriber`` tag:
412-
413-
.. configuration-block::
414-
415-
.. code-block:: yaml
416-
417-
# config/services.yaml
418-
services:
419-
# ...
420-
421-
App\EventListener\DatabaseActivitySubscriber:
422-
tags:
423-
- { name: 'doctrine.event_subscriber' }
424-
425-
.. code-block:: xml
426-
427-
<!-- config/services.xml -->
428-
<?xml version="1.0" encoding="UTF-8" ?>
429-
<container xmlns="http://symfony.com/schema/dic/services"
430-
xmlns:doctrine="http://symfony.com/schema/dic/doctrine">
431-
<services>
432-
<!-- ... -->
433-
434-
<service id="App\EventListener\DatabaseActivitySubscriber">
435-
<tag name="doctrine.event_subscriber"/>
436-
</service>
437-
</services>
438-
</container>
439-
440-
.. code-block:: php
441-
442-
// config/services.php
443-
use App\EventListener\DatabaseActivitySubscriber;
409+
.. note::
444410

445-
$container->autowire(DatabaseActivitySubscriber::class)
446-
->addTag('doctrine.event_subscriber')
447-
;
411+
``Doctrine\Bundle\DoctrineBundle\EventSubscriber\EventSubscriberInterface``
412+
is a marker interface extending ``Doctrine\Common\EventSubscriber`` and was
413+
introduced in DoctrineBundle 2.1.
414+
Subscribers implementing this interface will be enabled automatically in the
415+
Symfony application.
416+
In older versions of DoctrineBundle, the service had to be added manually
417+
and tagged with the ``doctrine.event_subscriber`` tag.
448418

449419
If you need to associate the subscriber with a specific Doctrine connection, you
450420
can do it in the service configuration:

0 commit comments

Comments
 (0)
0