getsky/phalcon-config-loader
Composer 安装命令:
composer require getsky/phalcon-config-loader
包简介
Component to load configuration from various files
关键字:
README 文档
README
ConfigLoader - it's manager configuration files for Phalcon. It allows you to create a configuration of various formats (ini, yaml, JSON, PHP arrays or any other, for which you will add adapter) via a single method.
$configYml = $configLoader->create('config.yml'); $configIni = $configLoader->create('config.ini'); $configPhp = $configLoader->create('config.php'); // or use string $string = 'foo = bar' $configFromText = $configLoader->fromText($string, 'ini'); // or use arrays $config = ['foo' => 'bar']; $configFromArray = $configLoader->fromArray($config);
ConfigLoader is able to track %environment% in configuration files and replace it on our environment.
// Create ConfigLoader and specify the environment of our application $configLoader = new ConfigLoader('prod'); // config.yml : test: %environment% $configYml = $configLoader->create('config.yml'); echo $configYml->test; // print: prod
To add your adapter, you must call add () with transfer expansion and adapter class,
which must inherit a class Phalcon\Config:
$config = $configLoader->add('xml', 'MyNamespace/XmlConfig');
Moreover, you can merge configuration files:
#config.ini [test] test = true %res% = import.ini exp = %res:import.ini %class% = Test/Class::SERVICES import-class = %class:Test/Class::SERVICES
#import.ini import = "test"
namespace Test; class Class { const SERVICES = '/const.ini'; }
#const.ini class = "class"
The result loading configuration from config.ini:
[
'test' => [
'test' => true,
'import' => true,
'env' => 'dev',
'exp' => [
'import' => true,
'env' => 'dev'
],
'class' => "class",
'impot-class' => [
'class' => "class"
]
]
]
Declared variables in the parent file will not be replaced by variables from the child (only %res% or %class%):
# /app/config/config.ini %res% = include.ini [foo] test = config-test
# /app/config/include.ini [foo] test = test bar = bar
# result [foo] test = config-test bar = bar
If you do not want to import resources (loading of the other configuration files in this configuration), the second parameter must pass a boolean false :
$config = $configLoader->create('config.ini', false);
统计信息
- 总下载量: 449
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 0
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2014-01-27