lapaz / plain-php
支持普通PHP脚本文件
0.1.1
2018-02-16 03:31 UTC
Requires
- php: ^5.6||^7.0
Requires (Dev)
- phpunit/phpunit: ^5.7.20||^6.0
This package is auto-updated.
Last update: 2024-09-05 18:46:30 UTC
README
比使用extract()
和require
方式更安全的普通PHP脚本文件运行器。
快速开始
要加载以下config-file.php
脚本
<?php /* @var $this SomeObject */ return [ // your config 'some-element' => $parameter, 'another-element' => $anotherParameter, 'element-by-method-call' => $this->getConfigElement(), ];
请使用下面的ScriptRunner代替原始的require
语句。
$config = ScriptRunner::which()->requires('path/to/config-file.php')->with([ 'parameter' => '...', 'anotherParameter' => '...', ])->binding($someObject)->run();
特性
- 比原始的
require
或include
更封闭和安全的评估 - 将任何对象绑定为目标文件中的
$this
变量 - 不可变且可分支的变量绑定上下文