Download the PHP package vivait/settings-bundle without Composer
On this page you can find all versions of the php package vivait/settings-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package settings-bundle
Viva IT - Settings Bundle 
The aim of this bundle is to allow you to retrieve and pass dynamic settings to services and other classes used in Symfony. These settings can be currently be stored in Doctrine, Redis, or Symfony's config itself. Single or multiple drivers can be specified for each setting and/or service, which will search each driver until a setting has been found.
A controller has been provided to easily allow your users to configure settings via a UI - although we recommend you customise this to match your own application.
Installation
Using composer
Enabling bundle
Add routing rules (optional)
Usage
Settings are accessed via drivers. The bundle comes with several drivers to get you started, but you must define them in
your config.yml
file:
The simplest way to retrieve a setting is to do it directly via the class. This will then check all of the drivers available until it can find the setting:
You can also check for settings via a driver collection. A driver collection is just a stack of drivers, and can be created via the class.
In the example above, the settings registry would try each driver referenced in the driver collection and stop when it found the appropriate setting.
You can also specify a default value for if a setting value isn't found in any driver:
Passing settings directly to services
Most likely, you're going to want to pass your settings directly to your services in your services config file. You can do this via expressions:
You can still specify the drivers in the expression:
Notice in the examples above how we've used a '.' to categorise a setting. The reason for this will become apparent when create our settings form, but groups are optional and can be nested.
Adding custom drivers
Adding custom drivers is easy, and is encouraged. For example, as part of our Auth Bundle, we allow per-user settings. This is provided via a custom driver.
All drivers must implement the interface. To register a driver add your driver to the service container:
Next, add the service id to your config.yml
file as described above.
Using a form to change a setting
Create a form type, and inject the required driver.
In the form type, add the setting keys you wish to modify, as well as SettingsSubscriber
and the KeyToArrayTransformer
:
Handle your form as normal, but set the data using your driver of choice:
Testing Run
Unit Test are written with PHPSpec.