Skip to content

Commit 1b8b032

Browse files
committed
Merge branch '4.4' into 5.3
* 4.4: Add note about EventSubscriberInterface introduced in DoctrineBundle 2.1
2 parents a25ee5a + e7ce930 commit 1b8b032

File tree

1 file changed

+9
-50
lines changed

1 file changed

+9
-50
lines changed

doctrine/events.rst

Lines changed: 9 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -365,11 +365,11 @@ want to log all the database activity. To do so, define a subscriber for the
365365
namespace App\EventListener;
366366

367367
use App\Entity\Product;
368-
use Doctrine\Common\EventSubscriber;
368+
use Doctrine\Bundle\DoctrineBundle\EventSubscriber\EventSubscriberInterface;
369369
use Doctrine\ORM\Events;
370370
use Doctrine\Persistence\Event\LifecycleEventArgs;
371371

372-
class DatabaseActivitySubscriber implements EventSubscriber
372+
class DatabaseActivitySubscriber implements EventSubscriberInterface
373373
{
374374
// this method can only return the event names; you cannot define a
375375
// custom method name to execute when each event triggers
@@ -414,9 +414,13 @@ want to log all the database activity. To do so, define a subscriber for the
414414
}
415415
}
416416

417-
The next step is to enable the Doctrine subscriber in the Symfony application by
418-
creating a new service for it and :doc:`tagging it </service_container/tags>`
419-
with the ``doctrine.event_subscriber`` tag:
417+
If you're using the :ref:`default services.yaml configuration <service-container-services-load-example>`
418+
and DoctrineBundle 2.1 (released May 25, 2020) or newer, this example will already
419+
work! Otherwise, :ref:`create a service <service-container-creating-service>` for this
420+
subscriber and :doc:`tag it </service_container/tags>` with ``doctrine.event_subscriber``.
421+
422+
If you need to configure some option of the subscriber (e.g. its priority or
423+
Doctrine connection to use) you must do that in the manual service configuration:
420424

421425
.. configuration-block::
422426

@@ -479,51 +483,6 @@ with the ``doctrine.event_subscriber`` tag:
479483
;
480484
};
481485
482-
If you need to associate the subscriber with a specific Doctrine connection, you
483-
can do it in the service configuration:
484-
485-
.. configuration-block::
486-
487-
.. code-block:: yaml
488-
489-
# config/services.yaml
490-
services:
491-
# ...
492-
493-
App\EventListener\DatabaseActivitySubscriber:
494-
tags:
495-
- { name: 'doctrine.event_subscriber', connection: 'default' }
496-
497-
.. code-block:: xml
498-
499-
<!-- config/services.xml -->
500-
<?xml version="1.0" encoding="UTF-8" ?>
501-
<container xmlns="http://symfony.com/schema/dic/services"
502-
xmlns:doctrine="http://symfony.com/schema/dic/doctrine">
503-
<services>
504-
<!-- ... -->
505-
506-
<service id="App\EventListener\DatabaseActivitySubscriber">
507-
<tag name="doctrine.event_subscriber" connection="default"/>
508-
</service>
509-
</services>
510-
</container>
511-
512-
.. code-block:: php
513-
514-
// config/services.php
515-
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
516-
517-
use App\EventListener\DatabaseActivitySubscriber;
518-
519-
return static function (ContainerConfigurator $container) {
520-
$services = $configurator->services();
521-
522-
$services->set(DatabaseActivitySubscriber::class)
523-
->tag('doctrine.event_subscriber', ['connection' => 'default'])
524-
;
525-
};
526-
527486
.. versionadded:: 5.3
528487

529488
Subscriber priority was introduced in Symfony 5.3.

0 commit comments

Comments
 (0)