2017 © Pedro Peláez
 

library config-component

config component within the chilimatic framework

image

chilimatic/config-component

config component within the chilimatic framework

  • Monday, December 12, 2016
  • by chilimatic
  • Repository
  • 1 Watchers
  • 0 Stars
  • 52 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 12 Versions
  • 0 % Grown

The README.md

config-component

chilimatic config-component, (*1)

The File Object is built for multi-domain architectures:, (*2)

The idea is pretty simple you create a config directory, every config file has the extension .cfg the object will created a list based on the given host_id of the server. if no host_id is set as parameter it will try to determinate the id via $_SERVER ['HTTP_HOST'] or it will try to look for the host parameter use from the cli, (*3)

php myscript.php host=www.example.com

if still no host_id is found it will throw an exception., (*4)

$config = new File(
    [
        \chilimatic\lib\Config\Adapter\File::CONFIG_PATH_INDEX  => __DIR__ . '/test/data',
        \chilimatic\lib\Config\Adapter\File::HOST_ID_KEY        => 'www.example.com' 
    ]
);

It will than generate a set of possible configs based on the delimiter, the delimiter is * by default you can switch it to all for windows machines., (*5)

the generated set in our case would look as follows:, (*6)

[ 
    '*.cfg', 
    '*.example.com.cfg', 
    'www.example.com.cfg'
]

as mentioned you can change the delimiter for windows machines to all, (*7)

[ 
    'all.cfg', 
    'all.example.com.cfg', 
    'www.example.com.cfg'
]

the *.cfg will be used on every system, and than it will be overwritten hierarchical, (*8)

The values are stored in a doublylinked-list so all values do remain but in general the config returns the last appended value to a specific key, (*9)

$config = new File(
    [
        \chilimatic\lib\Config\Adapter\File::CONFIG_PATH_INDEX  => __DIR__ . '/test/data',
        \chilimatic\lib\Config\Adapter\File::HOST_ID_KEY        => 'www.example.com' 
    ]
);
$config->set('key1', ['some', 'data']);
$config->set('key1', implode(' ', $config->get('key1')));

echo $config->get('key1'); // will return 'some data'

the config implements its own parser which allows you to write configs like, (*10)

#cache settings
cache_type = 'memcached'
cache_settings = { "server_list" : [{"host" : "127.0.0.1", "port" : "11211", "weight" : 1 }] }
// it is possible to read serialized data but as we all know this can lead to chaos :) 
// so stick to json if possible
serializedString = a:2:{s:2:"my";s:3:"key";s:5:"value";O:8:"stdClass":0:{}}

comments are defined as // or # and will be added to the node;, (*11)

The library includes a standard factory pattern that can be accessed static, (*12)

\chilimatic\lib\Config\ConfigFactory::make(
    'file',
     [
             \chilimatic\lib\Config\Adapter\File::CONFIG_PATH_INDEX  => __DIR__ . '/test/data',
             \chilimatic\lib\Config\Adapter\File::HOST_ID_KEY        => 'www.example.com' 
     ]
 ); // returns the same as the example above

As well as a singelton config wrapper which utilizes the factory to create a config that allows you static access., (*13)

// passed reference
$config = \chilimatic\lib\Config\Config::getInstance(
    'file',
     [
             \chilimatic\lib\Config\Adapter\File::CONFIG_PATH_INDEX  => __DIR__ . '/test/data',
             \chilimatic\lib\Config\Adapter\File::HOST_ID_KEY        => 'www.example.com' 
     ]
 );
// also accessable via
Config::set('my variable', 'my value);
Config::get('my variable');

you can have a look at the benchmark.php and the unit tests., (*14)

if you just wanna uses ini files you can use the ini adapter, (*15)

$config = new \chilimatic\lib\Config\Adapter\Ini(
    [
         \chilimatic\lib\Config\Adapter\Ini::FILE_INDEX => __DIR__ . '/test/data/'
    ]
);

if you just pass a directory it will scan for all files with an .ini extension It will merge them recursive based on the scanned order. and than pass it to the node graph structure inside of the config object, (*16)

if you pass a specific file it will only use this file., (*17)

Planned for the next steps are new engines right now it's a dom like structure with indexes this can be overkill and maybe other people prefer a flat hashmap structure.
Maybe a json adapter will be cool too., (*18)

The Versions

12/12 2016

dev-master

9999999-dev

config component within the chilimatic framework

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jakob Oberhummer

04/08 2016

2.1.1.x-dev

2.1.1.9999999-dev

config component within the chilimatic framework

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jakob Oberhummer

03/08 2016

2.1.0.x-dev

2.1.0.9999999-dev

config component within the chilimatic framework

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jakob Oberhummer

03/08 2016

2.1.0

2.1.0.0

config component within the chilimatic framework

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jakob Oberhummer

13/07 2016

dev-benchmark-optimization

dev-benchmark-optimization

config component within the chilimatic framework

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jakob Oberhummer

07/07 2016

2.0.1.x-dev

2.0.1.9999999-dev

config component within the chilimatic framework

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jakob Oberhummer

07/07 2016

2.0.1

2.0.1.0

config component within the chilimatic framework

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jakob Oberhummer

29/06 2016

2.0.0.x-dev

2.0.0.9999999-dev

config component within the chilimatic framework

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jakob Oberhummer

29/06 2016

2.0.0

2.0.0.0

config component within the chilimatic framework

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jakob Oberhummer

22/06 2016

1.0.2

1.0.2.0

config component within the chilimatic framework

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jakob Oberhummer

14/06 2016

1.0.1

1.0.1.0

config component within the chilimatic framework

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jakob Oberhummer

14/06 2016

1.0.0

1.0.0.0

config component within the chilimatic framework

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jakob Oberhummer