2017 © Pedro Peláez
 

library php-config

Simple class supporting different configuration values based on the environment

image

mkomorowski/php-config

Simple class supporting different configuration values based on the environment

  • Monday, July 20, 2015
  • by mKomorowski
  • Repository
  • 1 Watchers
  • 1 Stars
  • 170 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 6 % Grown

The README.md

php-config

Latest Stable Version Build Status Coverage Status, (*1)

A simple class supporting different configuration values based on the environment, (*2)

Installation

The package can be installed via Composer by adding to the composer.json require block., (*3)

{
    "require": {
        "mkomorowski/php-config": "1.0"
    }
}

Then update application packages by running the command:, (*4)

php composer.phar update

Configuration

Examples of files with application configuration options., (*5)

local.php, (*6)

return array(
        'debug' => true,
        'database' => array(
            'host' => '127.0.0.1',
            'password' => 'password',
        ),
);

production.php, (*7)

return array(
        'debug' => false,
        'database' => array(
            'host' => 'rds.amazon.com',
            'password' => 'password',
        ),
);

In the settings loader we are specifying the path to the directory with config files., (*8)

$loader = new mKomorowski\Config\Loader('/app/config');

Next we are defining the environment settings:, (*9)

$environment = new mKomorowski\Config\Environments(array(
    'local' => array('local', 'MacBook.local'),
    'stage' => array('cent_os_stage')
));

Finally we initialize the Config class, passing settings and environments. The third paramater is an optional default environment., (*10)

$config = new mKomorowski\Config\Config($loader, $environment, 'stage');

We can change the default environment later by:, (*11)

$config->setDefaultEnvironment('production');

Usage

To retrieve the settings just use:, (*12)

$config->get('debug');

Accessing nested values is possible with dotted notation, (*13)

$config->get('database.hostname');

If your hosts is signed to a specific environment it will return the appropriate value. If not it will look for default environment settings or return null if the key is not set., (*14)

The Versions

20/07 2015

dev-master

9999999-dev https://github.com/mKomorowski/php-config

Simple class supporting different configuration values based on the environment

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Michal Komorowski

settings php config environment hosts

14/06 2015

1.0

1.0.0.0 https://github.com/mKomorowski/php-config

Simple class supporting different configuration values based on the environment

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Michal Komorowski

settings php config environment hosts