2017 © Pedro Peláez
 

symfony-bundle settings-bundle

A bundle for Symfony2/3 that simplifies retrieving settings from config files and Doctrine entities

image

vkr/settings-bundle

A bundle for Symfony2/3 that simplifies retrieving settings from config files and Doctrine entities

  • Saturday, April 15, 2017
  • by wladislavk
  • Repository
  • 1 Watchers
  • 0 Stars
  • 129 Installations
  • PHP
  • 5 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 5 Versions
  • 0 % Grown

The README.md

About

This is a simple bundle that aims to simplify the process of getting Symfony project settings from different places. Currently it supports two sources of settings: a config file or an entity under control of Doctrine. Note that this bundle requires Doctrine to work., (*1)

Installation

The only thing you need to do prior to using this bundle is to define the entity. If you will always be using parameter-based settings, you can skip this completely., (*2)

To create an entity supported by this bundle, you need to create a Doctrine entity class that would implement VKR\SettingsBundle\Interfaces\SettingsEntityInterface and define two of its methods, getName() and getValue(), both of those must return strings., (*3)

Then, you need to create a parameter called settings_entity in your config file, it must contain the fully qualified name of your entity, e.g., (*4)

settings_entity: 'AppBundle\Entity\Settings', (*5)

Please note that the following entry will NOT work:, (*6)

settings_entity: 'AppBundle:Settings', (*7)

That's it., (*8)

Usage

First, create a SettingsRetriever service object. Then, use its get() method with your setting name as an argument. The script will first try to get a parameter with that key from your config file. If there is none, it will try to find a DB record with name parameter equal to get() method's argument and then use getValue() on it. Otherwise, it will through a VKR\SettingsBundle\Exception\SettingNotFoundException., (*9)

Example (should be run from a controller):, (*10)

$settingsRetriever = $this->get('vkr_settings.settings_retriever');
try {
    $mySetting = $settingsRetriever->get('my_setting');
} catch (VKR\SettingsBundle\Exception\SettingNotFoundException $e) {
    // do something
}

API

*void SettingsRetriever::__construct(Container $container, EntityManager $em)*, (*11)

Container and entity manager should be injected if initialized manually, (*12)

string SettingsRetriever::get(string $settingName, bool $suppressErrors=false), (*13)

If the second argument is set to true, the method will return false if the setting is not found instead of throwing an exception., (*14)

string[] SettingsRetriever::getAllFromDB(), (*15)

Will try to retrieve all objects from the settings entity as a key-value array. If the entity is not set, will return empty array. This method will ignore all parameters-based settings., (*16)

The Versions

15/04 2017

dev-master

9999999-dev https://github.com/wladislavk/SettingsBundle

A bundle for Symfony2/3 that simplifies retrieving settings from config files and Doctrine entities

  Sources   Download

MIT

The Requires

 

The Development Requires

by Vladislav Kryshtanovskiy

settings configuration symfony2 symfony3

15/04 2017

1.1.2

1.1.2.0 https://github.com/wladislavk/SettingsBundle

A bundle for Symfony2/3 that simplifies retrieving settings from config files and Doctrine entities

  Sources   Download

MIT

The Requires

 

The Development Requires

by Vladislav Kryshtanovskiy

settings configuration symfony2 symfony3

23/03 2017

1.1.1

1.1.1.0 https://github.com/wladislavk/SettingsBundle

A bundle for Symfony2/3 that simplifies retrieving settings from config files and Doctrine entities

  Sources   Download

MIT

The Requires

 

The Development Requires

by Vladislav Kryshtanovskiy

settings configuration symfony2 symfony3

21/07 2016

1.1.0

1.1.0.0 https://github.com/wladislavk/SettingsBundle

A bundle for Symfony2/3 that simplifies retrieving settings from config files and Doctrine entities

  Sources   Download

MIT

The Requires

 

The Development Requires

by Vladislav Kryshtanovskiy

settings configuration symfony2 symfony3

17/07 2016

1.0.0

1.0.0.0 https://github.com/wladislavk/SettingsBundle

A bundle for Symfony2/3 that simplifies retrieving settings from config files and Doctrine entities

  Sources   Download

MIT

The Requires

 

The Development Requires

by Vladislav Kryshtanovskiy

settings configuration symfony2 symfony3