承接 aloframework/config 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

aloframework/config

最新稳定版本:2.0.1

Composer 安装命令:

composer require aloframework/config

包简介

Allows easy, interfaceable class configurator with the ability to change the configuration during runtime

README 文档

README

A component that allows easy object configuration with default and overriding settings

Latest release API documentation: https://aloframework.github.io/config/

License Latest Stable Version Total Downloads

dev-develop Latest release
Dev Build Status Release Build Status
Coverage Status Coverage Status

Installation

Installation is available via Composer:

composer require aloframework/config

The abstract class

AloFramework\Config\AbstractConfig is what your own library configurations should extend. It has three main private properties: $defaults holding default configuration, $custom holding custom configuration/overrides and $merged, which holds the actual configuration that will be used. Your overriding config class will populate the default array and accept any custom variables in the constructor, e.g.:

use AloFramework\Config\AbstractConfig;

class MyConfig extends AbstractConfig {

    private static $defaultConfig = ['foo'          => 'bar',
                                     'importantVar' => 'andItsValue'];

    function __construct($customConfig = []) {
        parent::__construct(self::$defaultConfig, $customConfig);
    }
}

When reading the configuration, the values are fetched from the $merged array, which is essentially an array_merge($this->defaults, $this->custom). For more information refer to the API documentation above.

The interface

You can implement the AloFramework\Config\Configurable interface in your configuration-reading class to indicate that its runtime settings can be altered using this package. The trait described below can be used to implement the required methods.

The trait

If you don't want to write your own methods you can simply include the provided AloFramework\Config\ConfigurableTrait which will implement all the methods required by the interface.

Updating the configuration

Setting an item

You can add a custom configuration key or default setting override by calling $config->set('myKey', 'myValue'), using __set() like $config->myKey = 'myValue', or simply using it like an array: $config['myKey'] = 'myValue'.

Removing an item

You can remove custom configuration via $config->remove('myKey'), or by unsetting it like an array value: unset($config['myKey']);

Reading the configuration

Specific value

You can retrieve a specific configuration item from the merged array by calling $config->get('myKey'), using __get() like $config->myKey or by using the object like an array: $config['myKey'].

The merged config

You can retrieve the merged array via $config->getAll()

The default config

For this you would use $config->getDefaultConfig()

The custom overrides

For this you would use $config->getCustomConfig().

统计信息

  • 总下载量: 400
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 5
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: Apache-2.0
  • 更新时间: 2015-10-05