Symfony 1.2: sfDbConfigPlugin, a sfConfig Counterpart

Symfony has a file based configuration, and with sfDbConfigPlugin, it can handle a database based configuration.

sfDbConfigPlugin provide the following feature:

sfDbConfig class

sfDbConfig class provide a counterpart methods of sfConfig class:

sfDbConfig::set('MYSETTING::TEST', 'test value'); // set the value
sfDbConfig::get('MYSETTING::TEST', 'default');    // get the value, return 'default' if not defined
$exist = sfDbConfig::has('MYSETTING::TEST');      // check if a configuration exist
sfDbConfig::remove('MYSETTING::TEST');            // remove a configuration
Override a YAML configuration

We can easily override a YAML configuration, for example we have a configuration:

// app.yml
all:
  my_setting:
    setting1:                        test

To override the above configuration, we can define a sfDbConfig configuration named OVERRIDE::app_my_setting_setting1 and provide the overidden value.

Also we can define which environment will be overridden by specifying the environment before the configuration name, so it becomes OVERRIDE::prod:app_my_setting_setting1.

sfDbConfig configuration can be altered any time with the included admin interface.

db-config-edit

Instalation and Configuration
  1. Download the plugin here, currently only available for symfony 1.2.
  2. Install and enable the plugin.
  3. Rename project/plugins/sfDbConfigPlugin/config/schema.yml.sample to schema.yml.
  4. Rebuild model, form, filter, and sql, then insert generated sql to database.
  5. Enable sfDbConfigAdmin module in settings.yml so we can define and alter a configuration.
  6. Enable sfDbConfig module so we can clear the configuration override cache by navigating to an url /reload-config-override.

Leave a Reply