@@ -357,11 +357,11 @@ want to log all the database activity. To do so, define a subscriber for the
357
357
namespace App\EventListener;
358
358
359
359
use App\Entity\Product;
360
- use Doctrine\Common\ EventSubscriber;
360
+ use Doctrine\Bundle\DoctrineBundle\ EventSubscriber\EventSubscriberInterface ;
361
361
use Doctrine\ORM\Events;
362
362
use Doctrine\Persistence\Event\LifecycleEventArgs;
363
363
364
- class DatabaseActivitySubscriber implements EventSubscriber
364
+ class DatabaseActivitySubscriber implements EventSubscriberInterface
365
365
{
366
366
// this method can only return the event names; you cannot define a
367
367
// 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
406
406
}
407
407
}
408
408
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
- # ...
409
+ .. versionadded :: 2.1
420
410
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;
444
-
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.
448
418
449
419
If you need to associate the subscriber with a specific Doctrine connection, you
450
420
can do it in the service configuration:
0 commit comments