nikic/include-interceptor
最新稳定版本:v0.1.2
Composer 安装命令:
composer require nikic/include-interceptor
包简介
Intercept PHP includes
README 文档
README
Library to intercept PHP includes. A fork of icewind1991/interceptor.
composer require nikic/include-interceptor
Usage
use Nikic\IncludeInterceptor\Interceptor; $interceptor = new Interceptor(function(string $path) { if (!wantToIntercept($path)) { return null; } return transformCode(file_get_contents($path)); }); $interceptor->setUp(); // Start intercepting includes require 'src/foo.php'; $interceptor->tearDown(); // Stop intercepting includes
The interception hook follows the following contract:
- It is only called if the included file exists.
- The passed
$pathis the realpath. - If the hook returns
null, no interception is performed. - If the hook returns a string, these are taken as the transformed content of the file.
For convenience, a FileFilter is provided that implements white- and black-listing
of files and directories. Paths passed to addBlackList() and addWhiteList() should
always be realpaths.
use Nikic\IncludeInterceptor\Interceptor; use Nikic\IncludeInterceptor\FileFilter; $fileFilter = FileFilter::createAllWhitelisted(); // Start with everything whitelisted $fileFilter->addBlackList(__DIR__ . '/src/'); // Blacklist the src/ directory $fileFilter->addWhiteList(__DIR__ . '/src/foo.php'); // But whitelist the src/foo.php file $interceptor = new Interceptor(function(string $path) use ($fileFilter) { if (!$fileFilter->test($path)) { return null; } return transformCode(file_get_contents($path)); }); $interceptor->setUp(); require 'src/foo.php';
统计信息
- 总下载量: 27.28k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 69
- 点击次数: 2
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-12-28