There are many use cases where it’s useful to inject different services based
on the Symfony environment or on another param such as an env variable for instance.
Example 1
In Symfony dev env we want to use mailcatcher to send/receive emails.
In Symfony prod env we want to use postfix to send emails.
Example 2
In Symfony prod env on a staging server we want to use mailcatcher to send/receive emails.
In Symfony prod env on the production server we want to use postfix to send emails.
Example 1: environments
config.yml
config_dev.yml
Example 2: environment variables and parameters
Get the value of an env variable on your system and build a symfony parameter:
CLI
Apache
Inject the service dynamically based on this parameter