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


PHP Output\StreamOutput类代码示例

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


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

示例1: testFormattedEscapedOutput

 public function testFormattedEscapedOutput()
 {
     $output = new StreamOutput($this->stream, StreamOutput::VERBOSITY_NORMAL, true, null);
     $output->writeln('<info>' . OutputFormatter::escape('<error>some error</error>') . '</info>');
     rewind($output->getStream());
     $this->assertSame("[32m<error>some error</error>[39m" . PHP_EOL, stream_get_contents($output->getStream()));
 }
开发者ID:tronsha,项目名称:cerberus,代码行数:7,代码来源:ConsoleTest.php

示例2: testDoWrite

 public function testDoWrite()
 {
     $output = new StreamOutput($this->stream);
     $output->writeln('foo');
     rewind($output->getStream());
     $this->assertEquals('foo' . PHP_EOL, stream_get_contents($output->getStream()), '->doWrite() writes to the stream');
 }
开发者ID:Ener-Getick,项目名称:symfony,代码行数:7,代码来源:StreamOutputTest.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

 protected function execute(InputInterface $input, OutputInterface $output)
 {
     if (NULL !== ($file = $input->getOption('file'))) {
         if (is_file($file) && !$input->getOption('overwrite')) {
             $output->writeln(sprintf('File <info>%s</info> already exists, use option <comment>-o</comment> to overwrite it.', $file));
             return;
         }
         $backup = $output;
         $fp = fopen($file, 'wb');
         $output = new StreamOutput($fp);
     }
     $request = new HttpRequest(new Uri('http://test.me/'));
     $this->requestScope->enter($request);
     try {
         $output->writeln('routes:');
         $routes = $this->router->getRoutes($this->context)->getSortedRoutes();
         foreach (array_reverse($routes) as $name => $route) {
             $output->writeln(sprintf('  %s:', $name));
             foreach (explode("\n", trim(Yaml::dump($route->toArray($this->context), 100))) as $line) {
                 $output->writeln(sprintf('    %s', $line));
             }
         }
     } finally {
         $this->requestScope->leave($request);
     }
     if (isset($fp) && is_resource($fp)) {
         @fclose($fp);
         $backup->writeln(sprintf('Config dumped to <info>%s</info>', $file));
     }
 }
开发者ID:koolkode,项目名称:http-komponent,代码行数:30,代码来源:DumpRoutesCommand.php

示例5: run

 /**
  * Executes the application.
  *
  * Available options:
  *
  *  * interactive:               Sets the input interactive flag
  *  * decorated:                 Sets the output decorated flag
  *  * verbosity:                 Sets the output verbosity flag
  *  * capture_stderr_separately: Make output of stdOut and stdErr separately available
  *
  * @param array $input   An array of arguments and options
  * @param array $options An array of options
  *
  * @return int The command exit code
  */
 public function run(array $input, $options = array())
 {
     $this->input = new ArrayInput($input);
     if (isset($options['interactive'])) {
         $this->input->setInteractive($options['interactive']);
     }
     $this->captureStreamsIndependently = array_key_exists('capture_stderr_separately', $options) && $options['capture_stderr_separately'];
     if (!$this->captureStreamsIndependently) {
         $this->output = new StreamOutput(fopen('php://memory', 'w', false));
         if (isset($options['decorated'])) {
             $this->output->setDecorated($options['decorated']);
         }
         if (isset($options['verbosity'])) {
             $this->output->setVerbosity($options['verbosity']);
         }
     } else {
         $this->output = new ConsoleOutput(isset($options['verbosity']) ? $options['verbosity'] : ConsoleOutput::VERBOSITY_NORMAL, isset($options['decorated']) ? $options['decorated'] : null);
         $errorOutput = new StreamOutput(fopen('php://memory', 'w', false));
         $errorOutput->setFormatter($this->output->getFormatter());
         $errorOutput->setVerbosity($this->output->getVerbosity());
         $errorOutput->setDecorated($this->output->isDecorated());
         $reflectedOutput = new \ReflectionObject($this->output);
         $strErrProperty = $reflectedOutput->getProperty('stderr');
         $strErrProperty->setAccessible(true);
         $strErrProperty->setValue($this->output, $errorOutput);
         $reflectedParent = $reflectedOutput->getParentClass();
         $streamProperty = $reflectedParent->getProperty('stream');
         $streamProperty->setAccessible(true);
         $streamProperty->setValue($this->output, fopen('php://memory', 'w', false));
     }
     return $this->statusCode = $this->application->run($this->input, $this->output);
 }
