2017 © Pedro Peláez
 

symfony-bundle settings

Trinity Settings bundle

image

trinity/settings

Trinity Settings bundle

  • Wednesday, August 2, 2017
  • by modpreneur
  • Repository
  • 16 Watchers
  • 1 Stars
  • 3,272 Installations
  • PHP
  • 6 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 13 Versions
  • 0 % Grown

The README.md

Trinity Settings

Coverage Status Build Status, (*1)

Bundle for storing Symfony parameters in database using Doctrine2 ORM and easy reach from Symfony Controller and twig., (*2)

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, (*3)

trinity_settings:
    settings:
        null_value: ~
        key: "value"
        group.key: "value"

Note: The dot is defined for group., (*4)

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"

The Versions