We're starting to adopt Symfony 2 for projects here at work, which is great, but there's a challenge I'm working to solve that I've almost got, but not quite.
Symfony treats the concept of an environment as a separate runtime on a single server. This is great because you can switch between runtimes with different front controllers (web) or using the env switch (cli) at a whim.
However, our code is deployed across many servers as part of the development process. Everybody has a local VM, then code propagates up through Integration, QA, Staging, and finally Production.
So, our concept of an environment is server (virtual or physical). Here are the goals with this custom configuration
- Maintain Symfony's ootb functionality in respect to runtime environment switching
- Allow for public (i.e., developer controlled) configuration per-server
- Maintain private (i.e., sysad controlled) configuration per-server
- Will work for both web and cli
This means we can't just 100% rely on parameters.ini or any statically-named file, for that matter, since the developer will need control over configuration for each server plus all this files will be living next to eachother in git.
So, what I'd like to do is this. Add a new value to parameters.ini that sets the server environment. Something like this
app/config/parameters.ini
[parameters]
server="int"
And then, in the kernel, load an additional configuration file based on that value. For example, I'd love for this to work but it doesn't (since the container doesn't yet exist at this step)
app/AppKernel.php
public function registerContainerConfiguration(LoaderInterface $loader)
{
$loader->load(__DIR__.'/config/config_'.$this->getEnvironment().'.yml');
// Per-server config
$server = $this->getContainer()->getParameter( 'server' );
if ( $server )
{
$loader->load(__DIR__.'/config/server/'.$server.'.yml');
}
}
This would enable the usage of a file like app/config/server/int.yml that the developer can use to control non-private (i.e., not parameters.ini) configuration values.
Thanks for reading, and let me know if anything is confusing.
EDIT
For clarification, things I can't use or rely on
- *nix environment variables from the user's profile or via
export. Why? Integration, QA, and Staging might all be on the same box - Anything in the vhost config (won't work for cli)
- A statically-named file (i.e., something just named server.ini won't work)
parameters.iniusingparse_ini_filemethod. Although I didn't understand your problem clearly. Are you saying that each server config file will have different routing/security configuration?