本文整理汇总了PHP中Psy\Shell::getScopeVariable方法的典型用法代码示例。如果您正苦于以下问题:PHP Shell::getScopeVariable方法的具体用法?PHP Shell::getScopeVariable怎么用?PHP Shell::getScopeVariable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Psy\Shell
的用法示例。
在下文中一共展示了Shell::getScopeVariable方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testRenderingExceptions
public function testRenderingExceptions()
{
$shell = new Shell($this->getConfig());
$output = $this->getOutput();
$stream = $output->getStream();
$e = new ParseErrorException('message', 13);
$shell->addCode('code');
$this->assertTrue($shell->hasCode());
$this->assertNotEmpty($shell->getCodeBuffer());
$shell->renderException($e, $output);
$this->assertSame($e, $shell->getScopeVariable('_e'));
$this->assertFalse($shell->hasCode());
$this->assertEmpty($shell->getCodeBuffer());
rewind($stream);
$streamContents = stream_get_contents($stream);
$this->assertContains('PHP Parse error', $streamContents);
$this->assertContains('message', $streamContents);
$this->assertContains('line 13', $streamContents);
}
示例2: run
/**
* Run the execution loop.
*
* @throws ThrowUpException if thrown by the `throw-up` command.
*
* @param Shell $shell
*/
public function run(Shell $shell)
{
$loop = function ($__psysh__) {
// Load user-defined includes
set_error_handler(array($__psysh__, 'handleError'));
try {
foreach ($__psysh__->getIncludes() as $__psysh_include__) {
include $__psysh_include__;
}
} catch (\Exception $_e) {
$__psysh__->writeException($_e);
}
restore_error_handler();
unset($__psysh_include__);
extract($__psysh__->getScopeVariables());
do {
$__psysh__->beforeLoop();
$__psysh__->setScopeVariables(get_defined_vars());
try {
// read a line, see if we should eval
$__psysh__->getInput();
// evaluate the current code buffer
ob_start(array($__psysh__, 'writeStdout'), version_compare(PHP_VERSION, '5.4', '>=') ? 1 : 2);
set_error_handler(array($__psysh__, 'handleError'));
$_ = eval($__psysh__->flushCode());
restore_error_handler();
ob_end_flush();
$__psysh__->writeReturnValue($_);
} catch (BreakException $_e) {
restore_error_handler();
if (ob_get_level() > 0) {
ob_end_clean();
}
$__psysh__->writeException($_e);
return;
} catch (ThrowUpException $_e) {
restore_error_handler();
if (ob_get_level() > 0) {
ob_end_clean();
}
$__psysh__->writeException($_e);
throw $_e;
} catch (\Exception $_e) {
restore_error_handler();
if (ob_get_level() > 0) {
ob_end_clean();
}
$__psysh__->writeException($_e);
}
// a bit of housekeeping
unset($__psysh_out__);
$__psysh__->afterLoop();
} while (true);
};
// bind the closure to $this from the shell scope variables...
if (self::bindLoop()) {
$that = null;
try {
$that = $shell->getScopeVariable('this');
} catch (\InvalidArgumentException $e) {
// well, it was worth a shot
}
if (is_object($that)) {
$loop = $loop->bindTo($that, get_class($that));
} else {
$loop = $loop->bindTo(null, null);
}
}
$loop($shell);
}