Anax Configure module, for reading config files.

v2.0.1 2020-11-19 21:51 UTC


Latest Stable Version Join the chat at

Build Status CircleCI

Build Status Scrutinizer Code Quality Code Coverage

PHPStan Maintainability Codacy Badge

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.


$ composer require anax/configure

Related classes

These are the classes included in this module, and their primary purpose.

Class Purpose
Configuration Read configuration files and store in array.

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"];

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.

File/path What
route.php A file.
route/*.php Several files.

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.


There are no dependencies.


This software carries a MIT license. See LICENSE.txt for details.

..:  Copyright (c) 2013 - 2018 Mikael Roos,