amazium / amz-config
Config Aggregator
Requires
- php: ^7.3
- ext-json: ^1.7
- illuminate/support: ^5.7
Requires (Dev)
- phpstan/phpstan: ^0.11.2
- phpstan/phpstan-strict-rules: ^0.11.0
- phpunit/php-invoker: ^2.0
- phpunit/phpunit: 8.0.4
- roave/security-advisories: dev-master
- squizlabs/php_codesniffer: ^3.4
- symfony/yaml: ^4.2
This package is auto-updated.
Last update: 2020-12-28 18:16:58 UTC
README
Merge config files in a tree structure. Subdirectories and files are added as keys in the returned config array.
Suppose following file structure:
- project.config.php
- dependencies/
- factories.php
- services.php
This will create a config array with contents of the project.config.php file in the root, followed by:
$config = [ // config elements from project.config.php 'dependencies' => [ 'factories' => <whatever is returned in factories.php>, 'services' => <whatever is returned in services.php>, ], ];
Currently yaml, json and php config array files are supported.
Installation
Installation via composer:
composer require amazium/amz-config
Explicit Aggregator Factory
You can explicitely tell the system which aggregator to use, you can specify a directory or file. The file needs to be parsible by the selected aggregator.
When providing a directory, the files of this extension are also included als elements of the root object. A file
named project.config.php
will have his contents in the project
key of the config array. A consequence is that
files and sub paths are on the same level in this structure, while when you have a file as root, this file acts as
the root element.
Example usage:
use Amz\Config\AggregateFactory; $aggregator = AggregatorFactory::createPhpAggregator('/path/to/project.config.php'); $config = $aggregator->aggregate(); // OR: $aggregator = AggregatorFactory::createPhpAggregator('/path/to'); $config = $aggregator->aggregate();
Lazy Aggregator Factory
It is possible to pass the root config file to the static createAggregatorByExtension
method of the
AggregatorFactory
factory. This will inflect the right aggregator from the file extension. It will then
add all config files of the same extension in the subdirectory structure.
Example usage:
use Amz\Config\AggregateFactory; $aggregator = AggregatorFactory::createAggregatorByExtension('/path/to/project.config.php'); $config = $aggregator->aggregate();