mkomorowski/php-config
Composer 安装命令:
composer require mkomorowski/php-config
包简介
Simple class supporting different configuration values based on the environment
README 文档
README
A simple class supporting different configuration values based on the environment
Installation
The package can be installed via Composer by adding to the composer.json require block.
{ "require": { "mkomorowski/php-config": "1.0" } }
Then update application packages by running the command:
php composer.phar update
Configuration
Examples of files with application configuration options.
local.php
return array( 'debug' => true, 'database' => array( 'host' => '127.0.0.1', 'password' => 'password', ), );
production.php
return array( 'debug' => false, 'database' => array( 'host' => 'rds.amazon.com', 'password' => 'password', ), );
In the settings loader we are specifying the path to the directory with config files.
$loader = new mKomorowski\Config\Loader('/app/config');
Next we are defining the environment settings:
$environment = new mKomorowski\Config\Environments(array( 'local' => array('local', 'MacBook.local'), 'stage' => array('cent_os_stage') ));
Finally we initialize the Config class, passing settings and environments. The third paramater is an optional default environment.
$config = new mKomorowski\Config\Config($loader, $environment, 'stage');
We can change the default environment later by:
$config->setDefaultEnvironment('production');
Usage
To retrieve the settings just use:
$config->get('debug');
Accessing nested values is possible with dotted notation
$config->get('database.hostname');
If your hosts is signed to a specific environment it will return the appropriate value. If not it will look for default environment settings or return null if the key is not set.
统计信息
- 总下载量: 183
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2014-09-28