Trying to register a Doctrine EventSubscriber but it doesn't work.
(symfony 7)
Here's the Subscriber:
<?php
namespace App\EventSubscriber;
use Doctrine\Common\EventSubscriber;
use Doctrine\ORM\Events;
use Doctrine\Persistence\Event\LifecycleEventArgs;
class LogSubscriber implements EventSubscriber
{
public function getSubscribedEvents()
{
return [
Events::postPersist,
Events::postUpdate,
Events::postRemove
];
}
public function postPersist(LifecycleEventArgs $args)
{
dd($args);
}
public function postUpdate(LifecycleEventArgs $args)
{
dd($args);
}
public function postRemove(LifecycleEventArgs $args)
{
dd($args);
}
}
and my services.yaml
# This file is the entry point to configure your own services.
# Files in the packages/ subdirectory configure your dependencies.
# Put parameters here that don't need to change on each machine where the app is deployed
# https://symfony.com/doc/current/best_practices.html#use-parameters-for-application-configuration
parameters:
services:
# default configuration for services in *this* file
_defaults:
autowire: true # Automatically injects dependencies in your services.
autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.
# makes classes in src/ available to be used as services
# this creates a service per class whose id is the fully-qualified class name
App\:
resource: '../src/'
exclude:
- '../src/DependencyInjection/'
- '../src/Entity/'
- '../src/Kernel.php'
# add more service definitions when explicit configuration is needed
# please note that last definitions always *replace* previous ones
App\EventSubscriber\LogSubscriber:
tags:
- { name: doctrine.orm.event_subscribe, connection: default }
I tried with 'doctrine.event_subscribe' but that did not work.
I don't really understand what's wrong, thanks in advance for the help.
As @yolenoyer commented, the interface has been deprecated.
Preface your Listener with the new PHP 8 Attributes