assertis / config-lib
简单的配置库
Requires
- php: ^7.0
- ext-json: *
- monolog/monolog: ^1.17
- pimple/pimple: ^3.0
- symfony/validator: ^3.0
- symfony/yaml: ^2.8 | ^3.0
Requires (Dev)
- phpunit/phpunit: ^5.2
- symfony/http-foundation: ^3.3
- symfony/var-dumper: *
- dev-master
- 4.7.0
- 4.6.6
- 4.6.5
- 4.6.4
- 4.6.3
- 4.6.2
- 4.6.1
- 4.6.0
- 4.5.0
- 4.4.3
- 4.4.2
- 4.4.1
- 4.4.0
- 4.3.0
- 4.2.5
- 4.2.3
- 4.2.2
- 4.2.1
- 4.2.0
- 4.1.1
- 4.1.0
- 4.0.3
- 4.0.2
- 4.0.1
- 4.0.0
- 3.2.3
- 3.2.2
- 3.2.1
- 3.2.0
- 3.1.0
- 3.0.0
- 2.1.0
- 2.0.3
- 2.0.2
- 2.0.1
- 2.0.0
- 1.5.0
- 1.4.3
- v1.4.2
- v1.4.1
- v1.4.0
- v1.3.1
- v1.3.0
- v1.2.1
- v1.2.0
- v1.1.0
- v1.0.1
- 1.0.0
- dev-dependabot/add-v2-config-file
- dev-dependabot/composer/phpunit/phpunit-tw-5.2or-tw-6.0
- dev-dependabot/composer/phpunit/phpunit-tw-5.2or-tw-8.0
- dev-dependabot/composer/symfony/http-foundation-tw-3.3or-tw-4.0
- dev-dependabot/composer/symfony/validator-tw-3.0or-tw-4.0
- dev-pies/default-tenant
- dev-lnowak/do-not-require-tenant
- dev-core-1292
This package is auto-updated.
Last update: 2022-09-08 12:28:43 UTC
README
设计
配置库允许您从不同的来源将配置加载到应用程序中,它提供了在开发者环境中验证配置的方法。
我们提供了5种基本配置类型。
-
Assertis\Configuration\Drivers\SourceDriver
:简单驱动,您可以在构造函数中将配置数组设置到其中。 -
Assertis\Configuration\Drivers\DatabaseDriver
:使用PDO连接从数据库中获取配置的驱动。此驱动返回LazyConfiguration
。 -
Assertis\Configuration\Drivers\File\IniDriver
:从.ini
文件提供的配置 -
Assertis\Configuration\Drivers\File\JsonDriver
:从.json
文件提供的配置 -
Assertis\Configuration\Drivers\File\PhpDriver
:从.php
文件提供的配置。文件应返回数组 -
Assertis\Configuration\Drivers\File\YmlDriver
:从.yml
文件提供的配置。文件应返回数组 -
Assertis\Configuration\Drivers\File\XmlDriver
:从.xml
文件提供的配置。文件应返回包含配置的数组。例如:
<?php return [ 'key' => 'value' ]; ?>
我们以两种类型的对象返回配置
-
Assertis\Configuration\Collection\ConfigurationArray
是具有一些额外方法的数组类型对象。更多详细信息请见下文。 -
Assertis\Configuration\Collection\LazyConfiguration
是简单的数组类型对象,但有许多限制。基本上,您只能使用get
方法,其他方法将抛出Exception
。
库还提供了Assertis\Configuration\ConfigurationFactory
以方便地创建配置。
额外功能
-
如果存在,配置将加载“common”文件。文件扩展名取决于驱动类型。如果我们使用
IniDriver
进行测试环境,则如果存在,将加载common.ini
。 -
环境从
$_SERVER['ENV']
或getenv('ENV')
读取 -
当环境为默认(开发)或测试时,将测试配置结构
-
您可以使用路径获取值,例如:
rdis.db.user
-
当您请求值是数组时的键,此值将更改为
Assertis\Configuration\Collection\ConfigurationArray
-
您可以轻松地添加额外的驱动
安装
要安装此库,请将以下内容添加到您的composer.json
文件中,并运行composer update
"repositories": [ { "type": "vcs", "url": "https://github.com/assertis/config-lib" } ], "require": { "assertis/config-lib": "dev-master" }
使用
要使用此库,请将以下内容添加到您的Silex应用程序中
$app->register(new ConfigurationProvider(), [ 'config.driver' => new IniDriver($app['dir.root'] . '/configs'), 'config.validator' => $app['validator'], 'config.validator.constraints' => null ]);
将新租户添加到配置
- 首先,您的服务应该有一些称为租户模式的东西。
- 将您的常规租户体放入
config/schema/tenant.json
中,例如。
{ "database": { "order": { "dsn": "mysql:host=127.0.0.1;dbname=", "username": "root", "password": "" } }, "nlc": "", "barcode_key": "", "issuer_id": "" }
- 现在在您的服务中,您应该能够将租户添加到特定的配置文件中
php vendor/assertis/config-lib/src/Scripts/AddTenant.php {tenantName} {configFileName} [tenantSchemaFile]
如果tenantSchemaFile与config/schema/tenant.json
在不同的本地化中,请将其作为最后一个参数提供。例如使用方法:
php vendor/assertis/config-lib/src/Scripts/AddTenant.php hex-qa-b2b stage.json