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


PHP StreamOutput::write方法代码示例

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


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

示例1: run

 /**
  * {@inheritDoc}
  */
 public function run(OutputInterface $output)
 {
     /** @type DebugFormatterHelper $debugFormatter */
     $debugFormatter = $this->getHelperSet()->get('debug_formatter');
     $arguments = $this->resolveProcessArgs();
     $builder = new ProcessBuilder($arguments);
     $process = $builder->getProcess();
     if (null !== ($dispatcher = $this->getEventDispatcher())) {
         $event = new PreExecuteEvent($this, $process);
         $dispatcher->dispatch(Event::PRE_EXECUTE, $event);
         if ($event->isPropagationStopped()) {
             return true;
         }
     }
     if ($output->getVerbosity() === OutputInterface::VERBOSITY_VERY_VERBOSE) {
         $output->writeln(sprintf('        // Setting timeout for %d seconds.', $this->getParameter('timeout')));
     }
     $process->setTimeout($this->getParameter('timeout') !== 0 ? $this->getParameter('timeout') : null);
     if ($this->hasParameter('cwd')) {
         $process->setWorkingDirectory($this->getParameter('cwd'));
     }
     if (get_class($this) === 'Bldr\\Block\\Execute\\Task\\ExecuteTask') {
         $output->writeln(['', sprintf('    <info>[%s]</info> - <comment>Starting</comment>', $this->getName()), '']);
     }
     if ($output->getVerbosity() === OutputInterface::VERBOSITY_VERBOSE || $this->getParameter('dry_run')) {
         $output->writeln('        // ' . $process->getCommandLine());
     }
     if ($this->getParameter('dry_run')) {
         return true;
     }
     if ($this->hasParameter('output')) {
         $append = $this->hasParameter('append') && $this->getParameter('append') ? 'a' : 'w';
         $stream = fopen($this->getParameter('output'), $append);
         $output = new StreamOutput($stream, StreamOutput::VERBOSITY_NORMAL, true);
     }
     $output->writeln("<fg=blue>==============================\n</fg=blue>");
     $output->writeln($debugFormatter->start(spl_object_hash($process), $process->getCommandLine()));
     $process->run(function ($type, $buffer) use($output, $debugFormatter, $process) {
         if ($this->getParameter('raw')) {
             $output->write($buffer, false, OutputInterface::OUTPUT_RAW);
             return;
         }
         $output->write($debugFormatter->progress(spl_object_hash($process), $buffer, Process::ERR === $type));
     });
     $output->writeln($debugFormatter->stop(spl_object_hash($process), $process->getCommandLine(), $process->isSuccessful()));
     $output->writeln("<fg=blue>==============================</fg=blue>");
     if (null !== $dispatcher) {
         $event = new PostExecuteEvent($this, $process);
         $dispatcher->dispatch(Event::POST_EXECUTE, $event);
     }
     if (!in_array($process->getExitCode(), $this->getParameter('successCodes'))) {
         throw new TaskRuntimeException($this->getName(), $process->getErrorOutput());
     }
 }
开发者ID:kangkot,项目名称:bldr,代码行数:57,代码来源:ExecuteTask.php

示例2: printLegend

 public function printLegend()
 {
     $symbols = array();
     foreach (self::$eventStatusMap as $status) {
         $symbol = $status['symbol'];
         if ('' === $symbol || isset($symbols[$symbol])) {
             continue;
         }
         $symbols[$symbol] = sprintf('%s-%s', $this->output->isDecorated() ? sprintf($status['format'], $symbol) : $symbol, $status['description']);
     }
     $this->output->write(sprintf("\nLegend: %s\n", implode(', ', $symbols)));
 }
开发者ID:cryode,项目名称:PHP-CS-Fixer,代码行数:12,代码来源:ProcessOutput.php

示例3: startProcess

 /**
  * Creates the given process
  *
  * @throws \Exception
  */
 private function startProcess(OutputInterface $output)
 {
     $arguments = $this->resolveProcessArgs();
     $name = sha1(serialize($arguments));
     if ($this->background->hasProcess($name)) {
         throw new \RuntimeException("Service is already running.");
     }
     $builder = new ProcessBuilder($arguments);
     if ($this->hasParameter('cwd')) {
         $builder->setWorkingDirectory($this->getParameter('cwd'));
     }
     $process = $builder->getProcess();
     if ($output->getVerbosity() === OutputInterface::VERBOSITY_VERBOSE) {
         $output->writeln($process->getCommandLine());
     }
     if ($this->hasParameter('output')) {
         $append = $this->hasParameter('append') && $this->getParameter('append') ? 'a' : 'w';
         $stream = fopen($this->getParameter('output'), $append);
         $output = new StreamOutput($stream, StreamOutput::VERBOSITY_NORMAL, true);
     }
     $process->start(function ($type, $buffer) use($output) {
         $output->write($buffer);
     });
     $this->background->addProcess($name, $process);
     if (!in_array($process->getExitCode(), $this->getParameter('successCodes'))) {
         throw new TaskRuntimeException($this->getName(), $process->getErrorOutput());
     }
 }
开发者ID:kangkot,项目名称:bldr,代码行数:33,代码来源:BackgroundTask.php

