2017 © Pedro Peláez
 

library configloader

A simple config system

image

jomisacu/configloader

A simple config system

  • Thursday, April 13, 2017
  • by jomisacu
  • Repository
  • 1 Watchers
  • 0 Stars
  • 25 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 0 % Grown

The README.md

ConfigLoader

Provide a simple interface to handle configuration values., (*1)

Concepts

Config root directory

It's a place to store all configuration files under environments represented by sub directories., (*2)

Enviroment

A environment represents a directory into directory root., (*3)

By default the selected environment is ConfigLoader::ENV_PRODUCTION ("production"), to override this, you can put into config root directory a file named ENVIRONMENT.txt that contains a environment name, or, configure $_SERVER['ENVIRONMENT'] var through http server. For example, you can set this var on apache adding the line below:, (*4)

# httpd.conf or .htaccess 
SetEnv ENVIRONMENT 'development'

Config file

A config file is a pure php file that contains an array named $config with the specific scope values. Example:, (*5)

<?php // [config root dir]/[selected environment]/default.php file

$config['system_timezone'] = 'Americas/Santo_Domingo';

installation

php composer.phar require "jomisacu/configloader"

Usage

Use this package require atleast the below steps, (*6)

  1. include
<?php

include "vendor/autoload.php";

  1. Create a instance
<?php

// for specific environment values.
// represents a sub directory on config files root directory
// it's a string and can exists any number of environments
$environment = \Jomisacu\ConfigLoader::ENV_DEVELOPMENT; 

// directory where resides configuration environments dirs
// -+ config (config root)
//  |-- development
//  |-- production
//  |-- testing
//  |-- qa
//  |-- example
//  |-- ... 
$configFilesRootDir = __DIR__ . '/config';

// configuration files to be loaded automatically
$autoloadFiles = ['default'];

$config = \Jomisacu\ConfigLoaderFactory::create($configFilesRootDir, $environment, $autoloadFiles);

  1. Access to configuration values

```php <?php, (*7)

// ..., (*8)

// load files $config->load('default');, (*9)

// via method call echo $config->get('system_timezone') . "
";, (*10)

// via magic method echo $config->system_timezone . "
";, (*11)

// ..., (*12)

The Versions

13/04 2017

dev-master

9999999-dev

A simple config system

  Sources   Download

proprietary

by Avatar jomisacu

11/04 2017

v1.0.1

1.0.1.0

A simple config system

  Sources   Download

proprietary

by Avatar jomisacu

11/04 2017

v1.0.2

1.0.2.0

A simple config system

  Sources   Download

proprietary

by Avatar jomisacu

10/04 2017

v1.0.0

1.0.0.0

A simple config system

  Sources   Download

proprietary

by Avatar jomisacu