2017 © Pedro Peláez
 

library config

Easy PHP config allows to configure your settings by allowing to read environment from operating system and public variables

image

caiola/config

Easy PHP config allows to configure your settings by allowing to read environment from operating system and public variables

  • Monday, January 15, 2018
  • by caiola
  • Repository
  • 1 Watchers
  • 1 Stars
  • 160 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 5 Versions
  • 100 % Grown

The README.md

Config

Config is an easy and simple PHP class that allows to configure your settings by allowing to read environment from operating system and public variables that you define., (*1)

Install

Easy installation, (*2)

composer install caiola/config

How to use

Use composer autoload and use it, (*3)

Obtaining and overriding environment variables

<?php

// Autoload files using Composer autoload
$loader = require_once __DIR__ . '/vendor/autoload.php';

use Caiola\Config\Config as Config;

Config::getInstance()->setImmutable(false);
Config::getInstance()->setUseEnvironment(true);

echo "# windir: " . Config::getInstance()->windir . PHP_EOL;

Config::getInstance()->windir = 'c:\\win\\';

echo "# windir: " . Config::getInstance()->windir . PHP_EOL;

Results, (*4)

# windir: C:\WINDOWS
# windir: c:\win\

Obtaining and set environment variables as immutable

<?php

// Autoload files using Composer autoload
$loader = require_once __DIR__ . '/vendor/autoload.php';

use Caiola\Config\Config as Config;

// Allow to read environment variables
Config::getInstance()->setUseEnvironment(true);

// Allow to override environment variables
Config::getInstance()->setImmutable(true);

// Configuration example
$databases = array(
    'error_log' => '/var/log/error_log',
    'master'    => array(
        'host' => '127.0.0.1',
        'port' => '3306',
        'user' => 'root',
        'pass' => 'pass',
        'db'   => 'dbapp'
    )
);

Config::getInstance()->set($databases);

// Obtain configuration values through several methods
$cfg = new Config();
echo "# db master: " . $cfg->master['db'] . PHP_EOL;
echo "# db master: " . Config::getInstance()->master['db'] . PHP_EOL;
echo "# db master: " . Config::getByKey("master.db") . PHP_EOL;

echo "# error_log: " . $cfg->error_log . PHP_EOL;
echo "# error_log: " . Config::getInstance()->error_log . PHP_EOL;
echo "# error_log: " . Config::getByKey("error_log") . PHP_EOL;

echo "# windir: " . $cfg->windir . PHP_EOL;
echo "# windir: " . Config::getInstance()->windir . PHP_EOL;
echo "# windir: " . Config::getByKey("windir") . PHP_EOL;

Results, (*5)

# db master: dbapp
# db master: dbapp
# db master: dbapp
# error_log: /var/log/error_log
# error_log: /var/log/error_log
# error_log: /var/log/error_log
# windir: C:\WINDOWS
# windir: C:\WINDOWS
# windir: C:\WINDOWS

The Versions

15/01 2018

dev-master

9999999-dev

Easy PHP config allows to configure your settings by allowing to read environment from operating system and public variables

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Roberto Caiola

configuration config environment variables configs

15/01 2018

1.0.6

1.0.6.0

Easy PHP config allows to configure your settings by allowing to read environment from operating system and public variables

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Roberto Caiola

configuration config environment variables configs

15/01 2018

dev-develop

dev-develop

Easy PHP config allows to configure your settings by allowing to read environment from operating system and public variables

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Roberto Caiola

configuration config environment variables configs

15/01 2018

1.0.5

1.0.5.0

Easy PHP config allows to configure your settings by allowing to read environment from operating system and public variables

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Roberto Caiola

configuration config environment variables configs

12/01 2018

1.0.4

1.0.4.0

Easy PHP config allows to configure your settings by allowing to read environment from operating system and public variables

  Sources   Download

GPL

The Requires

  • php >=5.3.0

 

by Roberto Caiola