2017 © Pedro Peláez
 

library config

Powerful tool for configurations

image

stdakov/config

Powerful tool for configurations

  • Thursday, May 19, 2016
  • by stdakov
  • Repository
  • 1 Watchers
  • 0 Stars
  • 8 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

config

This is powerful configuration tool to manage every configuration file., (*1)

Supported files:

ini,php,json, (*2)

Installation

The preferred way to install this tool is through composer., (*3)

Either run, (*4)

php composer.phar require stdakov/config:dev-master

or add, (*5)

"stdakov/config": "dev-master"

Usage

For example we will have 3 configuration files in config dir: 'ini.ini' 'php.php' 'json.json', (*6)

require 'vendor/autoload.php';

$configFolder = 'config';
$helpersFolder = 'helpers';

$config = new \Dakov\Config();

We can also load helper functions if we have., (*7)

$config->loadHelpers($helpersFolder);

Lets load our configurations, (*8)

$config->loadConfigs($configFolder);

print_r($config->listConfigs());

//This is file configuration names which are loaded

Output, (*9)

Array
(
    [0] => ini
    [1] => json
    [2] => php
)

------------------INI--Configuration-----------------------, (*10)


print_r($config->load('ini')->get()->value()); print_r($config->load('ini')->get('database')->value()); try { print_r($config->load('ini')->get('server')->value()); } catch (\Exception $e) { var_dump($e->getMessage()); } try { print_r($config->load('app')->get('server')->value()); } catch (\Exception $e) { var_dump($e->getMessage()); } $config->load('ini')->get('database')->value()['DB_HOST'] == $config->load('ini')->get('database')->get('DB_HOST')->value();

Will output, (*11)

Array
(
    [database] => Array
        (
            [DB_HOST] => localhost
            [DB_DATABASE] => test
            [DB_USERNAME] => root
            [DB_PASSWORD] => test
        )

    [admin authentication] => Array
        (
            [ADMIN_AUTH] => 1
            [ADMIN_TABLE] => admin
        )

    [upload] => Array
        (
            [tmp_dir] => /tmp
            [upload_dir] => /public/storage
        )

)
Array
(
    [DB_HOST] => localhost
    [DB_DATABASE] => test
    [DB_USERNAME] => root
    [DB_PASSWORD] => test
)
string(21) "Missing option:server"
string(25) "Missing Configuration:app"

------------------JSON--Configuration-----------------------, (*12)

print_r($config->load('json')->get()->value());
print_r($config->load('json')->get('name')->value());

Will output, (*13)

Array
(
    [name] => stuff
    [components] => Array
        (
            [Version] => Array
                (
                    [versions] => 1
                )

            [Source] => Array
                (
                    [ip] => 0.0.0.1
                )

            [Empty] => Array
                (
                )

        )

)
stuff

------------------PHP--Configuration-----------------------, (*14)

print_r($config->load('php')->get()->value());
print_r($config->load('php')->get('test')->value());

Will output, (*15)

Array
(
    [test] => Array
        (
            [show] => this is test
        )

)
Array
(
    [show] => this is test
)

------------------Custom Configuration-------------------------, (*16)

$configData = [
    'user'     => 'username',
    'password' => 'password'
];

$config->set($configData, 'custom');
print_r($config->load('custom')->get()->value());
print_r($config->load('custom')->get('user')->value());

Will output, (*17)

Array
(
    [user] => username
    [password] => password
)
username
-------------------------------------------

-------------------Custom dir-INI-----------------------, (*18)


$customConfigPath = 'config/new/ini2.ini'; $config->registerConfig($customConfigPath); print_r($config->load('ini2')->get()->value()); print_r($config->load('ini2')->get('database')->value());

Will output, (*19)

Array
(
    [database] => Array
        (
            [DB_HOST] => localhost
            [DB_DATABASE] => test
            [DB_USERNAME] => root
            [DB_PASSWORD] => test
        )

    [admin authentication] => Array
        (
            [ADMIN_AUTH] => 1
            [ADMIN_TABLE] => admin
        )

    [upload] => Array
        (
            [tmp_dir] => /tmp
            [upload_dir] => /public/storage
        )

)
Array
(
    [DB_HOST] => localhost
    [DB_DATABASE] => test
    [DB_USERNAME] => root
    [DB_PASSWORD] => test
)
string(21) "Missing option:server"
string(26) "Missing Configuration:app2"

-------------------Custom dir-INI-with custom name----------------------, (*20)

$customConfigPath = 'config/new/ini2.ini';
$config->registerConfig($customConfigPath, 'myIni');
print_r($config->load('myIni')->get()->value());
print_r($config->load('myIni')->get('database')->value());

Will output, (*21)

Array
(
    [database] => Array
        (
            [DB_HOST] => localhost
            [DB_DATABASE] => test
            [DB_USERNAME] => root
            [DB_PASSWORD] => test
        )

    [admin authentication] => Array
        (
            [ADMIN_AUTH] => 1
            [ADMIN_TABLE] => admin
        )

    [upload] => Array
        (
            [tmp_dir] => /tmp
            [upload_dir] => /public/storage
        )

)
Array
(
    [DB_HOST] => localhost
    [DB_DATABASE] => test
    [DB_USERNAME] => root
    [DB_PASSWORD] => test
)
string(21) "Missing option:server"
string(21) "Missing option:server"

For working examples see the tests/example.php, (*22)

TODO

1.Implement xml files 2.Add functionality $config->load('ini2')->get('database.host')->value();, (*23)

The Versions

19/05 2016

dev-master

9999999-dev

Powerful tool for configurations

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

by Stanislav Dakov

configuration config