开发者ID:Ener-Getick,项目名称:symfony,代码行数:47,代码来源:ApplicationTester.php

示例6: readOutput

 /**
  * Returns the contents of the output stream.
  *
  * @param StreamOutput $output The output manager.
  *
  * @return string The contents of the stream.
  */
 public function readOutput(StreamOutput $output)
 {
     $contents = '';
     $stream = $output->getStream();
     rewind($stream);
     do {
         $contents .= fgets($stream);
     } while (!feof($stream));
     return $contents;
 }
开发者ID:bangpound,项目名称:console,代码行数:17,代码来源:CommandTestCase.php

示例7: getOutputBuffer

 /**
  * helper method to get output as string out of a StreamOutput
  *
  * @param $output
  *
  * @return string all output
  */
 protected function getOutputBuffer(StreamOutput $output)
 {
     $handle = $output->getStream();
     rewind($handle);
     $display = stream_get_contents($handle);
     // Symfony2's StreamOutput has a hidden dependency on PHP_EOL which needs to be removed by
     // normalizing it to the standard newline for text here.
     $display = strtr($display, array(PHP_EOL => "\n"));
     return $display;
 }
开发者ID:netz98,项目名称:n98-magerun,代码行数:17,代码来源:TestCase.php

示例8: execute

 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->loadConfig($input);
     $ignore_locked = false;
     $from_date = $this->getHarvestFromDate("Ymd", "3 days ago");
     $to_date = $this->getHarvestToDate("Ymd", "today");
     $chartType = $this->getChartType(null);
     $chartPeriod = $this->getChartPeriod(null);
     if (!($outputFilename = $input->getOption("output-file"))) {
         $outputFilename = 'FetchUserActivity-' . $from_date . '-' . $to_date . '.json';
     }
     $output->writeln('FetchUserActivity executed: ' . date('Ymd H:i:s'));
     $output->writeln('Verifying projects in Harvest');
     $output->writeln('Output filename: ' . $outputFilename);
     if ($this->getHarvestExcludeContractors()) {
         $output->writeln('NOTE: Contractors are excluded from the dataset!');
     }
     $ticketEntries = $this->getEntriesByUsers($from_date, $to_date);
     $output->writeln(sprintf('Collected %d ticket entries', sizeof($ticketEntries)));
     if (sizeof($ticketEntries) == 0) {
         //We have no entries containing ticket ids so bail
         return;
     }
     // GET THE LATEST ENTRY FOR EACH USER IN PERIOD REGARDLESS OF PROJECT
     $sortedEntries = null;
     foreach ($ticketEntries as $userArray) {
         foreach ($userArray as $entry) {
             $notes = strlen($entry->get('notes')) > 0 ? $entry->get('notes') : "...";
             $output->writeln(sprintf('%s | %s - %s: "%s" (%s timer @ %s)', self::getUserNameById($entry->get('user-id')), self::getProjectNameById($entry->get('project-id')), self::getTaskNameById($entry->get("task-id")), $notes, $entry->get('hours'), $entry->get('spent-at')));
             $sortedEntries[strtotime($entry->get("updated-at"))] = $entry;
         }
     }
     krsort($sortedEntries);
     $userSortedEntries = null;
     foreach ($sortedEntries as $updated => $entry) {
         if (!isset($userSortedEntries[$entry->get('user-id')])) {
             $userSortedEntries[$entry->get('user-id')]['project'] = self::getProjectNameById($entry->get('project-id'));
             $userSortedEntries[$entry->get('user-id')]['task'] = self::getTaskNameById($entry->get('task-id'));
             $userSortedEntries[$entry->get('user-id')]['username'] = self::getUserNameById($entry->get('user-id'));
             $userSortedEntries[$entry->get('user-id')]['notes'] = $entry->get("notes");
             $userSortedEntries[$entry->get('user-id')]['updated-at'] = $entry->get("updated-at");
             $userSortedEntries[$entry->get('user-id')]['timer-started-at'] = $entry->get("timer-started-at");
             $userSortedEntries[$entry->get('user-id')]['project-id'] = $entry->get('project-id');
             $userSortedEntries[$entry->get('user-id')]['spent-at'] = $entry->get('spent-at');
         } else {
             continue;
         }
     }
     $json = json_encode($userSortedEntries);
     // let's write the response to a file
     $outputFile = new StreamOutput(fopen('data/' . $outputFilename, 'w', false));
     $outputFile->doWrite($json, false);
     $output->writeln("FetchUserActivity completed -> " . $outputFilename . " updated");
 }
