2017 © Pedro Peláez
 

symfony-bundle config-bundle

Bundles provides tools that allow to you to dynamically store and fetch your configuration properties in a flexible way.

image

modera/config-bundle

Bundles provides tools that allow to you to dynamically store and fetch your configuration properties in a flexible way.

  • Sunday, November 26, 2017
  • by modera
  • Repository
  • 5 Watchers
  • 0 Stars
  • 3,603 Installations
  • PHP
  • 4 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 24 Versions
  • 0 % Grown

The README.md

ModeraConfigBundle

Bundles provides tools that allow to you to dynamically store and fetch your configuration properties in a flexible way. You can store any type of configuration property - your configuration property can store both simple values (like string, integers, arrays) or complex ones - like objects or references to entities, this is achieved by using so called "Handlers" (implementations of \Modera\ConfigBundle\Config\HandlerInterface)., (*1)

Installation

Step 1: Download the Bundle

``` bash composer require modera/config-bundle:4.x-dev, (*2)


This command requires you to have Composer installed globally, as explained in the [installation chapter](https://getcomposer.org/doc/00-intro.md) of the Composer documentation. ### Step 2: Enable the Bundle This bundle should be automatically enabled by [Flex](https://symfony.com/doc/current/setup/flex.html). In case you don't use Flex, you'll need to manually enable the bundle by adding the following line in the `config/bundles.php` file of your project: ``` php <?php // config/bundles.php return [ // ... Modera\ConfigBundle\ModeraConfigBundle::class => ['all' => true], ];

Publishing configuration properties

Before you can use your configuration properties you need to publish them. Publishing process consists of several steps:, (*3)

  1. Create a provider class.
  2. Register your provides class in service container with "modera_config.config_entries_provider" tag.
  3. Use modera:config:install-config-entries command to publish exposed configuration entries.

This is how a simple provider class could look like:, (*4)

``` php <?php, (*5)

namespace MyCompany\SiteBundle\Contributions;, (*6)

use Modera\ConfigBundle\Config\ConfigurationEntryDefinition as CED; use Sli\ExpanderBundle\Ext\ContributorInterface;, (*7)

class ConfigEntriesProvider implements ContributorInterface { private $em;, (*8)

public function __construct(EntityManager $em)
{
    $this->em = $em;
}

/**
 * {@inheritdoc}
 */
public function getItems()
{
    $serverConfig = array(
        'id' => 'modera_config.entity_repository_handler'
    );

    $admin = $this->em->find('MyCompany\SecurityBundle\Entity\User', 1);

    return array(
        new CED('admin_user', 'Site administrator', $admin)
    );
}

}, (*9)


Once you have a class you need to register it in a service container: ``` xml <services> <service id="my_company_site.contributions.config_entries_provider" class="MyCompany\SiteBundle\Contributions\ConfigEntriesProvider"> <tag name="modera_config.config_entries_provider" /> </service> </services>

Now we can use modera:config:install-config-entries to publish our configuration property., (*10)

Fetching configuration properties

In order to fetch a configuration property in your application code you need to use modera_config.configuration_entries_manager service., (*11)

``` php <?php, (*12)

/* @var \Modera\ConfigBundle\Manager\ConfigurationEntriesManagerInterface $service */ $service = $container->get('modera_config.configuration_entries_manager');, (*13)

/* @var \Modera\ConfigBundle\Config\ConfigurationEntryInterface $entry */ $entry = $service->findOneByNameOrDie('admin_user');, (*14)

// will yield "MyCompany\SecurityBundle\Entity\User" echo get_class($property->getValue());, (*15)


## Twig integration The bundle also provides integration with Twig that allow you to fetch configuration properties' values from your template. For this you will want to use `modera_config_value` function: ``` twig {{ modera_config_value("my_property_name") }}

This will print value for "my_property_name" configuration property. By default if no given configuration property is found then exception is thrown but you can change this behaviour by passing FALSE as second argument to the function and in this case NULL be returned instead of throwing an exception., (*16)

As you will read later in this document the bundle also has support for associating configuration entries with users. To fetch a user specific configuration property from a template use modera_config_owner_value, for example:, (*17)

``` twig {{ modera_config_value("my_property_name", app.user) }}, (*18)


## Handlers By default the bundle is capable of storing these types of values: * string * text * float * array * boolean * references to entities If you need to store some more complex values then you need to implement `\Modera\ConfigBundle\Config\HandlerInterface` interface. Please see already shipped implementations (`\Modera\ConfigBundle\Config\EntityRepositoryHandler`, for example) to see how you can create your own handlers. ## Creating user related configuration entries Sometimes you may want to store configuration entries which are not related to the system as a whole but instead to one single user, for example - user's preferred admin panel language. To achieve this you need to use `modera_config/owner_entity` semantic configuration key to specify a fully qualified name of user entity. For example: ``` yaml modera_config: owner_entity: "Modera\SecurityBundle\Entity\User"

Once owner_entity is configured don't forget to update your database schema by running doctrine:schema:update --force., (*19)

Now that we have proper configuration in place and database schema has been updated when creating new configuration entries you can specify "owner", for example:, (*20)

``` php <?php, (*21)

$bob = new \Modera\SecurityBundle\Entity\User(); // ... configure and persist $bob, (*22)

$ce = new ConfigurationEntry(); $ce->setOwner($myUser);, (*23)

$manager->save($ce); ```, (*24)

Hints

In your application code when working with components from ModeraConfigBundle you should rely on interfaces instead of implementations, that is, when you use modera_config.configuration_entries_manager rely on \Modera\ConfigBundle\Manager\ConfigurationEntriesManagerInterface and when working with configuration entries rely on \Modera\ConfigBundle\Manager\ConfigurationEntryInterface this way you will make your code portable. By default the bundle uses Doctrine ORM to store values for configuration entries but later some more storage mechanism may be added and if you rely on interfaces then you won't need to update your code to leverage new possible storage engines., (*25)

