# config/services.yamlservices:# ...App\EventListener\SearchIndexer:tags:-name:'doctrine.event_listener'# this is the only required option for the lifecycle listener tagevent:'postPersist'# listeners can define their priority in case multiple subscribers or listeners are associated# to the same event (default priority = 0; higher numbers = listener is run earlier)priority:500# you can also restrict listeners to a specific Doctrine connectionconnection:'default'
<!-- config/services.xml --><?xml version="1.0" encoding="UTF-8" ?><containerxmlns="http://symfony.com/schema/dic/services" xmlns:doctrine="http://symfony.com/schema/dic/doctrine"><services><!-- ... --><!-- * 'event' is the only required option that defines the lifecycle listener * 'priority': used when multiple subscribers or listeners are associated to the same event * (default priority = 0; higher numbers = listener is run earlier) * 'connection': restricts the listener to a specific Doctrine connection --><serviceid="App\EventListener\SearchIndexer"><tagname="doctrine.event_listener" event="postPersist" priority="500" connection="default"/></service></services></container>
// config/services.phpnamespaceSymfony\Component\DependencyInjection\Loader\Configurator;useApp\EventListener\SearchIndexer;returnstaticfunction(ContainerConfigurator $configurator){ $services = $configurator->services();// listeners are applied by default to all Doctrine connections $services->set(SearchIndexer::class) ->tag('doctrine.event_listener', [// this is the only required option for the lifecycle listener tag'event' => 'postPersist',// listeners can define their priority in case multiple subscribers or listeners are associated// to the same event (default priority = 0; higher numbers = listener is run earlier)'priority' => 500,// you can also restrict listeners to a specific Doctrine connection'connection' => 'default', ]) ;};