rch / config-access-bundle
使用点路径获取/设置您的应用程序配置值。
v1.0.0
2016-06-04 11:59 UTC
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-09-18 19:12:52 UTC
README
从任何容器感知上下文中检索最终配置值。
为什么?
在Symfony中,当您需要获取任何配置(默认在app/config
)的值时,答案总是参数。
但是,最终配置呢?在DI容器编译之后?在编译器传递和bundle扩展更改或合并默认配置之后呢?
实际上,除了每次需要时处理整个bundle的配置之外,没有解决方案,即使只是部分。这个bundle旨在解决这个问题。
相关问题
- Symfony2访问config.yml中定义的变量?(Stack Overflow)
- 如何从symfony2 config中读取配置设置?(Stack Overflow)
安装
下载bundle
$ composer require rch/config-access-bundle
此命令要求您全局安装Composer。
启用Bundle
然后,通过将其添加到项目中app/AppKernel.php
文件中注册的bundle列表中来启用bundle
// app/AppKernel.php $bundles = array( // ... new RCH\ConfigAccessBundle\RCHConfigAccessBundle(), );
用法
获取配置值
<?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"?
注入到您的服务中
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; } // ... }
贡献
许可
代码在MIT许可证下发布。
关于完整的版权信息,请参阅分发的LICENSE文件。