定制 icio/scope 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

icio/scope

最新稳定版本:0.4

Composer 安装命令:

composer require icio/scope

包简介

README 文档

README

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.

For example, instead of doing:

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

with KeyState you can set an Array key state:

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

Currently available scopes help with:

  • 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.

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:

$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).

统计信息

  • 总下载量: 21
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 2
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-11-20

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固