rch/config-access-bundle

Get/set your application config values using dot paths.

v1.0.0 2016-06-04 11:59 UTC

This package is not auto-updated.

Last update: 2024-04-17 17:23:56 UTC


README

Build Status StyleCI SensioLabsInsight

Retrieve final configuration values from any container-aware context.

Why?

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

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?

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.

Related issues:

Installation

Download the bundle

$ composer require rch/config-access-bundle

This command requires you to have Composer installed globally.

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:

// 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

License

The code is released under the MIT license.

For the whole copyright, see the distributed LICENSE file.