jalet/tvnu-config

Environment based configuration helper for multiple formats. INI, YAML, Databse (PDO) or Array.

This package's canonical repository appears to be gone and the package has been frozen as a result.

1.2.0 2015-12-15 09:41 UTC

This package is not auto-updated.

Last update: 2020-01-24 15:00:54 UTC


README

Environment based configuration helper for multiple formats. INI, YAML, Arrays or Database (PDO.

Build Status

Requirements

  • PHP 5.6+
  • PDO (optional)
  • YAML (optional)

Usage

INI

[production]
foo     = Bar
bar.foo = Hello World
bar.biz = World Hello
biz     = Baz

[development : production]
foo = Foo Dev

[local : development]
bar.biz = Hello Local
// Production
$a = new Tvnu\Config\Adapter\Ini('production', 'path/to/config'));
$c = new Tvnu\Config\Config($a);

echo $c->get('foo'); // Bar

// Development
$a = new Tvnu\Config\Adapter\Ini('development', 'path/to/config'));
$c = new Tvnu\Config\Config($a);

echo $c->get('foo'); // Foo Dev

// Local
$a = new Tvnu\Config\Adapter\Ini('local', 'path/to/config'));
$c = new Tvnu\Config\Config($a);

echo $c->get('bar.biz'); // Hello Local

PHP Array

// path/to/config/config.php
return [
    'foo' => 'Bar',
    'bar' => [
        'foo' => "Hello World",
        'biz' => "World Hello",
        'baz' => [
            'foo' => 'Foobar'
        ]
    ],
    'biz' => 'Baz'
];

// path/to/config/config.development.php
return [
    'foo' => 'Foo Dev',
    'bar' => [
        'foo' => "Hello World",
        'biz' => "World Hello",
        'baz' => [
            'foo' => 'Barfoo'
        ]
    ],
];

// path/to/config/config.local.php
return [
    'biz' => [
        'baz' => 'Hello Local'
    ]
];
// Production
$a = new Tvnu\Config\Adapter\PhpArray('production', 'path/to/config'));
$c = new Tvnu\Config\Config($a);

echo $c->get('foo'); // Bar

// Development
$a = new Tvnu\Config\Adapter\PhpArray('development', 'path/to/config'));
$c = new Tvnu\Config\Config($a);

echo $c->get('foo'); // Foo Dev

// Local
$a = new Tvnu\Config\Adapter\PhpArray('local', 'path/to/config'));
$c = new Tvnu\Config\Config($a);

echo $c->get('bar.biz'); // Hello Local

YAML

production:
    foo: Bar
    bar:
        foo: "Hello World"
        biz: "World Hello"
        bar:
            foo: "Hello World Third"
    biz: Baz   

development:
    foo: "Foo Dev"

local:
    bar:
        biz: "Hello Local"
// Production
$a = new Tvnu\Config\Adapter\Yaml('production', 'path/to/config'));
$c = new Tvnu\Config\Config($a);

echo $c->get('foo'); // Bar

// Development
$a = new Tvnu\Config\Adapter\Yaml('development', 'path/to/config'));
$c = new Tvnu\Config\Config($a);

echo $c->get('foo'); // Foo Dev

// Local
$a = new Tvnu\Config\Adapter\Yaml('local', 'path/to/config'));
$c = new Tvnu\Config\Config($a);

echo $c->get('bar.biz'); // Hello Local

Database (PDO)

    #    |    key    |    val    
-------------------------------------
    1    |    foo    |    Bar    
    2    |    biz    |    Baz    
    3    |  bar.foo  |    Hello World    
    4    |  bar.biz  |    World Hello
// Production
$a = new Tvnu\Config\Adapter\Database($pdoConnection, $myTableName, array('my', 'fields', 'of', 'choice'));
$c = new Tvnu\Config\Config($a);

echo $c->get('foo'); // Bar

Composer

Packagegist

composer.json

{
    "require": {
        "jalet/tvnu-config": "1.2.0"
    }
}

Tests

# Run tests
$ composer test

# Run tests with coverage
$ composer coverage

ToDo

  • Return array of values

Licence

Copyright (c) 2013 Joakim Jarsäter joakim@jarsater.com

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.