I have a listener service. I want to read some config parameters inside it.
How can I access the service container within the listener class?
You can pass container parameters into your service by using the %your_param_name%
notation:
services:
kernel.listener.locale_listener:
class: My\BundleName\Listener\LocaleListener
tags:
- { name: kernel.event_listener, event: kernel.request, method: onKernelRequest }
arguments: [ @router, @service_container, %your_param_name% ]
which will present itself as (in this example) the 3rd argument in your service's constructor method:
public function __construct($router, $container, $paramValue)
{
// ...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With