protected function execute(InputInterface $input, OutputInterface $output) { $this->validateInput($input); $environment = $this->getSelectedEnvironment(); $limit = (int) $input->getOption('limit'); $activities = $environment->getActivities($limit, $input->getOption('type')); if (!$activities) { $this->stdErr->writeln('No activities found'); return 1; } $headers = array("ID", "Created", "Description", "% Complete", "Result"); $rows = array(); foreach ($activities as $activity) { $description = $activity->getDescription(); $description = wordwrap($description, 40); $rows[] = array($activity['id'], date('Y-m-d H:i:s', strtotime($activity['created_at'])), $description, $activity->getCompletionPercent(), $activity->state); } if ($output instanceof StreamOutput && $input->getOption('pipe')) { $stream = $output->getStream(); array_unshift($rows, $headers); foreach ($rows as $row) { fputcsv($stream, $row, "\t"); } return 0; } $this->stdErr->writeln("Recent activities for the environment <info>" . $environment['id'] . "</info>"); $table = new Table($output); $table->setHeaders($headers); $table->addRows($rows); $table->render(); return 0; }
/** * Gets the display returned by the last execution of the application. * * @param bool $normalize Whether to normalize end of lines to \n or not * * @return string The display */ public function getDisplay($normalize = false) { rewind($this->output->getStream()); $display = stream_get_contents($this->output->getStream()); if ($normalize) { $display = str_replace(PHP_EOL, "\n", $display); } return $display; }
/** * Determine if reporter is reporting to a tty terminal * * @return bool */ private function hasTty() { if (getenv("PERIDOT_TTY")) { return true; } $tty = function_exists('posix_isatty') && @posix_isatty($this->output->getStream()); if ($tty) { putenv("PERIDOT_TTY=1"); } return $tty; }
public function dump_output(OutputInterface $output_formatter) { $dump = ''; if ($output_formatter instanceof StreamOutput) { $stream = $output_formatter->getStream(); // rewind stream to read full contents rewind($stream); $dump = stream_get_contents($stream); } else { var_dump($output_formatter); throw new \Exception('Cannot dump output of type "' . get_class($output_formatter) . '"!'); } return $dump; }
/** * @param \Symfony\Component\Console\Output\OutputInterface $output * @param array $rows */ public function render(OutputInterface $output, array $rows) { if ($output instanceof StreamOutput) { $stream = $output->getStream(); } else { $stream = \STDOUT; } $i = 0; foreach ($rows as $row) { if ($i++ == 0) { fputcsv($stream, array_keys($row)); } fputcsv($stream, $row); } }
/** * {@inheritdoc} */ public function render(OutputInterface $output, array $rows) { // no rows - there is nothing to do if (!$rows) { return; } if ($output instanceof StreamOutput) { $stream = $output->getStream(); } else { $stream = \STDOUT; } fputcsv($stream, array_keys(reset($rows))); foreach ($rows as $row) { fputcsv($stream, $row); } }
public static function create(OutputInterface $output) { return $output instanceof StreamOutput ? new StreamHandler($output->getStream()) : new self($output); }
/** * Detect automatically whether the output is a TTY terminal. * * @param OutputInterface $output * * @return bool */ protected function isTerminal(OutputInterface $output) { if (!$output instanceof StreamOutput) { return false; } // If the POSIX extension doesn't exist, default to true. It's better // for Windows users if we assume the output is a terminal. if (!function_exists('posix_isatty')) { return true; } // This uses the same test as StreamOutput::hasColorSupport(). $stream = $output->getStream(); /** @noinspection PhpParamsInspection */ return @posix_isatty($stream); }
/** * @return string */ protected function getOutput() { rewind($this->output->getStream()); return stream_get_contents($this->output->getStream()); }