2017 © Pedro Peláez
 

symfony-bundle config-access-bundle

Get/set your application config values using dot paths.

image

rch/config-access-bundle

Get/set your application config values using dot paths.

  • Thursday, August 11, 2016
  • by rch
  • Repository
  • 2 Watchers
  • 3 Stars
  • 8 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

RCHConfigAccessBundle

Build Status StyleCI SensioLabsInsight, (*1)

Retrieve final configuration values from any container-aware context., (*2)

Why?

In Symfony, when you need to get the value of any configuration (default in app/config) the answer is always parameters., (*3)

But, what about the final configuration? After that the DI container has been compiled? After that compiler passes and bundle extensions changed it or merged it with a default one?, (*4)

Actuall there is no solution excepted processing the whole configuration of a bundle each time you need it, even partially. This bundle is intended to solve this problem., (*5)

Related issues: - Symfony2 accessing variables defined in config? (Stack Overflow) - How do I read configuration settings from symfony2 config? (Stack Overflow), (*6)

Installation

Download the bundle

$ composer require rch/config-access-bundle

This command requires you to have Composer installed globally., (*7)

Enable the Bundle

Then, enable the bundle by adding it to the list of registered bundles in the app/AppKernel.php file of your project:, (*8)

// app/AppKernel.php

$bundles = array(
    // ...
    new RCH\ConfigAccessBundle\RCHConfigAccessBundle(),
);

Usage

Get configuration values

<?php

$accessor = $this->container->get('rch.config_access.accessor');

$accessor->get('security');
// array('encoders' => array(...), 'providers' => array(...), ...)

$accessor->get('framework.serializer');
// array('enabled' => true, ...)

$accessor->get('framework.serializer.enabled');
// true

$accessor->get('stof_doctrine_extensions.uploadable');
// array('orm' => array(...), 'uploadable' => array(...), ...)

$accessor->get('lexik_jwt_authentication.encoder.service'); 
// 'lexik_jwt_authentication.encoder.default'

$accessor->get('frameorf.default_locale'); 
$accessor->get('framework.default_loal');

// Did you mean "framework.default_locale"?

Inject them into your services

services:
    foo_manager:
        arguments: 
            - '@=service("rch_config_access.accessor").get("security")'
<?php

namespace AppBundle\Services;

class FooManager 
{
    public function __construct(array $security)
    {
        $this->security = $security;
    }

    // ...
}

Contributing

Guidelines, (*9)

License

The code is released under the MIT license., (*10)

For the whole copyright, see the distributed LICENSE file., (*11)

The Versions