2017 © Pedro Peláez
 

library scope

image

icio/scope

  • Thursday, September 25, 2014
  • by icio
  • Repository
  • 2 Watchers
  • 1 Stars
  • 8 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 4 Versions
  • 0 % Grown

The README.md

Scope Build Status

Scope offers a mechanism for preparing global environments and containers for the duration of a callback, keeping state mutation and clean-up to only declaration in your code. Inspired by Python's native with., (*1)

For example, instead of doing:, (*2)

global $x;
$xBackup = $x;
$x = $xNew;
$done = do_it();
$x = $xBackup;

with KeyState you can set an Array key state:, (*3)

(new KeyState($GLOBALS, array("x" => $newX)))->call('do_it');

Currently available scopes help with:, (*4)

  • Collecting multiple scopes together, with Scope;
  • Setting temporary values on arrays, with KeyState;
  • Capturing function output, with Buffer;
  • Changing into a new directory, with WorkingDirectory; and
  • Worrying about different error levels, with ErrorReporting.

Sometimes you'll want to hop in and out of a given scope, providing default context by following the changes incurred by your actions within. The scopes can optionally account for this. The Buffer can collect the output across multiple sessions; the WorkingDirectory can go back to the directory it left upon re-entry; the KetState can track the value of keys, should they be changed in-scope; and the ErrorReporting can track any changes to the reporting. See the spec tests for details., (*5)

All entered scopes are passed into the callback as function arguments. For example, when working with output buffers you can capture and return the output as so:, (*6)

$output = (new Scope(
    new Buffer(Buffer::CLEAN),
    new WorkingDirectory("./old")
))->call(function(Buffer $buffer) {
    require "old-script.php";
    return $buffer->getContents();
});

If exceptions are thrown during the callback then we close the scopes and re-throw the exception. If exceptions are thrown by the scopes then we clean up any already entered and re-throw the exception. Exceptions thrown whilst trying to leave a scope prevent the clean-up of others (which should perhaps change)., (*7)

The Versions

25/09 2014

dev-master

9999999-dev

  Sources   Download

MIT

The Development Requires

by Paul Scott

25/09 2014

0.4

0.4.0.0

  Sources   Download

MIT

The Development Requires

by Paul Scott

16/09 2014

0.3

0.3.0.0

  Sources   Download

MIT

The Development Requires

by Paul Scott

15/09 2014

dev-feature/instance-refactor

dev-feature/instance-refactor

  Sources   Download

MIT

The Development Requires

by Paul Scott