2017 © Pedro Peláez
 

library config

Config schema validator

image

innmind/config

Config schema validator

  • Monday, April 2, 2018
  • by Baptouuuu
  • Repository
  • 0 Watchers
  • 0 Stars
  • 11 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 0 % Grown

The README.md

Config

master develop
Scrutinizer Code Quality Scrutinizer Code Quality
Code Coverage Code Coverage
Build Status Build Status

Library to enforce a configuration schema with an emphasis on schema visualization., (*1)

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., (*2)

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... */]., (*3)

Installation

composer require innmind/config

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:, (*4)

# schema.yml
prototype<string>:
    type: string
    alias: '?string'
    repository: '?string'
    factory: '?string'
    labels: set<string>
    identity:
        property: string
        type: string
    properties:
        prototype<string>:
            type: string
            prototype<scalar>: mixed
use Innmind\Config\Config;
use Symfony\Component\Yaml\Yaml;

$config = (new Config)->build(Yaml::parseFile('schema.yml'));
$data = $config->process($data);

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., (*5)

The full list of keys formats you can use:, (*6)

  • prototype<int> will instruct to have an int as a key
  • prototype<int>+ will instruct to have an int as a key and to have at least one key
  • prototype<string> will instruct to have an string as a key
  • prototype<string>+ will instruct to have an string as a key and to have at least one key
  • prototype<scalar> will instruct to have an scalar as a key
  • prototype<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:, (*7)

  • any value having a is_{type} function, this includes int, float, bool, string, scalar, array, object and resource, can be declared optional by prefixing with a ?
  • set<{type}> where type is any value accepted by Innmind\Immutable\Set
  • set<{type}>+ where type is any value accepted by Innmind\Immutable\Set and must at least have one value
  • stream<{type}> where type is any value accepted by Innmind\Immutable\Stream
  • stream<{type}>+ where type is any value accepted by Innmind\Immutable\Stream and must at least have one value
  • sequence
  • sequence+ must have at least one value
  • enum({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 Structure or Property then to use it:, (*8)

$config = new Config(
    new Structures(
        ...Structures::defaults()->add(MyStructure::class)
    ),
    new Properties(
        ...Properties::defaults()->add(MyProperty::class)
    )
);

The Versions

02/04 2018

dev-master

9999999-dev http://github.com/Innmind/Config

Config schema validator

  Sources   Download

MIT

The Requires

 

The Development Requires

config validator

02/04 2018

1.1.0

1.1.0.0 http://github.com/Innmind/Config

Config schema validator

  Sources   Download

MIT

The Requires

 

The Development Requires

config validator

02/04 2018

dev-develop

dev-develop http://github.com/Innmind/Config

Config schema validator

  Sources   Download

MIT

The Requires

 

The Development Requires

config validator

01/04 2018

1.0.0

1.0.0.0 http://github.com/Innmind/Config

Config schema validator

  Sources   Download

MIT

The Requires

 

The Development Requires

config validator