grithin/file-include
Composer 安装命令:
composer require grithin/file-include
包简介
Include files in isolated context with options
关键字:
README 文档
README
For including files in an isolated context, but with injected variables, and potentially extracted variables.
composer require grithin/file-include
Use
use \Grithin\FileInclude; # inject `bob` into the file context, so file code can access $bob FileInclude::include('file.php', ['bob'=>$bob]); # inject the global $bob into the file global $bob; FileInclude::require_once('file2.php', null, ['globals'=>['bob']]);
Extraction
Extraction will adjust the return value. Whereas, normally, the return value is the return of the file, when variables are being extracted, the return changes into an array, where the normal return can be found in ['_return'=>$x]
file.php
$bob = 'bob'; return 123;
$result = FileInclude::include_once('file.php', null, ['extract'=>['bob']]); /*> [ '_return'=>123, 'bob'=>'bob' ] */
Notes
This is a rewrite and selection from \Grithin\Files in phpbase
统计信息
- 总下载量: 9
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-07-20