nia / configuration
nia 组件,用于简单的配置文件解析。
此软件包的官方仓库似乎已消失,因此该软件包已被冻结。
1.0.0
2016-02-06 23:43 UTC
Requires
- php: >=7.0.0
- nia/collection-map-stringmap: *
This package is not auto-updated.
Last update: 2022-03-10 22:22:10 UTC
README
配置文件统一读取。
安装
使用 Composer 需要此软件包。
composer require nia/configuration
测试
要运行单元测试,请使用以下命令
$ cd /path/to/nia/component/
$ phpunit --bootstrap=vendor/autoload.php tests/
示例:如何使用
以下示例展示了如何使用此组件处理包含 ini 配置的字符串。它使用了 Nia\Configuration\Reader\Ini\IniStringConfiguration
类。如果你想读取 ini 文件,只需使用 Nia\Configuration\Reader\Ini\IniFileConfiguration
类。
还有一个针对 json 字符串(Nia\Configuration\Reader\Json\JsonStringConfiguration
)和 json 文件(Nia\Configuration\Reader\Json\JsonFileConfiguration
)的实现。
$content = <<<EOL [database] hostname=127.0.0.1 username=root password= port=1234 [environment] debug.mode=development debug.log=/var/log/application.log EOL; $configuration = new IniStringConfiguration($content); $hostname = $configuration->getSection('database')->get('hostname'); $debugLog = $configuration->getSection('environment')->get('debug.log');