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
Call to action
Did you like this post? You can help me back in several ways: (use the "reply" link on the right to comment or to contact me )
- Report any error/typo.
- Report something that could be improved.
- Like and repost!
- Follow me on Bluesky 🦋
- Subscribe to the RSS feed.
- Click on the More on Stackoverflow buttons to make me win "Announcer" badges 🏅.
                    Thank you for reading! And see you soon on Strangebuzz! 😉
                    
