tacoberu/php-config

配置库提供了加载配置的接口。本地、用户基础、系统基础、应用基础。

dev-master 2018-04-14 01:42 UTC

This package is auto-updated.

Last update: 2024-09-17 23:17:26 UTC


README

配置库提供了加载配置的接口。本地、用户基础、系统基础、应用基础。

用例

$config = Config::createByEnvironment('doe', null, getcwd()); // doe is application name
$config->has('name'); // true
$config->required('name'); // John
$config->required('core.name'); // Andrey
$config->required('lang[5].name'); // germany
$config->required('lang[de].name'); // germany
$config->required('core'); // [ name => Andrey, age => 42 ]
$config->required('nope'); // exception
$config->get('nope'); // NULL
$config->get('nope', 'Mark'); // Mark

默认配置

$config = Config::createByEnvironment('doe', __dir__ . '/default.json', getcwd());

自解析器

$config = Config::createByEnvironment('doe', __dir__ . '/default.xml', getcwd());
$config->addParser(new XmlParser);

配置源

配置是从哪里加载的

系统

  • Linux: /etc/doe.ini
  • MacOS: /private/etc/doe.ini
  • Win: ?

用户

  • Linux: /home/current-user/.config/doe/config.ini
  • MacOS: /Users/current-user/.config/doe/config.ini
  • Win: ?

本地

./doe.ini

内置格式

  • ini
  • json

待办事项

  • 自加载器
  • 包含
  • 合并父项