rch / config-access-bundle
Get/set your application config values using dot paths.
Installs: 18
Dependents: 0
Suggesters: 0
Security: 0
Stars: 3
Watchers: 2
Forks: 1
Open Issues: 0
Type:symfony-bundle
Requires
- php: >= 5.4.0
- doctrine/collections: ~1.3
- symfony/cache: ~3.1
- symfony/config: ~2.8|~3.1
- symfony/dependency-injection: ~2.8|~3.1
- symfony/expression-language: ~2.8|~3.1
- symfony/framework-bundle: ~2.8|~3.1
- symfony/http-kernel: ~2.8|~3.1
Requires (Dev)
- friendsofphp/php-cs-fixer: ~2.0@dev
- phpunit/phpunit: ^4.5|^5.0
Suggests
- symfony/expression-language: For injecting configuration values as service arguments
This package is not auto-updated.
Last update: 2024-12-11 20:07:23 UTC
README
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:
- Symfony2 accessing variables defined in config? (Stack Overflow)
- How do I read configuration settings from symfony2 config? (Stack Overflow)
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
License
The code is released under the MIT license.
For the whole copyright, see the distributed LICENSE file.