本文整理汇总了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()));
}
示例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');
}
示例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());
}
}
示例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));
}
}
示例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);
}
示例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;
}
示例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;
}
示例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");
}
示例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;
}
示例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");
}
}
示例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);
}
示例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");
}
示例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());
}
}
示例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)));
}
示例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");
}
});
}