Injecting the APP_ENV and APP_DEBUG parameters in your Symfony services

Published on 2024-04-13 • Modified on 2024-04-13

This snippet shows how to inject the APP_ENV and APP_DEBUG parameters in your Symfony services (or your controllers) with a bind. In a previous snippet, we saw how to inject the Symfony project's root directory. We can do exactly the same here as APP_ENV and APP_DEBUG are kernel parameters, too.


services:
    _defaults:
        bind:
            string $environment: '%kernel.environment%'
            string $debug: '%kernel.debug%'

# // then inject in your services with:
# public class myService
# {
#       public function __construct(string $environment, string $debug)
#       {

 More on Stackoverflow   Read the doc  Random snippet

  Work with me!