Download the PHP package time2split/time2configure without Composer
On this page you can find all versions of the php package time2split/time2configure. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download time2split/time2configure
More information about time2split/time2configure
Files in time2split/time2configure
Package time2configure
Short Description Tree shaped configuration with text interpolation
License MIT
Informations about the package time2configure
Time2Configure
Time2Configure is a php library implementing the concept of tree configuration with value interpolations.
Configuring a program consists to get some entries from the external world, for instance by entering some command line arguments, and then to use theses entries inside the program.
Most of the time, the program does the reading of a formatted configuration (json
, ini
, etc) with some specialized format reader and then uses directly the obtained result as the program configuration.
Usefull formats for configuration storage may be json
, php
array, or other tree shapped formats.
Even a flat format like ini
or csv
can allows the usage of a hierarchical notation (eg. ) that finally defines a tree-shapped configuration.
Tree is a natural way to represent a configuration.
Time2Configure proposes a general abstraction of tree configuration, not focused on any format but rather on storage and features. Moreover, these tree configurations have the very usefull ability to use complex value interpolation languages.
Installation
The library is distributed as a Composer project.
Documentation
Some examples
To have a very first taste of the library in action let's give a first example:
Because the configuration is a tree we are able reduce the visibility of some part of a program to a specific sub-tree.
The library consider that each node of the tree can store a value, not only leaves.
Value interpolation
The second main feature, over the tree aspect is the value interpolation.
Value interpolation permits to compile automatically an entries's value to generate dynamically another value when the entry is accessed. Here is an example using the previous example's $config:
In this example we used the provided interpolator Interpolators::recursive() which substitute every ${key} token encountered in a text value by the actual $config['key'] value stored. (For now, this is the only interpolator provided by the library.)
More complex interpolated language can be made. For instance, the pcp project defines a more complex language with the help of the great parsica-php/parsica project. The [pcp interpolated language]() permits to use operators based expressions (assignments, boolean) and is even able to parse command line arguments.
The interpolation principe is simple, but let the ability to create very complex languages.
Features
- Tree shapped configurations
- Fluent tree builder
- Interpolated values
- Hierarchical configurations
- Operations and decorators to add more complex behaviours
Hierarchy of configurations
In many scenarios there is a default base configuration that the user can modify to create the final one. Time2Configure provides a solution to create a list of configurations where only the last one can be effectively modified.
More generally, this is a very usefull feature that permits to a process to immunize its configuration against modification by a sub-process without the need of copying.
Decorators
Decorators are usefull to add more behaviour to a configuration. Fo instance, the decorator Configurations::doOnRead() is able to do an action when a value is accessed.
There is also some mapping decorators that can uses the original entry values to makes new one. Here is a new examples: