2017 © Pedro Peláez
 

library environ

Lightweight environment manager

image

neemzy/environ

Lightweight environment manager

  • Thursday, February 18, 2016
  • by neemzy
  • Repository
  • 1 Watchers
  • 4 Stars
  • 155 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 1 Forks
  • 1 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

ENVIRON

Lightweight environment manager, (*1)

HOW TO USE IT

1. Instantiate

$environ = new Neemzy\Environ\Manager();

2. Add environments

When adding an environment, you have to specify :, (*2)

  • A name
  • A condition closure
  • A callback closure
$environ
    ->add(
        'dev',
        new Neemzy\Environ\Environment(
            function () {
                return preg_match('/localhost/', $_SERVER['SERVER_NAME']);
            },
            function () {
                $pdo = new PDO('sqlite:dev.db');
            }
        )
    )
    ->add(
        'prod',
        new Neemzy\Environ\Environment(
            function () {
                return true;
            },
            function () {
                $pdo = new PDO('mysql:host=MYHOST;dbname=MYDBNAME', 'MYUSER', 'MYPASSWORD');
            }
        )
    );

You can chain declarations as above., (*3)

3. ???

$environ->init();

This will browse the environments you declared above. The first one which condition closure returns a truthy value is then set up as the current environment, and its callback closure is triggered., (*4)

4. Profit !

Let's assume you're on localhost., (*5)

// This will print 'dev'
echo($environ->get());

// Triggers the callback as well
$environ->set('prod');

if ($environ->is('prod')) {
    // There you go !
}

The Versions

18/02 2016

dev-master

9999999-dev

Lightweight environment manager

  Sources   Download

The Requires

  • php >=5.3.0

 

by Avatar neemzy

18/02 2016

1.0.0

1.0.0.0

Lightweight environment manager

  Sources   Download

The Requires

  • php >=5.3.0

 

by Avatar neemzy