assertis / config-lib
Simple configuration library
Installs: 15 656
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 19
Forks: 0
Open Issues: 5
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
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.ini
file -
Assertis\Configuration\Drivers\File\JsonDriver
: configuration provided from.json
file -
Assertis\Configuration\Drivers\File\PhpDriver
: configuration provided from.php
file. File should return array -
Assertis\Configuration\Drivers\File\YmlDriver
: configuration provided from.yml
file. File should return array -
Assertis\Configuration\Drivers\File\XmlDriver
: configuration provided from.xml
file. File should return array with configuration. Ex:
<?php return [ 'key' => 'value' ]; ?>
We are returning configuration in 2 type of objects:
-
Assertis\Configuration\Collection\ConfigurationArray
is array type object with some extra methods. More detail below. -
Assertis\Configuration\Collection\LazyConfiguration
is simple array type object but with many limitations. Basically you can only useget
method, 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
IniDriver
for test env thencommon.ini
will 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.json
e.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