xety/configurator
Composer 安装命令:
composer require xety/configurator
包简介
A simple configuration class without dependencies that use the Fluent pattern.
关键字:
README 文档
README
| Travis | Coverage | Stable Version | Downloads | PHP | License |
|---|---|---|---|---|---|
A simple configuration class without dependencies that use the Fluent pattern.
Requirement
Installation
composer require xety/configurator
Usage
The Configurator class is an abstract class, so you just need to extends it:
<?php namespace App; use Xety\Configurator\Configurator; class MyClass extends Configurator { }
If you want to setup a default configuration for your class, just do the following :
<?php class MyClass extends Configurator { protected $defaultConfig = [ 'key' => 'value', //etc ]; public function __construct() { $this->setConfig($defaultConfig); } }
Docs
Methods
| Name | Description |
|---|---|
| setConfig | Set the values to the options array. |
| getConfig | Get all the options with their values. |
| flushConfig | Flush a list of options from the config array. |
| mergeConfig | Merge the values to the options array. |
| clearConfig | Clear all options stored. |
| setOption | Set a value to the given option. |
| getOption | Get an option value. |
| hasOption | Check if the option exist. |
| flushOption | Flush an option. |
| pushOption | Push the listed args to the named option. |
| consumeOption | Read then flush an option. |
| transientOption | Adds a transient configuration key/value. |
Configurator::setConfig
public setConfig (array $values)
Description
Set the values to the options array. This function will replace all the configuration options.
Parameters
(array) $values: The values to push into the config.
Return Values
\Xety\Configurator\Configurator::class
Configurator::getConfig
public getConfig (void)
Description
Get all the options with their values.
Parameters
This function has no parameters.
Return Values
array
Configurator::flushConfig
public flushConfig (string ...$filter)
Description
Flush a list of options from the options array.
Usage:
$this->flushConfig('key1', 'key2', 'key3');
Parameters
(string) ...$filter: All the options to remove from the config.
Return Values
\Xety\Configurator\Configurator::class
Configurator::mergeConfig
public mergeConfig (array $values, bool $invert = false)
Description
Merge the values to the options array.
Parameters
(array) $values: The values to merge in the config.(bool) $invert: Invert the merge by merging the actual config into the values.
Return Values
\Xety\Configurator\Configurator::class
Configurator::clearConfig
public clearConfig (void)
Description
Clear all options stored.
Parameters
This function has no parameters.
Return Values
\Xety\Configurator\Configurator::class
Configurator::setOption
public setOption (string $name, mixed $value)
Description
Set a value to the given option.
Usage:
$this->setOption('key', 'value'); $this->setOption('key', ['key2' => ['value2']]);
Parameters
(string) $name: The option name.(mixed) $value: The option value.
Return Values
\Xety\Configurator\Configurator::class
Configurator::getOption
public getOption (string $name)
Description
Get an option value.
Usage:
$this->getOption('key');
Parameters
(string) $name: The option name to to get.
Return Values
mixed
Configurator::hasOption
public hasOption (string $name)
Description
Check if the option exist.
Parameters
(string) $name: The option name to check.
Return Values
bool
Configurator::flushOption
public flushOption (string $name)
Description
Flush an option.
Parameters
(string) $name: The name of the option to flush.
Return Values
\Xety\Configurator\Configurator::class
Configurator::pushOption
public pushOption (string $name, array $args)
Description
Push the listed args to the named option.
Usage:
$this->pushOption('key', ['key1' => 'value1'], ['key2' => ['value2' => 'value3']]);
Result:
'key' => [ 'key1' => 'value1', 'key2' => [ 'value2' => 'value3' ] ]
Parameters
(string) $name: The name of the option.(array) $args: A list of values to push into the option key.
Return Values
\Xety\Configurator\Configurator::class
Configurator::consumeOption
public consumeOption (string $name)
Description
Read then flush an option. Exemple:
Config:
$config = [ 'key1' => 'value1' ];
Usage:
$result = $this->consumeOption('key1');
Result:
echo $result; // value1 var_dump($config); // []
Parameters
(string) $name: The name of the option to read then flush.
Return Values
mixed
Configurator::transientOption
public transientOption (string $name, mixed $value)
Description
Adds a transient configuration key/value.
Usage:
// Will update the value of the key `key` if it exist, // or it will create it with the value `value`. $this->transientOption('key', 'value');
Parameters
(string) $name: The name of the option.(mixed) $value: The value to set.
Return Values
\Xety\Configurator\Configurator::class
Contribute
If you want to contribute, please follow this guide.
xety/configurator 适用场景与选型建议
xety/configurator 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 457.93k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2017 年 06 月 02 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「configuration」 「fluent」 「config」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 xety/configurator 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 xety/configurator 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 xety/configurator 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Configuration component
Presentation and Formatting helper with nice fluent interface.
A Zend Framework module to quickly and easily set PHP settings.
Traits gathering fluent syntax common methods
A modern, fluent HTTP client. Forked from Mashape, reimagined by Nidux, and open-sourced for the PHP community.
A fluent PHP CURL wrapper
统计信息
- 总下载量: 457.93k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 20
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-06-02