donsimon/alt-brite-config
Composer 安装命令:
composer require donsimon/alt-brite-config
包简介
A simple PHP INI (or plain array) configuration class with dot-notation access
关键字:
README 文档
README
A simple PHP INI (or plain array) configuration class with dot-notation access
- Parses both INI files and PHP arrays
- Deals allows for configuration inheritance
- Available via Composer / Packagist
Usage
You need a configuration file. Example .ini contents:
[default]
database.host = bar
database.user = foo
database.pass = baz
service.api_key = 123456
email = test@dev.com
[staging:default]
database.user = foo2
database.pass = baz2
[production:staging]
database.user = foo1
database.pass = baz1
email = test@production.com
Or alternatively, if you prefer plain PHP arrays:
<?php $config['default']['database']['host'] = 'bar'; $config['default']['database']['user'] = 'foo'; $config['default']['database']['pass'] = 'baz'; $config['default']['service']['api_key'] = '123456'; $config['default']['email'] = 'test@dev.com'; $config['production']['extends'] = 'staging'; $config['production']['database']['user'] = 'foo1'; $config['production']['database']['pass'] = 'baz1'; $config['production']['email'] = 'test@production.com'; $config['staging']['extends'] = 'default'; $config['staging']['database']['user'] = 'foo2'; $config['staging']['database']['pass'] = 'baz2';
If you want to use the 'registry', register your configuration file during bootstrap:
<?php use Brite\Config\Config; // Registering as the 'default' config means you can grab the config // without specifying a name. Config::register('default', __DIR__ . '/test_config/config.php', 'staging');
Then access your configuration when required:
<?php use Brite\Config\Config; // This grabs the config registered as 'default' $config = Config::instance(); echo $config->get('database.host'); // output: "bar" echo $config->get('database.user'); // output: "foo1"
Alternatively, if you have multiple configuration files, you may name your configuration something other than 'default' during bootstrap, and access it via:
<?php use Brite\Config\Config; // This grabs the config registered as 'database' $dbConfig = Config::instance('database'); echo $dbConfig->get('host'); echo $dbConfig->get('user');
However, we all know that global access is bad, right? You can create your own instance to contain your configuration, rather than using a global static registry:
<?php use Brite\Config\IniConfig; $config = new IniConfig('/path/to/file.ini', 'staging'); // Now register $config with your registry
... and that's it. Simple!
统计信息
- 总下载量: 21
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-06-06