开发者ID:reload,项目名称:harvestdata,代码行数:54,代码来源:FetchUserActivity.php

示例9: readOutput

 /**
  * Reads the contents of an output stream.
  *
  * @param StreamOutput $output The stream output manager.
  *
  * @return string The contents of the stream.
  */
 protected function readOutput(StreamOutput $output)
 {
     $stream = $output->getStream();
     $contents = '';
     rewind($stream);
     do {
         $contents .= fgets($stream);
     } while (!feof($stream));
     fclose($stream);
     return $contents;
 }
开发者ID:box-project,项目名称:box3,代码行数:18,代码来源:AbstractCommandTestCase.php

示例10: execute

 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->loadConfig($input);
     $from_date = $this->getHarvestFromDate("Ymd", "yesterday");
     $to_date = $this->getHarvestToDate("Ymd", "yesterday");
     $chartType = $this->getChartType();
     $chartPeriod = $this->getChartPeriod();
     if (!($outputFilename = $input->getOption("output-file"))) {
         $outputFilename = 'FetchData-' . $from_date . '-' . $to_date . '.xml';
     }
     $output->writeln('FetchData executed: ' . date('Ymd H:i:s'));
     $output->writeln('Output filename: ' . $outputFilename);
     if ($this->getHarvestExcludeContractors()) {
         $output->writeln('NOTE: Contractors are excluded from the dataset!');
     }
     $output->writeln(sprintf('Chart type is "%s" and period is "%s"', $chartType, $chartPeriod));
     $output->writeln(sprintf("Collecting Harvest entries between %s to %s", $from_date, $to_date));
     switch ($chartType) {
         case 'singlecolumn':
             $sortedTicketEntries = $this->fetchBillableHoursInPeriod($from_date, $to_date);
             $data = \GeckoChart::makeSingleColumn($sortedTicketEntries, $chartPeriod);
             break;
             // used for displaying budget vs. actual billable hours
         // used for displaying budget vs. actual billable hours
         case 'columnspline':
             $sortedTicketEntries = $this->fetchBillableHoursInPeriod($from_date, $to_date);
             $data = \GeckoChart::makeSingleColumnWithSpline($sortedTicketEntries, $chartPeriod);
             break;
         case 'stackedcolumn':
             $assembledEntries = $this->fetchAllHoursInPeriod($from_date, $to_date);
             $data = \GeckoChart::makeStackedColumn($assembledEntries, $chartPeriod);
             break;
         case 'piechart':
             $assembledEntries = $this->fetchAllHoursInPeriod($from_date, $to_date);
             $chartPeriodTitle = date("M. jS", strtotime($from_date)) . " - " . date("M. jS", strtotime($to_date));
             $data = \GeckoChart::makePieChart($assembledEntries, $chartPeriodTitle);
             break;
         default:
             $output->writeln("FetchData ChartType not recognized -> " . $chartType . "");
             return;
             break;
     }
     // lets write the data to a file
     if ($data) {
         $outputFile = new StreamOutput(fopen('data/' . $outputFilename, 'w', false));
         $outputFile->doWrite($data, false);
         $output->writeln("\nFetchData completed -> " . $outputFilename . " updated");
     }
 }
开发者ID:reload,项目名称:harvestdata,代码行数:49,代码来源:FetchData.php

示例11: 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

