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


PHP Shell::setScopeVariables方法代码示例

本文整理汇总了PHP中Psy\Shell::setScopeVariables方法的典型用法代码示例。如果您正苦于以下问题:PHP Shell::setScopeVariables方法的具体用法?PHP Shell::setScopeVariables怎么用?PHP Shell::setScopeVariables使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Psy\Shell的用法示例。


在下文中一共展示了Shell::setScopeVariables方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: execute

    /**
     * @param InputInterface  $input
     * @param OutputInterface $output
     *
     * @return int|void
     */
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $initialized = false;
        try {
            $this->detectMagento($output);
            $initialized = $this->initMagento();
        } catch (Exception $e) {
            // do nothing
        }
        $parser = new Parser(new Lexer());
        $cleaner = new CodeCleaner($parser);
        $consoleOutput = new ShellOutput();
        $config = new Configuration();
        $config->setCodeCleaner($cleaner);
        $shell = new Shell($config);
        $shell->setScopeVariables(['di' => $this->getObjectManager()]);
        if ($initialized) {
            $ok = Charset::convertInteger(Charset::UNICODE_CHECKMARK_CHAR);
            $edition = $this->productMeta->getEdition();
            $magentoVersion = $this->productMeta->getVersion();
            $consoleOutput->writeln('<fg=black;bg=green>Magento ' . $magentoVersion . ' ' . $edition . ' initialized.</fg=black;bg=green> ' . $ok);
        } else {
            $consoleOutput->writeln('<fg=black;bg=yellow>Magento is not initialized.</fg=black;bg=yellow>');
        }
        $help = <<<'help'
At the prompt, type <comment>help</comment> for some help.

To exit the shell, type <comment>^D</comment>.
help;
        $consoleOutput->writeln($help);
        $shell->run($input, $consoleOutput);
    }
开发者ID:ktomk,项目名称:n98-magerun2,代码行数:38,代码来源:ConsoleCommand.php

示例2: run

 /**
  * Run the execution loop.
  *
  * Forks into a master and a loop process. The loop process will handle the
  * evaluation of all instructions, then return its state via a socket upon
  * completion.
  *
  * @param Shell $shell
  */
 public function run(Shell $shell)
 {
     list($up, $down) = stream_socket_pair(STREAM_PF_UNIX, STREAM_SOCK_STREAM, STREAM_IPPROTO_IP);
     if (!$up) {
         throw new \RuntimeException('Unable to create socket pair.');
     }
     $pid = pcntl_fork();
     if ($pid < 0) {
         throw new \RuntimeException('Unable to start execution loop.');
     } elseif ($pid > 0) {
         // This is the main thread. We'll just wait for a while.
         // We won't be needing this one.
         fclose($up);
         // Wait for a return value from the loop process.
         $read = array($down);
         $write = null;
         $except = null;
         if (stream_select($read, $write, $except, null) === false) {
             throw new \RuntimeException('Error waiting for execution loop.');
         }
         $content = stream_get_contents($down);
         fclose($down);
         if ($content) {
             $shell->setScopeVariables(@unserialize($content));
         }
         return;
     }
     // This is the child process. It's going to do all the work.
     if (function_exists('setproctitle')) {
         setproctitle('psysh (loop)');
     }
     // We won't be needing this one.
     fclose($down);
     // Let's do some processing.
     parent::run($shell);
     // Send the scope variables back up to the main thread
     fwrite($up, $this->serializeReturn($shell->getScopeVariables()));
     fclose($up);
     exit;
 }
开发者ID:EnmanuelCode,项目名称:backend-laravel,代码行数:49,代码来源:ForkingLoop.php

示例3: 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;
 }
开发者ID:Litipk,项目名称:Jupyter-PHP,代码行数:41,代码来源:ExecuteAction.php

示例4: testUnknownScopeVariablesThrowExceptions

 /**
  * @expectedException \InvalidArgumentException
  */
 public function testUnknownScopeVariablesThrowExceptions()
 {
     $shell = new Shell($this->getConfig());
     $shell->setScopeVariables(array('foo' => 'FOO', 'bar' => 1));
     $shell->getScopeVariable('baz');
 }
开发者ID:EnmanuelCode,项目名称:backend-laravel,代码行数:9,代码来源:ShellTest.php

示例5: execute

 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $shell = new Shell();
     $shell->setScopeVariables(['app' => $this->container, 'config' => $this->container->get(ConfigurationInterface::class)]);
     $shell->run();
 }
开发者ID:hannesvdvreken,项目名称:glue,代码行数:9,代码来源:TinkerCommand.php

示例6: initialize

 protected function initialize(InputInterface $input, OutputInterface $output)
 {
     $this->psysh = $this->getContainer()->get('shell.psysh');
     $this->psysh->setScopeVariables(['container' => $this->getContainer()->get('service_container'), 'kernel' => $this->getContainer()->get('kernel')]);
 }
开发者ID:wilbros,项目名称:SlurpREPL,代码行数:5,代码来源:SlurpCommand.php


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