J'ai enfin compris le fonctionnement des Services et Listeners, merci .
Suite aux clés trouvés lors des mes recherches Google, j'ai configuré mon fichier config.yml comme suit :
services:
LoggingListener:
class: compagnie\CRUDBundle\Listener\LoggingListener
scope: request
arguments: ['@LoggerService']
tags:
- { name: doctrine.event_listener, event: onFlush, method: onFlush }
LoggerService:
class: compagnie\CRUDBundle\Service\Logger
scope: request
arguments: [@doctrine.orm.entity_manager, @request, @security.context]
Et j'obtiens l'erreur suivante que je ne comprend pas, lorsque j'accède à l'application :
1/1 ScopeWideningInjectionException: Scope Widening Injection detected: The definition "doctrine.dbal.default_connection.event_manager" references the service "logginglistener" which belongs to a narrower scope. Generally, it is safer to either move "doctrine.dbal.default_connection.event_manager" to scope "request" or alternatively rely on the provider pattern by injecting the container itself, and requesting the service "logginglistener" each time it is needed. In rare, special cases however that might not be necessary, then you can set the reference to strict=false to get rid of this error.
Et lorsque je clear le cache :
[Symfony\Component\DependencyInjection\Exception\ScopeWideningInjectionException]
Scope Widening Injection detected: The definition "doctrine.dbal.default_co
nnection.event_manager" references the service "logginglistener" which belo
ngs to a narrower scope. Generally, it is safer to either move "doctrine.db
al.default_connection.event_manager" to scope "request" or alternatively re
ly on the provider pattern by injecting the container itself, and requestin
g the service "logginglistener" each time it is needed. In rare, special ca
ses however that might not be necessary, then you can set the reference to
strict=false to get rid of this error.
Partager