2017 © Pedro Peláez
 

library config

image

wandu/config

  • Thursday, April 5, 2018
  • by wan2land
  • Repository
  • 0 Watchers
  • 0 Stars
  • 25 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 19 Versions
  • 14 % Grown

The README.md

Wandu Config

Latest Stable Version Latest Unstable Version Total Downloads License, (*1)

Simple Config Based On Dot Array., (*2)

Installation

composer require wandu/config

Usage

$config = new \Wandu\Config\Config([
    'host' => 'wandu.github.io',
    'log' => [
        'handler' => 'monolog',
        'path' => 'log/wandu.log',
    ],
]);

static::assertSame('wandu.github.io', $config->get('host'));
static::assertSame('wandu.github.io', $config['host']);

static::assertSame([
    'handler' => 'monolog',
    'path' => 'log/wandu.log',
], $config->get('log'));
static::assertSame([
    'handler' => 'monolog',
    'path' => 'log/wandu.log',
], $config['log']);

static::assertSame('log/wandu.log', $config->get('log.path'));
static::assertSame('log/wandu.log', $config['log']['path']);
static::assertSame('log/wandu.log', $config['log.path']); // you can use dot syntax in array!

Use Default Value

$config = new \Wandu\Config\Config([
    'debug' => false,
    'cache_dir' => null,
]);

static::assertSame(false, $config['debug']);
static::assertSame(null, $config['cache_dir']);
static::assertSame(null, $config['unknown']);

static::assertSame(false, $config->get('debug', true));
static::assertSame(null, $config->get('cache_dir', "/")); // check by array_key_exists
static::assertSame("unknown text..", $config->get('unknown', "unknown text.."));

Support Loader

$config = new \Wandu\Config\Config();

$config->pushLoader(new \Wandu\Config\Loader\PhpLoader());
$config->pushLoader(new \Wandu\Config\Loader\JsonLoader());
$config->pushLoader(new \Wandu\Config\Loader\EnvLoader());
$config->pushLoader(new \Wandu\Config\Loader\YmlLoader());
$config->pushLoader(new \Wandu\Config\Loader\PathLoader([
    new \Wandu\Config\Loader\YmlLoader(),
]));

$config->load(__DIR__ . '/test_php.php');
$config->load(__DIR__ . '/test_json.json');
$config->load(__DIR__ . '/test_env.env');
$config->load(__DIR__ . '/test_yml.yml');
$config->load(__DIR__ . '/test_path');

static::assertSame([
    'foo' => 'foo string',
    'vendor1' => [
        'service1' => [
            'name' => 'vendor1 service1 name..',
            'path' => 'vendor1 service1 path..',
        ],
        'service2' => [
            'name' => 'vendor1 service2 name..',
            'path' => 'vendor1 service2 path..',
        ],
    ],
    'vendor2' => [
        'service1' => [
            'name' => 'vendor2 service1 name..',
            'path' => 'vendor2 service1 path..',
        ],
        'service2' => [
            'name' => 'vendor2 service2 name..',
            'path' => 'vendor2 service2 path..',
        ],
    ],
    'json1' => 'json 1 string',
    'json2' => [
        'json2-1',
        'json2-2',
    ],
    'env1' => 'what the',
    'env2' => false,
    'yml1' => [
        'yml11' => true,
    ],
    'yml2' => [
        'paths' => ['vendor/*', 'tests/*']
    ],
    'yml3' => [
        'yml3_1',
        'yml3_2',
    ],
    'app' => [
        'debug' => true,
        'env' => 'test',
    ],
], $config->toArray());

The Versions

05/04 2018

v3.0.0-alpha1

3.0.0.0-alpha1

  Sources   Download

05/04 2018

v3.0.0-alpha2

3.0.0.0-alpha2

  Sources   Download

05/04 2018

v3.0.0-alpha3

3.0.0.0-alpha3

  Sources   Download

10/02 2018

dev-master

9999999-dev

Simple Config Based On Dot Array.

  Sources   Download

MIT

The Requires

  • php >=7.1

 

08/08 2017

v4.0.0-beta2

4.0.0.0-beta2

Simple Config Based On Dot Array.

  Sources   Download

MIT

The Requires

  • php >=7.0

 

08/06 2017

v4.0.0-beta1

4.0.0.0-beta1

Simple Config Based On Dot Array.

  Sources   Download

MIT

The Requires

  • php >=7.0

 

25/10 2016

3.0.x-dev

3.0.9999999.9999999-dev

Simple Config Based On Dot Array.

  Sources   Download

MIT

The Requires

 

25/10 2016

dev-develop

dev-develop

Simple Config Based On Dot Array.

  Sources   Download

MIT

The Requires

 

25/10 2016

v3.0.3

3.0.3.0

Simple Config Based On Dot Array.

  Sources   Download

MIT

The Requires

 

25/10 2016

v3.0.4

3.0.4.0

Simple Config Based On Dot Array.

  Sources   Download

MIT

The Requires

 

17/08 2016

v3.0.0

3.0.0.0

  Sources   Download

MIT

The Requires

 

17/08 2016

v3.0.1

3.0.1.0

  Sources   Download

MIT

The Requires

 

17/08 2016

v3.0.2

3.0.2.0

  Sources   Download

MIT

The Requires

 

14/07 2016

v3.0.0-beta4

3.0.0.0-beta4

  Sources   Download

MIT

The Requires

  • php >=5.6

 

14/07 2016

v3.0.0-beta5

3.0.0.0-beta5

  Sources   Download

MIT

The Requires

  • php >=5.6

 

14/07 2016

v3.0.0-beta6

3.0.0.0-beta6

  Sources   Download

MIT

The Requires

  • php >=5.6

 

26/05 2016

v3.0.0-beta1

3.0.0.0-beta1

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

26/05 2016

v3.0.0-beta2

3.0.0.0-beta2

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

26/05 2016

v3.0.0-beta3

3.0.0.0-beta3

  Sources   Download

MIT

The Requires

  • php >=7.0.0