lapaz/plain-php

支持普通PHP脚本文件

0.1.1 2018-02-16 03:31 UTC

This package is auto-updated.

Last update: 2024-09-05 18:46:30 UTC


README

Build Status

比使用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();

特性

  • 比原始的requireinclude更封闭和安全的评估
  • 将任何对象绑定为目标文件中的$this变量
  • 不可变且可分支的变量绑定上下文