bauhaus / config
Simple config container
v0.1.0
2018-02-11 11:30 UTC
Requires
- php: >=7.2
- psr/container: ^v1.0.0
Requires (Dev)
- phpunit/phpunit: ^7.0.0
- squizlabs/php_codesniffer: ^3.2
This package is auto-updated.
Last update: 2024-10-23 11:24:39 UTC
README
Warning! This package won't worry about backward compatibily for
v0.*
.
Bauhaus Config
Bauhaus Config aims to provide a simple way to load and validate configurations via a container implementation of PSR-11.
TODOS
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)
Motivation
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).
Usage
<?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'); // true
Installation
Install it using Composer:
$ composer require bauhaus/config
Coding Standard and Testing
This 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