adamquaile/php-global-abstraction
最新稳定版本:v2.0.0
Composer 安装命令:
composer require adamquaile/php-global-abstraction
包简介
Wrapper around features of PHP which affect global scope
README 文档
README
This library provides object-oriented wrappers around some of the features of PHP affecting global scope.
The currently implemented features are:
- Constants
- Functions
- Echo / Print
Global state is evil. Avoid it wherever possible. Do not think this library makes it okay.
This library has two main use cases:
- when you're working in an environment where it's unavoidable, and you still want code you write as testable as possible
- while you're refactoring your code to get out of this mess
Usage
Install it with composer, adamquaile/php-global-abstraction.
Constants
<?php
$constants = new \AdamQuaile\PhpGlobal\Constants\ConstantWrapper();
$constants->set('key', 'value');
$constants->get('key');
$constants->isDefined('key');
Functions
<?php
$functions = new \AdamQuaile\PhpGlobal\Functions\FunctionWrapper(
new FunctionCreator(),
new FunctionInvoker()
);
# Create function with a specified name
$functions->create($callable, 'func_in_global_scope');
\func_in_global_scope($arguments);
# Create function and return its automatically generated name
$functionName = $functions->create($callable);
$$functionName($arguments);
# Call a function existing in global scope
$functions->invoke('strlen', 'hello world');
Echo / Print
<?php
$output = new \AdamQuaile\PhpGlobal\Output\EchoWrapper();
$output->output('Hello ', $world);
统计信息
- 总下载量: 108
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 3
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-01-31