Warning! This package won't worry about backward compatibily for
v0.*.
Bauhaus Config aims to provide a simple way to load and validate configurations via a container implementation of PSR-11.
This package isn't still complete. Missing features are:
- Validate configuration schema (use JSON schema)
- Load from
yaml(It will be done in a new repository bauhaus/config-yaml)
It's annoying when something inside your application breaks just because a configuration entry was missing.
To prevent it, Bauhaus Config validates when the configurations are loaded (being implemented).
<?php
use Psr\Container\NotFoundExceptionInterface as PsrNotFoundException;
use Psr\Container\ContainerInterface as PsrContainer;
use Bauhaus\Config;
use Bauhaus\Config\NotFoundException;
$config = new Config([
'instrument' => 'bass',
'pokemons' => ['charmander', 'pikachu'],
'books' => [
'study' => ['Clean Code', 'GOOS', 'Design Patterns'],
],
]);
$config instanceof PsrContainer; // true
$config->has('instrument'); // true
$config->has('pokemons'); // true
$config->has('books.study'); // true
$config->has('cars'); // false
$config->has('travels.asia'); // false
$config->get('instrument'); // 'bass'
$config->get('pokemons'); // ['charmander', 'pikachu']
$config->get('books'); // Config(['study' => ['Clean Code', 'GOOS', 'Design Patterns']])
$config->get('cars'); // throw NotFoundException implementing PsrNotFoundException
$config->get('travels.asia'); // throw NotFoundException implementing PsrNotFoundException
$config->get('books')->has('study'); // trueInstall it using Composer:
$ composer require bauhaus/configThis code has two levels of testing:
-
Coding standard (using PHPCS with PSR-2 standard):
$ composer run test:cs
-
Unit tests (using PHPUnit):
$ composer run test:unit
To run all at one:
$ composer run tests