2017 © Pedro Peláez
 

library config-helper

Extends Symfony Dependency Injection Component and provides store configurations in each bundles separately by common yaml-file

image

adrenalinkin/config-helper

Extends Symfony Dependency Injection Component and provides store configurations in each bundles separately by common yaml-file

  • Friday, July 27, 2018
  • by adrenalinkin
  • Repository
  • 1 Watchers
  • 0 Stars
  • 28 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 8 Versions
  • 4 % Grown

The README.md

Config Helper На Русском

Introduction

Component allows extend standard class Symfony\Component\DependencyInjection\Extension\Extension and open possibility for collect YAML configurations across all registered bundles., (*1)

Installation

Open a command console, enter your project directory and execute the following command to download the latest stable version of this component:, (*2)

    composer require adrenalinkin/config-helper

This command requires you to have Composer install globally., (*3)

Usage examples and compare with standard methods

Let's say we have two bundles in our project. Bundles contains business-logic of the two separate system parts: * AcmeBundle with entities AcmeBundle:User and AcmeBundle:Position * AcmePostBundle with entity AcmePostBundle:Post, (*4)

Imagine you need to add configuration for each entity. Let's say we need configuration which should determine user's system role for get access to specific functionality. For the configuration creation has been created bundle AcmeConfigBundle. Configuration example:, (*5)

acme_config:
    AcmeBundle:User:     ROLE_USER_ADMIN # key - name of the entity; value - role
    AcmeBundle:Position: ROLE_USER_ADMIN
    AcmePostBundle:Post: ROLE_POST_ADMIN

Standard methods

We can put configuration into global configuration file app/config/config.yml:, (*6)

# app/config/config.yml

# other bundle's configurations

acme_config:
    AcmeBundle:User:     ROLE_USER_ADMIN
    AcmeBundle:Position: ROLE_USER_ADMIN
    AcmePostBundle:Post: ROLE_POST_ADMIN

# other bundle's configurations

Also, we can put configuration into AcmeConfigBundle bundle under specific configuration file and load that from AcmeConfigExtension:, (*7)

#Acme/ConfigBundle/Resources/config/custom.yml
acme_config:
    AcmeBundle:User:     ROLE_USER_ADMIN
    AcmeBundle:Position: ROLE_USER_ADMIN
    AcmePostBundle:Post: ROLE_POST_ADMIN

However, both of method, for our realisation, got one flaw. All time when we will create new bundles - we will need modify global configuration file or configuration file in the AcmeConfigBundle. Both situation provoke a hard-linking between separate parts of the project, (*8)

Component usage

To prevent hard-linkin between separate parts of the project you need:, (*9)

  • Choose file name for configuration store, for example acme_config.yml.
  • Extends AcmeConfigExtension from AbstractExtension:
<?php

namespace Acme\Bundle\ConfigBundle\DependencyInjection;

use Linkin\Component\ConfigHelper\Extension\AbstractExtension;

use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader;

class AcmeConfigExtension extends AbstractExtension
{
    /**
     * {@inheritdoc}
     */
    public function getAlias()
    {
        return 'acme_config';
    }

    /**
     * {@inheritdoc}
     */
    public function load(array $configs, ContainerBuilder $container)
    {
        // load all configurations from the all registered bundles
        $configs = $this->getConfigurationsFromFile('acme_config.yml', $container);
        // process received configuration
        $configs = $this->processConfiguration(new Configuration(), $configs);

        // some actions

        $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
        $loader->load('services.yml');
    }
}
  • Create configuration files per bundles:
# Acme/AcmeBundle/Resources/config/acme_config.yml
acme_config:
    AcmeBundle:User:     ROLE_USER_ADMIN
    AcmeBundle:Position: ROLE_USER_ADMIN
# AcmePost/AcmePostBundle/Resources/config/acme_config.yml
acme_config:
    AcmePostBundle:Post: ROLE_POST_ADMIN

This method allows you create and remove configurations in the bundles without global changes in the project. You can remove some configuration in the needed bundle or even remove whole bundle ( for example AcmePostBundle)., (*10)

Note: By default method getConfigurationsFromFile($fileName, ContainerBuilder $container, $merge = true) uses standard PHP function array_merge_recursive to merge all found configurations. If you want prepare configuration by yourself put false as third parameter and receive stack of the all registered configurations., (*11)

License

license, (*12)

The Versions

27/07 2018

dev-master

9999999-dev

Extends Symfony Dependency Injection Component and provides store configurations in each bundles separately by common yaml-file

  Sources   Download

MIT

The Requires

 

by Viktor Linkin

component config helper symfony yaml dependency-injection di dependencyinjection symfony-component yaml-configuration

27/07 2018

v1.0.6

1.0.6.0

Extends Symfony Dependency Injection Component and provides store configurations in each bundles separately by common yaml-file

  Sources   Download

MIT

The Requires

 

by Viktor Linkin

helper dependency-injection symfony-component yaml-configuration

20/03 2018

v1.0.5

1.0.5.0

Extends Symfony Dependency Injection Component and provides store configurations in each bundles separately by common yaml-file

  Sources   Download

MIT

The Requires

 

by Viktor Linkin

config helper yaml di dependencyinjection symfony-component

14/02 2018

v1.0.4

1.0.4.0

Extends Symfony Dependency Injection Component and provides store configurations in each bundles separately by common yaml-file

  Sources   Download

MIT

The Requires

 

by Viktor Linkin

component config helper symfony di dependencyinjection symfony-component

02/02 2018

v1.0.3

1.0.3.0

This component extends Symfony Config Component and provides store configurations in the bundles directly

  Sources   Download

MIT

The Requires

 

by Viktor Linkin

component config helper symfony2 di dependencyinjection

22/11 2017

v1.0.2

1.0.2.0

This component extends Symfony Config Component and provides store configurations in the bundles directly

  Sources   Download

MIT

The Requires

 

by Viktor Linkin

component config helper symfony2 di dependencyinjection

21/11 2017

v1.0.1

1.0.1.0

This component extends Symfony Config Component and provides store configurations in the bundles directly

  Sources   Download

MIT

The Requires

 

by Viktor Linkin

component config helper symfony2 di dependencyinjection

26/07 2017

v1.0.0

1.0.0.0

This component extends Symfony Config Component and provides store configurations in the bundles directly

  Sources   Download

MIT

The Requires

 

by Viktor Linkin

component config helper symfony2 di dependencyinjection