定制 dflydev/dot-access-configuration 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

dflydev/dot-access-configuration

最新稳定版本:v2.0.1

Composer 安装命令:

composer require dflydev/dot-access-configuration

包简介

Given a deep data structure representing a configuration, access configuration by dot notation.

README 文档

README

Given a deep data structure representing a configuration, access configuration by dot notation.

This library combines dflydev/dot-access-data and dflydev/placeholder-resolver to provide a complete configuration solution.

Requirements

Usage

Generally one will use an implementation of ConfigurationBuilderInterface to build ConfigurationInterface instances. For example, to build a Configuration out of a YAML file, one would use the YamlFileConfigurationBuilder:

use Dflydev\DotAccessConfiguration\YamlFileConfigurationBuilder;

$configurationBuilder = new YamlFileConfigurationBuilder('config/config.yml');
$configuration = $configurationBuilder->build();

Once created, the Configuration instance behaves similarly to a Data instance from dflydev/dot-access-data.

$configuration->set('a.b.c', 'ABC');
$configuration->get('a.b.c');
$configuration->set('a.b.e', array('A', 'B', 'C'));
$configuration->append('a.b.e', 'D');

Custom Configurations

Configuration Builders use Configuration Factories and Placeholder Resolver Factories behind the scenes in order to build a working configuration.

Under normal circumstances one should not need to do anything with the Placeholder Resolver Factory. However, one may wish to extend the default Configuration class or use an entirely different implementation altogether.

In order to build instances of custom ConfigurationInterface implementations with the standard builders, one would need to implement ConfigurationFactoryInterface and inject it into any ConfigurationBuilderInterface.

If a Configuration is declared as follows:

namespace MyProject;

use Dflydev\DotAccessConfiguration\Configuration;

class MyConf extends Configuration
{
    public function someSpecialMethod()
    {
        // Whatever you want here.
    }
}

Create the following factory:

namespace MyProject;

use Dflydev\DotAccessConfiguration\ConfigurationFactoryInterface;

class MyConfFactory implements ConfigurationFactoryInterface
{
    /**
     * {@inheritdocs}
     */
    public function create()
    {
        return new MyConf;
    }
}

To use the factory with any builder, inject it as follows:

use Dflydev\DotAccessConfiguration\YamlFileConfigurationBuilder;
use MyProject\MyConfFactory;

$configurationBuilder = new YamlFileConfigurationBuilder('config/config.yml');

// Inject your custom Configuration Factory
$configurationBuilder->setConfigurationFactory(new MyConfFactory);

// Will now build instances of MyConfFactory instead of
// the standard Configuration implementation.
$configuration = $configurationBuilder->build();

License

This library is licensed under the New BSD License - see the LICENSE file for details.

Community

If you have questions or want to help out, join us in the #dflydev channel on irc.freenode.net.

统计信息

  • 总下载量: 14.42M
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 134
  • 点击次数: 1
  • 依赖项目数: 4
  • 推荐数: 0

GitHub 信息

  • Stars: 134
  • Watchers: 2
  • Forks: 7
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2012-04-24