2017 © Pedro Peláez
 

library configkit

Fast config toolkit, which provides super lightweight config accessor and loader.

image

corneltek/configkit

Fast config toolkit, which provides super lightweight config accessor and loader.

  • Monday, May 29, 2017
  • by c9s
  • Repository
  • 2 Watchers
  • 10 Stars
  • 12,862 Installations
  • PHP
  • 8 Dependents
  • 0 Suggesters
  • 1 Forks
  • 2 Open issues
  • 22 Versions
  • 1 % Grown

The README.md

ConfigKit

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

ConfigKit compiles your readable YAML config file to PHP files automatically., (*2)

YAML format is clean, smart, easy. but in PHP, you have to parse yaml config file in every request. Parsing YAML costs too much CPU time. How to improve it ?, (*3)

php-ConfigKit is a library for config files and which is designed for performance, it parses yaml config files for the first time, then compiles the config files into php files, so these config files can be cached in PHP, and it can also be in APC or any other cache backend system., (*4)

ConfigKit is simple and fast, all you have to do is defining your config file in YAML format, then use ConfigKit to load the config file., (*5)

ConfigKit uses static methods because static methods are faster than object methods., (*6)

It checks if a {config file}.php exists, if so, then checks the file modification time to decide whether to recompile yaml files., (*7)

When APC extension is enabled, PHP source code can be cached in APC, so when you require the pure php source file, it will be faster then reparsing it from yaml., (*8)

A generated config PHP file is like:, (*9)

<?php return array (
      'ApplicationName' => 'Phifty',
      'ApplicationID' => 'phifty',
      'ApplicationUUID' => '9fc933c0-70f9-11e1-9095-3c07541dfc0c',
      'Domain' => 'phifty.dev',

Requirement

YAML extension, (*10)

Installation

Composer:, (*11)

{
    "require": { 
        "corneltek/configkit": "~1.5"
    }
}

Usage

ConfigCompiler

To compile a yaml config file and get the config stash:, (*12)

$config = ConfigCompiler::load('tests/ConfigKit/data/framework.yml');
print_r( $config );

To disable stats check (mtime checking):, (*13)

ConfigCompiler::$statCheck = false;
$config = ConfigCompiler::load('tests/ConfigKit/data/framework.yml');

If you want to compile the config file manually, you may call the compile static function to do that:, (*14)

$compiledFile = ConfigCompiler::compile('config/framework.yml');

You may also specify the compiled filename in the arguments:, (*15)

$compiledFile = ConfigCompiler::compile('config/framework.yml', 'config/framework.php');

You can also override some config values during the compilation, by using the override_compile function:, (*16)

$compiledFile = ConfigCompiler::override_compile('config/framework.yml', array( 
    'something_should_not_be_in_config_file' => 123123123,
    'something_should_not_be_in_git' => 123123123,
    'something_generated_in_the_runtime' => random(),
));

To test if a compiled file needs to be updated (re-compile):, (*17)

if ( ConfigCompiler::test('config/framework.yml','config/framework.php')) ) {
    ConfigCompiler::compile(....);
} else {
    // already up to date.
}

ConfigLoader

You can manage multiple config files with ConfigLoader, (*18)

$loader = new ConfigLoader;
$loader->load( 'framework', 'config/framework.yml' );
$loader->load( 'database', 'config/database.yml' );

To get config stash, (*19)

$paths = $loader->get('framework','web.paths');
$templates = $loader->get('framework','web.templates');
foreach( $paths as $path ) {
    echo $path, "\n";
}

To write all config stash into one cache file:, (*20)

$loader->writeStashes('all.php');

To load all config stash back:, (*21)

$loader->loadStashes('all.php');

Generate AppConfigLoader class

$loader = new ConfigKit\ConfigLoader;
$loader->load('database','tests/data/database.yml');
$loader->load('framework','tests/data/framework.yml');
$appClass = $loader->generateAppClass('MyApp\\AppConfigLoader');
$path = $appClass->generatePsr4ClassUnder('tests');
require_once($path); 
$appConfigLoader = new \MyApp\AppConfigLoader;

The Versions

29/05 2017

dev-master

9999999-dev

Fast config toolkit, which provides super lightweight config accessor and loader.

  Sources   Download

MIT

The Requires

 

The Development Requires

cache config yaml accessor

29/05 2017

1.6.6

1.6.6.0

Fast config toolkit, which provides super lightweight config accessor and loader.

  Sources   Download

MIT

The Requires

 

The Development Requires

cache config yaml accessor

27/05 2017

1.6.5

1.6.5.0

Fast config toolkit, which provides super lightweight config accessor and loader.

  Sources   Download

MIT

The Requires

 

The Development Requires

cache config yaml accessor

21/05 2017

1.6.4

1.6.4.0

Fast config toolkit, which provides super lightweight config accessor and loader.

  Sources   Download

MIT

The Requires

 

The Development Requires

cache config yaml accessor

18/05 2017

1.6.3

1.6.3.0

Fast config toolkit, which provides super lightweight config accessor and loader.

  Sources   Download

MIT

The Requires

 

The Development Requires

cache config yaml accessor

17/05 2017

1.6.2

1.6.2.0

Fast config toolkit, which provides super lightweight config accessor and loader.

  Sources   Download

MIT

The Requires

 

The Development Requires

cache config yaml accessor

12/06 2016

1.6.1

1.6.1.0

Fast config toolkit, which provides super lightweight config accessor and loader.

  Sources   Download

MIT

The Requires

 

The Development Requires

cache config yaml accessor

23/08 2015

1.6.0

1.6.0.0

Fast config toolkit, which provides super lightweight config accessor and loader.

  Sources   Download

MIT

The Requires

 

The Development Requires

cache config yaml accessor

03/07 2015

1.5.5

1.5.5.0

  Sources   Download

The Requires

 

The Development Requires

13/09 2014

1.5.4

1.5.4.0

  Sources   Download

The Requires

 

The Development Requires

02/09 2014

1.5.3

1.5.3.0

  Sources   Download

The Requires

 

The Development Requires

30/08 2014

1.5.2

1.5.2.0

  Sources   Download

The Requires

 

The Development Requires

30/08 2014

1.5.1

1.5.1.0

  Sources   Download

The Requires

 

The Development Requires

21/02 2014

1.5.0

1.5.0.0

  Sources   Download

The Requires

 

The Development Requires

21/06 2013

1.4.2

1.4.2.0

  Sources   Download

The Requires

 

The Development Requires

21/06 2013

1.4.1

1.4.1.0

  Sources   Download

The Requires

 

The Development Requires

21/06 2013

1.4.0

1.4.0.0

  Sources   Download

The Requires

 

The Development Requires

21/06 2013

1.3.4

1.3.4.0

  Sources   Download

The Requires

 

The Development Requires

19/06 2013

1.3.3

1.3.3.0

  Sources   Download

The Requires

 

The Development Requires

19/06 2013

1.3.2

1.3.2.0

  Sources   Download

The Requires

 

The Development Requires

21/03 2013

1.3.1

1.3.1.0

  Sources   Download

The Requires

 

The Development Requires

21/03 2013

1.3.0

1.3.0.0

  Sources   Download

The Requires

 

The Development Requires