bauhaus/config

Simple config container

v0.1.0 2018-02-11 11:30 UTC

This package is auto-updated.

Last update: 2024-10-23 11:24:39 UTC


README

Build Status Coverage Status Codacy Badge

Latest Stable Version Latest Unstable Version Total Downloads composer.lock

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:

  1. Coding standard (using PHPCS with PSR-2 standard):

    $ composer run test:cs
  2. Unit tests (using PHPUnit):

    $ composer run test:unit

To run all at one:

$ composer run tests