PHP code example of bauhaus / config

1. Go to this page and download the library: Download bauhaus/config library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

bauhaus / config example snippets




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