2017 © Pedro Peláez
 

library env-backup

Backup/restore environment variables: globals, static vars, configs

image

clippings/env-backup

Backup/restore environment variables: globals, static vars, configs

  • Wednesday, April 30, 2014
  • by hkdobrev
  • Repository
  • 12 Watchers
  • 1 Stars
  • 862 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 8 Versions
  • 0 % Grown

The README.md

Env Backup

Build Status Scrutinizer Code Quality Code Coverage Latest Stable Version, (*1)

Backup/restore environment variables: globals and static vars. This is very useful for initializing environment for a test. Keep the current state of the environment from interfering with other tests., (*2)

You can add "Parameters" to the environment, each "applying" and "restoring" a specific super global or static property of a class, you can even keep a precice state of the filesystem., (*3)

  • GlobalParam - used for setting / restoring '_POST', '_GET', '_FILES', '_SERVER', '_COOKIE' and '_SESSION'
  • ServerParam - used specifically for '_SERVER' super global so you can set / restore only some of its contents, e.g. REMOTE_HOST', 'CLIENT_IP ...
  • StaticParam - used for setting / restoring static properties of classes, it can handle protected and private ones too.
  • FileParam - used for setting / restoring files and their contents. Ensures a certain file and its content are present, and restore previous state
  • DirectoryParam - used for setting / restoring a whole dir with all of its contents. Ensures a certain dir and its content are present, and restore previous state

Example:, (*4)

use CL\EnvBackup\Env;
use CL\EnvBackup\GlobalParam;
use CL\EnvBackup\ServerParam;
use CL\EnvBackup\StaticParam;

$env = new Env(array(
    new GlobalParam('_POST', array('new post name' => 'val')),
    new ServerParam('REMOTE_ADDR', '1.1.1.1'),
    new StaticParam('MyClass', 'private_var', 10)
    new FileParam('/path/to/file', 'file content')
    new DirectoryParam('/path/to/dir', array(
        'file1.txt' => 'file contents',
        'inner_dir' => array(
            'inner_file1.csv' => 'a, b',
            'inner_file2.txt' => 'test',
        )
    ))
));

$env->apply();

// Do some stuff that changes / uses these variables
// ...

$env->restore();

ServerParam in CLI

In CLI environment, $_SERVER variables are very different than if the script is run by apache or cgi. If you want to use env-backup in such an environment, you can pass ServerParam::CLI like this:, (*5)

$env = new Env(array(
    new ServerParam('HOME', '/test/home', ServerParam::CLI),
    new ServerParam('argc', 4, ServerParam::CLI),
));

License

Copyright (c) 2014, Clippings Ltd. Developed by Ivan Kerin as part of clippings.com, (*6)

Under BSD-3-Clause license, read LICENSE file., (*7)

The Versions

30/04 2014

dev-master

9999999-dev

Backup/restore environment variables: globals, static vars, configs

  Sources   Download

BSD-3-Clause

30/04 2014

0.2.5

0.2.5.0

Backup/restore environment variables: globals, static vars, configs

  Sources   Download

BSD-3-Clause

25/03 2014

0.2.4

0.2.4.0

Backup/restore environment variables: globals, static vars, configs

  Sources   Download

BSD-3-Clause

25/03 2014

0.2.3

0.2.3.0

Backup/restore environment variables: globals, static vars, configs

  Sources   Download

BSD-3-Clause

14/03 2014

0.2.2

0.2.2.0

Backup/restore environment variables: globals, static vars, configs

  Sources   Download

BSD-3-Clause

14/03 2014

0.2.1

0.2.1.0

Backup/restore environment variables: globals, static vars, configs

  Sources   Download

BSD-3-Clause

13/03 2014

0.2.0

0.2.0.0

Backup/restore environment variables: globals, static vars, configs

  Sources   Download

BSD-3-Clause

13/03 2014

0.1

0.1.0.0

Backup/restore environment variables: globals, static vars, configs

  Sources   Download

BSD-3-Clause