Download the PHP package innmind/config without Composer
On this page you can find all versions of the php package innmind/config. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download innmind/config
More information about innmind/config
Files in innmind/config
Package config
Short Description Config schema validator
License MIT
Homepage http://github.com/Innmind/Config
Informations about the package config
Config
master |
develop |
---|---|
Library to enforce a configuration schema with an emphasis on schema visualization.
It's born after a constant struggle to build prototype definitions with symfony/config
as well as the fact prototypes can't be mixed with property definitions.
Note: a prototype is a definition allowing to repeat the sub-schema in the array, for example prototype<int>: bool
allows you to have a configuration like [1 => true, 2 => false /* etc... */]
.
Installation
Usage
To better visualize the config schema you should define it via yaml or json (or any other minimalist format). Here's an example showing the possibilities of this library:
When you call process
it will validate the $data
but also transform the data in case of set
, stream
and sequence
types by returning instances of Innmind\Immutable\Set
, Innmind\Immutable\Stream
and Innmind\Immutable\Sequence
, the $data
returned is also a Innmind\Immutable\Map
instead of a simple array in order to ease the manipulation of the config data.
The full list of keys formats you can use:
prototype<int>
will instruct to have an int as a keyprototype<int>+
will instruct to have an int as a key and to have at least one keyprototype<string>
will instruct to have an string as a keyprototype<string>+
will instruct to have an string as a key and to have at least one keyprototype<scalar>
will instruct to have an scalar as a keyprototype<scalar>+
will instruct to have an scalar as a key and to have at least one key- any other string will be considered as a key name
The full list of values formats you can use:
- any value having a
is_{type}
function, this includesint
,float
,bool
,string
,scalar
,array
,object
andresource
, can be declared optional by prefixing with a?
set<{type}>
wheretype
is any value accepted byInnmind\Immutable\Set
set<{type}>+
wheretype
is any value accepted byInnmind\Immutable\Set
and must at least have one valuestream<{type}>
wheretype
is any value accepted byInnmind\Immutable\Stream
stream<{type}>+
wheretype
is any value accepted byInnmind\Immutable\Stream
and must at least have one valuesequence
sequence+
must have at least one valueenum({typeA|typeB})
possible values separated by a|
?enum({typeA|typeB})
possible values separated by a|
but the value is optional
Extend behaviour
The formatsshowed are the one by defaults but you can easily yours, for that you need to implements either Property
then to use it: