anax / configure
Anax Configure module, for reading config files.
Installs: 19 703
Dependents: 43
Suggesters: 1
Security: 0
Stars: 0
Watchers: 2
Forks: 1
Open Issues: 0
Requires
- php: ^7.2
Requires (Dev)
- anax/di: ^2.0.4
- phpstan/phpstan: ^0.12.56
- phpunit/phpunit: ^7
This package is auto-updated.
Last update: 2024-10-20 06:26:43 UTC
README
Read configuration files for Anax and Anax modules.
The configuration files for a module can be stored in one of several base directories. The Configuration class scans all valid base directories and stops at the first one containing configuration items.
The configuration items can be stored in a file, and/or in a directory containing several files. All files are loaded and combined into one array containing each bits and piece of the module configuration.
Install
$ composer require anax/configure
Related classes
These are the classes included in this module, and their primary purpose.
Use as DI service
You can create the Configuration object as a $di service. That is how Anax does it.
Sample usage
Create a object that can read configuration files.
First create the object and point it to a set of directories.
$config = new \Anax\Configure\Configuration(); $dirs = ["path1", "path2"]; $config->setBaseDirectories($dirs);
Now use the objekt to find and load configuration files for an item, in the example we are using the module "router" as an example.
$config = $di->get("configuration")->load("route")
The $config
will now contain the configuration items found from the file, or files. You could now provide the array to the module or object that should use it.
A configuration file
A configuration file for a module "route" is any, or a combination of the following.
The files should return a value, which will be its contribution to the configuration.
The configuration array
The resulting configuration array looks like this, still using "route" as example for the module name.
$config = [ "file" => filename for route.php, "config" => result returned from route.php, "items" => [ [ "file" => filename for route/file1.php, "config" => result returned from route/file1.php, ], [ "file" => filename for route/file2.php, "config" => result returned from route/file2.php, ], ]. ];
Tha "route" module can then decide on how to use the actual configuration details.
Dependency
There are no dependencies.
License
This software carries a MIT license. See LICENSE.txt for details.
.
..: Copyright (c) 2013 - 2018 Mikael Roos, mos@dbwebb.se