I want to make a local config file, config_local.yml, that allows each development environment to be configured correctly without screwing up other people’s dev environments. I want it to be a separate file so that I can “gitignore” it and know that nothing essential is missing from the project, while simultaneously not having the issue of git constantly telling me that config_dev.yml has new changes (and running the risk of someone committing those changes).
Right now, I have config_dev.yml doing
imports:
- { resource: config_local.yml }
which is great, unless the file doesn’t exist (i.e. for a new clone of the repository).
My question is: Is there any way to make this include optional? I.e., If the file exists then import it, otherwise ignore it.
Edit: I was hoping for a syntax like:
imports:
- { resource: config.yml }
? { resource: config_local.yml }
A solution is to create a separate environment, which is explained in the Symfony2 cookbook. If you do not wish to create one, there is another way involving the creation of an extension.
Some digging in the Symfony code revealed me that
YamlFileLoader::load()FileLocator::locate()will throw\InvalidArgumentException, if a file is not found. It is invoked byYamlFileLoader::load().If you use the naming conventions, the extension will be automatically executed. For a more thorough explanation, visit this blog.