本文整理汇总了PHP中Psy\Shell::flushCode方法的典型用法代码示例。如果您正苦于以下问题:PHP Shell::flushCode方法的具体用法?PHP Shell::flushCode怎么用?PHP Shell::flushCode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Psy\Shell
的用法示例。
在下文中一共展示了Shell::flushCode方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getClosure
/**
* @return callable
*/
private function getClosure()
{
$closure = function () {
extract($this->shellSoul->getScopeVariables());
try {
$this->shellSoul->addCode($this->code);
// evaluate the current code buffer
ob_start([$this->shellSoul, 'writeStdout'], version_compare(PHP_VERSION, '5.4', '>=') ? 1 : 2);
set_error_handler([$this->shellSoul, 'handleError']);
$_ = eval($this->shellSoul->flushCode() ?: Loop::NOOP_INPUT);
restore_error_handler();
ob_end_flush();
$this->shellSoul->writeReturnValue($_);
} catch (BreakException $_e) {
restore_error_handler();
if (ob_get_level() > 0) {
ob_end_clean();
}
$this->shellSoul->writeException($_e);
return;
} catch (ThrowUpException $_e) {
restore_error_handler();
if (ob_get_level() > 0) {
ob_end_clean();
}
$this->shellSoul->writeException($_e);
throw $_e;
} catch (\Exception $_e) {
restore_error_handler();
if (ob_get_level() > 0) {
ob_end_clean();
}
$this->shellSoul->writeException($_e);
}
$this->shellSoul->setScopeVariables(get_defined_vars());
};
return $closure;
}
示例2: testClosuresSupport
public function testClosuresSupport()
{
$shell = new Shell($this->getConfig());
$code = '$test = function () {}';
$shell->addCode($code);
$shell->flushCode();
$code = '$test()';
$shell->addCode($code);
$shell->flushCode();
}
示例3: testCodeBufferThrowsParseExceptions
/**
* @expectedException \Psy\Exception\ParseErrorException
*/
public function testCodeBufferThrowsParseExceptions()
{
$shell = new Shell();
$shell->addCode('this is not valid');
$shell->flushCode();
}