Licensing

This bundle is under the MIT license. See the complete license in the bundle: Resources/meta/LICENSE, (*26)

The Versions

26/11 2017

dev-sf3

dev-sf3

Bundles provides tools that allow to you to dynamically store and fetch your configuration properties in a flexible way.

  Sources   Download

MIT

The Requires

 

The Development Requires

02/01 2017

dev-master

9999999-dev

Bundles provides tools that allow to you to dynamically store and fetch your configuration properties in a flexible way.

  Sources   Download

MIT

The Requires

 

The Development Requires

02/01 2017

dev-MPFE-963

dev-MPFE-963

Bundles provides tools that allow to you to dynamically store and fetch your configuration properties in a flexible way.

  Sources   Download

MIT

The Requires

 

The Development Requires

02/01 2017

dev-MPFE-975

dev-MPFE-975

Bundles provides tools that allow to you to dynamically store and fetch your configuration properties in a flexible way.

  Sources   Download

MIT

The Requires

 

The Development Requires

02/01 2017

dev-MPFE-977

dev-MPFE-977

Bundles provides tools that allow to you to dynamically store and fetch your configuration properties in a flexible way.

  Sources   Download

MIT

The Requires

 

The Development Requires

02/01 2017

v2.54.0

2.54.0.0

Bundles provides tools that allow to you to dynamically store and fetch your configuration properties in a flexible way.

  Sources   Download

MIT

The Requires

 

The Development Requires

02/01 2017

dev-MPFE-1005

dev-MPFE-1005

Bundles provides tools that allow to you to dynamically store and fetch your configuration properties in a flexible way.

  Sources   Download

MIT

The Requires

 

The Development Requires

02/01 2017

dev-MPFE-1007

dev-MPFE-1007

Bundles provides tools that allow to you to dynamically store and fetch your configuration properties in a flexible way.

  Sources   Download

MIT

The Requires

 

The Development Requires

02/01 2017

dev-MPFE-1014

dev-MPFE-1014

Bundles provides tools that allow to you to dynamically store and fetch your configuration properties in a flexible way.

  Sources   Download

MIT

The Requires

 

The Development Requires

02/01 2017

dev-MPFE-1017

dev-MPFE-1017

Bundles provides tools that allow to you to dynamically store and fetch your configuration properties in a flexible way.

  Sources   Download

MIT

The Requires

 

The Development Requires

02/01 2017

v2.55.0

2.55.0.0

Bundles provides tools that allow to you to dynamically store and fetch your configuration properties in a flexible way.

  Sources   Download

MIT

The Requires

 

The Development Requires

02/01 2017

dev-MPFE-1014-2

dev-MPFE-1014-2

Bundles provides tools that allow to you to dynamically store and fetch your configuration properties in a flexible way.

  Sources   Download

MIT

The Requires

 

The Development Requires

02/01 2017

dev-MPFE-1029

dev-MPFE-1029

Bundles provides tools that allow to you to dynamically store and fetch your configuration properties in a flexible way.

  Sources   Download

MIT

The Requires

 

The Development Requires

02/01 2017

dev-direct-bundle-csrf

dev-direct-bundle-csrf

Bundles provides tools that allow to you to dynamically store and fetch your configuration properties in a flexible way.

  Sources   Download

MIT

The Requires

 

The Development Requires

02/01 2017

v2.56.0

2.56.0.0

Bundles provides tools that allow to you to dynamically store and fetch your configuration properties in a flexible way.

  Sources   Download

MIT

The Requires

 

The Development Requires

02/01 2017

dev-crub_pagination_fetch_fix

dev-crub_pagination_fetch_fix

Bundles provides tools that allow to you to dynamically store and fetch your configuration properties in a flexible way.

  Sources   Download

MIT

The Requires

 

The Development Requires

05/09 2016

2.x-dev

2.9999999.9999999.9999999-dev

Bundles provides tools that allow to you to dynamically store and fetch your configuration properties in a flexible way.

  Sources   Download

MIT

The Requires

 

The Development Requires

05/09 2016

v2.52.0

2.52.0.0

Bundles provides tools that allow to you to dynamically store and fetch your configuration properties in a flexible way.

  Sources   Download

MIT

The Requires

 

The Development Requires

05/09 2016

v2.52.1

2.52.1.0

Bundles provides tools that allow to you to dynamically store and fetch your configuration properties in a flexible way.

  Sources   Download

MIT

The Requires

 

The Development Requires

05/09 2016

v2.52.2

2.52.2.0

Bundles provides tools that allow to you to dynamically store and fetch your configuration properties in a flexible way.

  Sources   Download

MIT

The Requires

 

The Development Requires

05/09 2016

v2.53.0

2.53.0.0

Bundles provides tools that allow to you to dynamically store and fetch your configuration properties in a flexible way.

  Sources   Download

MIT

The Requires

 

The Development Requires

22/07 2016

v2.0.50

2.0.50.0

Bundles provides tools that allow to you to dynamically store and fetch your configuration properties in a flexible way.

  Sources   Download

MIT

The Requires

 

The Development Requires

22/07 2016

v2.51.0

2.51.0.0

Bundles provides tools that allow to you to dynamically store and fetch your configuration properties in a flexible way.

  Sources   Download

MIT

The Requires

 

The Development Requires

22/07 2016

v2.51.1

2.51.1.0

Bundles provides tools that allow to you to dynamically store and fetch your configuration properties in a flexible way.

  Sources   Download

MIT

The Requires

 

The Development Requires