示例4: execute

 /**
  * @inheritdoc
  */
 public function execute(ResultCollection $collection, ResultCollection $aggregatedResults)
 {
     if (!$this->destination) {
         return;
     }
     $dir = dirname($this->destination);
     if (!file_exists($dir)) {
         mkdir($dir, 0777, true);
     }
     $this->output->writeln(sprintf('Generating %s Report...', $this->formater->getName()));
     $handle = fopen($this->destination, 'w');
     $stream = new StreamOutput($handle);
     $stream->write($this->formater->terminate($collection, $aggregatedResults));
     fclose($handle);
 }
开发者ID:truffo,项目名称:PhpMetrics,代码行数:18,代码来源:ReportWriter.php

示例5: run

 /**
  * {@inheritDoc}
  */
 public function run(OutputInterface $output)
 {
     $arguments = $this->resolveProcessArgs();
     $builder = new ProcessBuilder($arguments);
     if (null !== ($dispatcher = $this->getEventDispatcher())) {
         $event = new PreExecuteEvent($this, $builder);
         $dispatcher->dispatch(Event::PRE_EXECUTE, $event);
         if ($event->isPropagationStopped()) {
             return true;
         }
     }
     if ($output->getVerbosity() === OutputInterface::VERBOSITY_VERY_VERBOSE) {
         $output->writeln(sprintf('        // Setting timeout for %d seconds.', $this->getParameter('timeout')));
     }
     $builder->setTimeout($this->getParameter('timeout') !== 0 ? $this->getParameter('timeout') : null);
     if ($this->hasParameter('cwd')) {
         $builder->setWorkingDirectory($this->getParameter('cwd'));
     }
     $process = $builder->getProcess();
     if (get_class($this) === 'Bldr\\Block\\Execute\\Task\\ExecuteTask') {
         $output->writeln(['', sprintf('    <info>[%s]</info> - <comment>Starting</comment>', $this->getName()), '']);
     }
     if ($output->getVerbosity() === OutputInterface::VERBOSITY_VERBOSE || $this->getParameter('dry_run')) {
         $output->writeln('        // ' . $process->getCommandLine());
     }
     if ($this->getParameter('dry_run')) {
         return true;
     }
     if ($this->hasParameter('output')) {
         $append = $this->hasParameter('append') && $this->getParameter('append') ? 'a' : 'w';
         $stream = fopen($this->getParameter('output'), $append);
         $output = new StreamOutput($stream, StreamOutput::VERBOSITY_NORMAL, true);
     }
     $process->start(function ($type, $buffer) use($output) {
         $output->write("\r        " . str_replace("\n", "\n        ", $buffer));
     });
     while ($process->isRunning()) {
     }
     if (null !== $dispatcher) {
         $event = new PostExecuteEvent($this, $process);
         $dispatcher->dispatch(Event::POST_EXECUTE, $event);
     }
     if (!in_array($process->getExitCode(), $this->getParameter('successCodes'))) {
         throw new TaskRuntimeException($this->getName(), $process->getErrorOutput());
     }
 }
开发者ID:gitter-badger,项目名称:bldr,代码行数:49,代码来源:ExecuteTask.php

示例6: updateAction

 /**
  * @Request(csrf=true)
  */
 public function updateAction()
 {
     if (!($file = App::session()->get('system.update'))) {
         App::abort(400, __('You may not call this step directly.'));
     }
     App::session()->remove('system.update');
     return App::response()->stream(function () use($file) {
         $output = new StreamOutput(fopen('php://output', 'w'));
         try {
             if (!file_exists($file) || !is_file($file)) {
                 throw new \RuntimeException('File does not exist.');
             }
             $updater = new SelfUpdater($output);
             $updater->update($file);
         } catch (\Exception $e) {
             $output->writeln(sprintf("\n<error>%s</error>", $e->getMessage()));
             $output->write("status=error");
         }
     });
 }
开发者ID:pagekit,项目名称:pagekit,代码行数:23,代码来源:UpdateController.php

示例7: write

 /**
  * Write to output
  *
  * @param array|string $messages Messages
  * @param bool         $newline  Whether to append a newline
  * @param int          $type     The output type
  *
  * @return void
  */
 public function write($messages, $newline = false, $type = \Symfony\Component\Console\Output\Output::OUTPUT_NORMAL)
 {
     $messages = (array) $messages;
     foreach ($messages as &$message) {
         $l = strlen($message) - 1;
         if ($l >= 0) {
             if ($message[$l] === "\n") {
                 $message = substr($message, 0, $l);
                 $l--;
                 $newline = true;
             }
             if ($this->previousWasNewLine && $l >= 0 && $message[0] !== "\n") {
                 $message = $this->getIndention() . $message;
             }
             if (strpos($message, "\n") !== false) {
                 $message = str_replace("\n", "\n" . $this->getIndention(), $message);
             }
             // TODO: Indent wrapped lines - that's just not that easy because of the ANSI color escape codes
         }
     }
     parent::write($messages, $newline, $type);
     $this->previousWasNewLine = $newline;
 }
开发者ID:netresearch,项目名称:kite,代码行数:32,代码来源:Output.php


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