simplon/config
Composer 安装命令:
composer require simplon/config
包简介
Simple Config Reader
README 文档
README
_ _ __ _
___(_)_ __ ___ _ __ | | ___ _ __ ___ ___ _ __ / _(_) __ _
/ __| | '_ ` _ \| '_ \| |/ _ \| '_ \ / __/ _ \| '_ \| |_| |/ _` |
\__ \ | | | | | | |_) | | (_) | | | | | (_| (_) | | | | _| | (_| |
|___/_|_| |_| |_| .__/|_|\___/|_| |_| \___\___/|_| |_|_| |_|\__, |
|_| |___/
Simplon Config
Its a simple config file reader which handles namespaced config arrays.
Config file example
$app = [ 'url' => [ 'service' => '[URL_SERVICE]', 'frontend' => '[URL_FRONTEND]', ], 'database' => [ 'mysql' => [ 'localhost' => [ 'server' => 'localhost', 'database' => 'some_db', 'username' => 'rootuser', 'password' => 'rootuser' ] ], ], 'email' => [ 'host' => 'localhost', 'port' => 25, ], ];
Get data from your config file
To safe resources we access the config class via singleton pattern Config::getInstance(). By passing the config file path we inform the class which file we want to read. Now, in order to fetch an actual value we pass an existing config array index as array to getConfigKeys(['url']). As a result we would receive all values which are within the array index of url:
[ 'service' => '[URL_SERVICE]', 'frontend' => '[URL_FRONTEND]', ];
Multiple array elements will be chained together. According to that the following example will only return the string value for ['url']['service']:
use Simplon\Config\Config; $configPath = __DIR__ . '/../../config/common.config.php'; $urlService = Config::getInstance() ->setConfigPath($configPath) ->getConfigByKeys(['url', 'service']); echo $urlService; // prints "[URL_SERVICE]"
统计信息
- 总下载量: 416
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2012-10-18