trinity / settings
Trinity Settings bundle
Installs: 3 284
Dependents: 4
Suggesters: 0
Security: 0
Stars: 1
Watchers: 15
Forks: 0
Open Issues: 0
Type:symfony-bundle
Requires
- php: >=7.1
- doctrine/orm: ~2.5
- symfony/config: ~2.8|~3.0
- symfony/dependency-injection: ~2.8|~3.0
- symfony/http-kernel: ~2.8|~3.0
- twig/extensions: ~1.3
- twig/twig: ~1.20|~2.0
Requires (Dev)
- doctrine/doctrine-bundle: ~1.6
- fzaninotto/faker: ~1.5
- mockery/mockery: ~0.9
- phpstan/phpstan: ~0.7
- phpunit/phpunit: ~6
- satooshi/php-coveralls: ~1
- symfony/browser-kit: ~2.8|~3.0
- symfony/form: ~3
- symfony/twig-bundle: ~2.8|~3.0
- symfony/validator: ~3
- symfony/var-dumper: ~3.0
README
#Trinity Settings
Bundle for storing Symfony parameters in database using Doctrine2 ORM and easy reach from Symfony Controller and twig.
##Installation
1. Add trinity/settings to your composer.json
//composer.json
{
//..
"require": {
//..
"trinity/settings": "~1.0",
//..
}
//..
}
2. Enable trinity/settings in the kernel:
<?php
// app/AppKernel.php
public function registerBundles()
{
$bundles = array(
// ...
new \Trinity\Bundle\SettingsBundle\SettingsBundle(),
// ...
);
}
##Usages
###Set defaults variables:
In some config.yml
trinity_settings:
settings:
null_value: ~
key: "value"
group.key: "value"
Note: The dot is defined for group.
Usage in Controller:
//Global Setting
$this->get('trinity.settings')->set('parameter', $parameter);
$this->get('trinity.settings')->get('parameter');
$this->get('trinity.settings')->has('parameter');
//User Setting
$this->get('trinity.settings')->set('parameter', $parameter, $owner);
$this->get('trinity.settings')->get('parameter', $owner);
$this->get('trinity.settings')->has('parameter', $owner);
$this->get('trinity.settings')->has('parameter', $user->getId());
//Setting for some setting group ($owner can be null)
$this->get('trinity.settings')->set('parameter', $parameter, $owner, $group);
$this->get('trinity.settings')->get('parameter', $owner, $group);
$this->get('trinity.settings')->has('parameter', $owner, $group);
###Usage In Twig:
{{ get_setting('some_setting') }}
{{ get_setting('some_user_setting', app.user.id) }}
{{ get_setting('some_group_setting', null, 'MySettingGroup') }}
{{ get_setting('some_user_group_setting', app.user.id, 'MySettingGroup') }}
{{ has_setting('some_setting') }}
{{ has_setting('some_user_setting', app.user.id) }}
{{ has_setting('some_group_setting', null, 'MySettingGroup') }}
{{ has_setting('some_user_group_setting', app.user.id, 'MySettingGroup') }}
###Running tests:
php "bin/phpunit.phar"