當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。