当前位置: 首页>>代码示例>>PHP>>正文


PHP Shell::getScopeVariable方法代码示例

本文整理汇总了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);
 }
开发者ID:HarveyCheng,项目名称:myblog,代码行数:19,代码来源:ShellTest.php

示例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);
 }
开发者ID:kpaxer,项目名称:shcms,代码行数:77,代码来源:Loop.php


注:本文中的Psy\Shell::getScopeVariable方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。