eig / configurator
此包已被弃用且不再维护。未建议替代包。
PHP 通用配置对象
2.1.0
2019-11-13 23:17 UTC
Requires
- php: >=7.2
- illuminate/config: ^6.5
- symfony/finder: ^4.3
- tightenco/collect: ^6.5
Requires (Dev)
- mockery/mockery: ^1.2.2
- php-coveralls/php-coveralls: 2.1.*
- phpunit/phpunit: ^8
- symfony/var-dumper: ^4.3
This package is auto-updated.
Last update: 2021-06-01 18:50:26 UTC
README
PHP 包配置加载器
此包是一个独立的库,允许您轻松设置并访问您自己的 PHP 包中的配置变量。
支持
PHP
- 7.2
- 7.3
安装
composer require eig/configurator
使用方法
在您的应用程序中包含 Configurator 类
use eig\Configurator\Configurator as Config;
现在实例化一个副本
$config = new Config("path/to/files");
或加载一个值数组
$config = new Config($array, $key); 您可以混合和匹配加载配置值的方法。
现在您可以通过配置对象使用点符号引用从提供的文件中加载的配置变量
$config->get('app.name');
您还可以访问几个方法: all() -> 返回所有项目 get($key) -> 返回键处的项目,可能使用点符号 has($key) -> 返回布尔值(True/False)如果值存在,可能使用点符号 load($value, $key) -> 将更多值加载到配置对象中,**注意: $key 仅在添加值数组时需要。对于添加文件,文件名用作顶级键。
外观
要通过外观使用库,请使用 eig\Configurator\Facades\Configurator 然后在您的代码中,您可以像这样加载和访问配置值
/** * This mehtod is required first to access any configuration values * Failing to load first will return a null to any calls to items() or get() */ Configurator::load($path); /** * This method will return all items that are loaded as an array. */ Configurator::all(); /** * This method will return the item you specify just like using the array notation on a * regular Configurator instance */ Configurator::get($value); /** * This method will return true or false if the value exists in the config object */ Configurator::has($value); /** * This method sets the value provided to the key */ Configurator::set($key, $value)
贡献
要为此项目做出贡献,请克隆 GitHub 仓库,为要创建的功能或要修复的错误创建一个新分支。编写测试以证明您的功能或错误修复有效,然后在 GitHub 上提交拉取请求。