示例12: execute

 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->loadConfig($input);
     $ignore_locked = false;
     $from_date = $this->getHarvestFromDate("Ymd", "today");
     $to_date = $this->getHarvestToDate("Ymd", "today");
     $chartType = $this->getChartType(null);
     $chartPeriod = $this->getChartPeriod(null);
     if (!($outputFilename = $input->getOption("output-file"))) {
         $outputFilename = 'FetchEntries-' . $from_date . '-' . $to_date . '.xml';
     }
     $output->writeln('FetchEntries executed: ' . date('Ymd H:i:s'));
     $output->writeln('Verifying projects in Harvest');
     $output->writeln('Output filename: ' . $outputFilename);
     if ($this->getHarvestExcludeContractors()) {
         $output->writeln('NOTE: Contractors are excluded from the dataset!');
     }
     $ticketEntries = $this->getEntriesByUsers($from_date, $to_date);
     $output->writeln(sprintf('Collected %d ticket entries', sizeof($ticketEntries)));
     if (sizeof($ticketEntries) == 0) {
         //We have no entries containing ticket ids so bail
         return;
     }
     $sortedEntries = null;
     foreach ($ticketEntries as $userArray) {
         foreach ($userArray as $entry) {
             $notes = strlen($entry->get('notes')) > 0 ? $entry->get('notes') : "...";
             $output->writeln(sprintf('%s | %s - %s: "%s" (%s timer @ %s)', self::getUserNameById($entry->get('user-id')), self::getProjectNameById($entry->get('project-id')), self::getTaskNameById($entry->get("task-id")), $notes, $entry->get('hours'), $entry->get('spent-at')));
             $sortedEntries[strtotime($entry->get("updated-at"))] = $entry;
         }
     }
     krsort($sortedEntries);
     // get top 30
     $sortedEntries = array_slice($sortedEntries, 0, 30, true);
     // TODO: Refactor and move to GeckoChart.php
     // prepare the response!
     $geckoresponse = new \GeckoResponse();
     // format as text
     foreach ($sortedEntries as $entry) {
         $notes = strlen($entry->get('notes')) > 0 ? $entry->get('notes') : "[no notes]";
         $data['item'][] = array('text' => '<span class="t-size-x18">' . self::getProjectNameById($entry->get('project-id')) . ':</span><br/><span class="t-size-x24">"' . $notes . '"</span><br/><span class="t-size-x18">' . self::getUserNameById($entry->get('user-id')) . ' - ' . self::getTaskNameById($entry->get("task-id")) . ', ' . $entry->get('hours') . ' timer</span>', 'type' => 0);
     }
     $response = $geckoresponse->getResponse($data, true);
     // let's write the response to a file
     $outputFile = new StreamOutput(fopen('data/' . $outputFilename, 'w', false));
     $outputFile->doWrite($response, false);
     $output->writeln("FetchEntries completed -> " . $outputFilename . " updated");
 }
开发者ID:reload,项目名称:harvestdata,代码行数:48,代码来源:FetchEntries.php

示例13: 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

示例14: execute

 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $instance = $this->instances->find(Instance::makeId($input->getOption('root'), $input->getOption('name')));
     if (!$instance) {
         throw new \Exception("Failed to locate instance: " . Instance::makeId($input->getOption('root'), $input->getOption('name')));
     }
     $prefix = $input->getOption('prefix');
     $dsnParts = \DB\DSN::parseDSN($instance->getDsn());
     $output_file_path = $input->getOption('output-file');
     if ($output_file_path != '') {
         $output_file = fopen($output_file_path, "w");
         $output = new StreamOutput($output_file);
     }
     $envVars = array("{$prefix}URL" => $instance->getUrl(), "{$prefix}ROOT" => $instance->getRoot(), "{$prefix}DB_DSN" => $instance->getDsn(), "{$prefix}DB_USER" => $dsnParts['username'], "{$prefix}DB_PASS" => $dsnParts['password'], "{$prefix}DB_HOST" => $dsnParts['hostspec'], "{$prefix}DB_PORT" => $dsnParts['port'], "{$prefix}DB_NAME" => $dsnParts['database'], "{$prefix}DB_ARGS" => $instance->getDatasource() ? $instance->getDatasource()->toMySQLArguments() : '');
     foreach ($envVars as $var => $value) {
         $output->writeln($var . '=' . escapeshellarg($value));
     }
     // $output->writeln('export ' . implode(' ', array_keys($envVars)));
 }
开发者ID:eileenmcnaughton,项目名称:amp,代码行数:19,代码来源:ExportCommand.php

示例15: 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


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