Symfony2: How to get a config parameter within a listener?
dependency-injection, symfony
Solution
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)
{
// ...
}
Problem
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?