assertis/config-lib
最新稳定版本:4.7.0
Composer 安装命令:
composer require assertis/config-lib
包简介
Simple configuration library
README 文档
README
Design
Configuration library enables you to load configurations into application from different source, it give you way to validate configuration on developer environment.
We are providing 5 base type of configurations.
-
Assertis\Configuration\Drivers\SourceDriver: simple driver, you can set array with configuration into constructor. -
Assertis\Configuration\Drivers\DatabaseDriver: driver is using PDO connection to gain access to configuration from database. This driver is returningLazyConfiguration. -
Assertis\Configuration\Drivers\File\IniDriver: configuration provided from.inifile -
Assertis\Configuration\Drivers\File\JsonDriver: configuration provided from.jsonfile -
Assertis\Configuration\Drivers\File\PhpDriver: configuration provided from.phpfile. File should return array -
Assertis\Configuration\Drivers\File\YmlDriver: configuration provided from.ymlfile. File should return array -
Assertis\Configuration\Drivers\File\XmlDriver: configuration provided from.xmlfile. File should return array with configuration. Ex:
<?php return [ 'key' => 'value' ]; ?>
We are returning configuration in 2 type of objects:
-
Assertis\Configuration\Collection\ConfigurationArrayis array type object with some extra methods. More detail below. -
Assertis\Configuration\Collection\LazyConfigurationis simple array type object but with many limitations. Basically you can only usegetmethod, others will throwException.
Library is also providing Assertis\Configuration\ConfigurationFactory to create configuration easily.
Extras
-
Configuration will load "common" file if exists. File extension depends of driver type. If we are using
IniDriverfor test env thencommon.iniwill be loaded if exists. -
Environment is read from
$_SERVER['ENV']orgetenv('ENV') -
When environment is default (dev) or test, configuration structure will be tested
-
You can get value using path, for example:
rdis.db.user -
When you are asking for key when value is array, this value will be changed to
Assertis\Configuration\Collection\ConfigurationArray -
You can add easily extra drivers
Installation
To install this library add the following to your composer.json file and run composer update:
"repositories": [ { "type": "vcs", "url": "https://github.com/assertis/config-lib" } ], "require": { "assertis/config-lib": "dev-master" }
Usage
To use this library add the following to your Silex application:
$app->register(new ConfigurationProvider(), [ 'config.driver' => new IniDriver($app['dir.root'] . '/configs'), 'config.validator' => $app['validator'], 'config.validator.constraints' => null ]);
Add new tenant to configuration
- First of all your service should have something called tenant schema.
- Put your regular tenant body into
config/schema/tenant.jsone.g.
{
"database": {
"order": {
"dsn": "mysql:host=127.0.0.1;dbname=",
"username": "root",
"password": ""
}
},
"nlc": "",
"barcode_key": "",
"issuer_id": ""
}
- Now in your service you should be able to add tenant to specific config file
php vendor/assertis/config-lib/src/Scripts/AddTenant.php {tenantName} {configFileName} [tenantSchemaFile]
If tenantSchemaFile is in different localization than config/schema/tenant.json please provide it as a last parameter.
E.g. of usage
php vendor/assertis/config-lib/src/Scripts/AddTenant.php hex-qa-b2b stage.json
统计信息
- 总下载量: 15.66k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-11-10