Zed-K
Zed-K

Reputation: 999

Symfony: Dynamic configuration file loading

Here is the context :

It may sound trivial, but all I'm looking for is the proper way to load these specific YAML files.


From what I understood so far, using an Extension class isn't possible, since it has no knowledge about current user.

Using a custom service to manage these configurations rather than relying on Symfony's parameters seems more appropriate, but I can't find how to implement validation (using a Configuration class) and caching.

Any help would be greatly appreciated, thanks for your inputs!

Upvotes: 1

Views: 2846

Answers (2)

olaurendeau
olaurendeau

Reputation: 669

Using the Yaml, Processor and Configuration components of Symfony2 should fit your needs.

Define your "CompanyConfiguration" class as if you were in the DependencyInjection case Create a new "CompanyLoader" service

use Symfony\Component\Yaml\Yaml;
use Symfony\Component\Config\Definition\Processor;

$companies = Yaml::parse('company.yml');
$processor = new Processor();
$configuration = new CompanyConfiguration();
$processor->processConfiguration($configuration, $companies);

Now you should be able to use your companies array to do what you want

Upvotes: 3

LBA
LBA

Reputation: 4089

Have a look at http://symfony.com/doc/current/cookbook/configuration/configuration_organization.html as well as http://symfony.com/doc/current/cookbook/configuration/environments.html. If that's not the correct answer you'll have to be more specific on what your company.yml configuration contains.

Upvotes: 1

Related Questions