當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Formatter\OutputFormatter類代碼示例

本文整理匯總了PHP中Symfony\Component\Console\Formatter\OutputFormatter的典型用法代碼示例。如果您正苦於以下問題:PHP OutputFormatter類的具體用法?PHP OutputFormatter怎麽用?PHP OutputFormatter使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了OutputFormatter類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: run

 /**
  * Override run method to internationalize error message.
  *
  * @param \Symfony\Component\Console\Input\InputInterface $input
  * @param \Symfony\Component\Console\Output\OutputInterface $output
  * @return int Return code
  */
 public function run(InputInterface $input, OutputInterface $output)
 {
     // Set extra colors
     // The most problem is $output->getFormatter() don't work.
     // So create new formatter to add extra color.
     $formatter = new OutputFormatter($output->isDecorated());
     $formatter->setStyle('red', new OutputFormatterStyle('red', 'black'));
     $formatter->setStyle('green', new OutputFormatterStyle('green', 'black'));
     $formatter->setStyle('yellow', new OutputFormatterStyle('yellow', 'black'));
     $formatter->setStyle('blue', new OutputFormatterStyle('blue', 'black'));
     $formatter->setStyle('magenta', new OutputFormatterStyle('magenta', 'black'));
     $formatter->setStyle('yellow-blue', new OutputFormatterStyle('yellow', 'blue'));
     $output->setFormatter($formatter);
     \App::setLocale(\Config::get('syncle::MessageLang'));
     try {
         $result = parent::run($input, $output);
     } catch (\RuntimeException $e) {
         // All error messages were hard coded in
         // Symfony/Component/Console/Input/Input.php
         if ($e->getMessage() == 'Not enough arguments.') {
             $this->error(\Lang::get('syncle::BaseCommand.ArgumentNotEnough'));
         } elseif ($e->getMessage() == 'Too many arguments.') {
             $this->error(\Lang::get('syncle::BaseCommand.TooManyArgument'));
         } elseif (preg_match('/The "(.+)" option does not exist./', $e->getMessage(), $matches)) {
             $this->error(\Lang::get('syncle::BaseCommand.OptionNotExist', array('option' => $matches[1])));
         } else {
             $this->error($e->getMessage());
         }
         $result = 1;
     }
     return $result;
 }
開發者ID:hirokws,項目名稱:syncle,代碼行數:39,代碼來源:BaseCommand.php

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

示例3: writePrompt

 /**
  * {@inheritdoc}
  */
 protected function writePrompt(OutputInterface $output, Question $question)
 {
     $text = OutputFormatter::escape($question->getQuestion());
     $default = $question->getDefault();
     switch (true) {
         case null === $default:
             $text = sprintf(' <info>%s</info>:', $text);
             break;
         case $question instanceof ConfirmationQuestion:
             $text = sprintf(' <info>%s (yes/no)</info> [<comment>%s</comment>]:', $text, $default ? 'yes' : 'no');
             break;
         case $question instanceof ChoiceQuestion && $question->isMultiselect():
             $choices = $question->getChoices();
             $default = explode(',', $default);
             foreach ($default as $key => $value) {
                 $default[$key] = $choices[trim($value)];
             }
             $text = sprintf(' <info>%s</info> [<comment>%s</comment>]:', $text, OutputFormatter::escape(implode(', ', $default)));
             break;
         case $question instanceof ChoiceQuestion:
             $choices = $question->getChoices();
             $text = sprintf(' <info>%s</info> [<comment>%s</comment>]:', $text, OutputFormatter::escape($choices[$default]));
             break;
         default:
             $text = sprintf(' <info>%s</info> [<comment>%s</comment>]:', $text, OutputFormatter::escape($default));
     }
     $output->writeln($text);
     if ($question instanceof ChoiceQuestion) {
         $width = max(array_map('strlen', array_keys($question->getChoices())));
         foreach ($question->getChoices() as $key => $value) {
             $output->writeln(sprintf("  [<comment>%-{$width}s</comment>] %s", $key, $value));
         }
     }
     $output->write(' > ');
 }
開發者ID:heximcz,項目名稱:bind-manager,代碼行數:38,代碼來源:SymfonyQuestionHelper.php

示例4: generate

 /**
  * {@inheritdoc}
  */
 public function generate(ReportSummary $reportSummary)
 {
     $dom = new \DOMDocument('1.0', 'UTF-8');
     // new nodes should be added to this or existing children
     $root = $dom->createElement('report');
     $dom->appendChild($root);
     $filesXML = $dom->createElement('files');
     $root->appendChild($filesXML);
     $i = 1;
     foreach ($reportSummary->getChanged() as $file => $fixResult) {
         $fileXML = $dom->createElement('file');
         $fileXML->setAttribute('id', $i++);
         $fileXML->setAttribute('name', $file);
         $filesXML->appendChild($fileXML);
         if ($reportSummary->shouldAddAppliedFixers()) {
             $fileXML->appendChild($this->createAppliedFixersElement($dom, $fixResult));
         }
         if (!empty($fixResult['diff'])) {
             $fileXML->appendChild($this->createDiffElement($dom, $fixResult));
         }
     }
     if (null !== $reportSummary->getTime()) {
         $root->appendChild($this->createTimeElement($reportSummary->getTime(), $dom));
     }
     if (null !== $reportSummary->getTime()) {
         $root->appendChild($this->createMemoryElement($reportSummary->getMemory(), $dom));
     }
     $dom->formatOutput = true;
     return $reportSummary->isDecoratedOutput() ? OutputFormatter::escape($dom->saveXML()) : $dom->saveXML();
 }
開發者ID:GrahamForks,項目名稱:PHP-CS-Fixer,代碼行數:33,代碼來源:XmlReporter.php

示例5: complete

 /**
  * Print escaped values of all parameters
  * Strings like 'Namespace\\' has to be escaped
  *
  * @link https://github.com/symfony/symfony/issues/17908
  *
  * @return void
  */
 public function complete()
 {
     $this->io->write('<info>Summary :</info>');
     foreach ($this->getConfigKey('Placeholders') as $placeholder) {
         $this->io->write(sprintf(_('%1$s: <info>%2$s</info>'), Formatter\OutputFormatter::escape($placeholder['name']), Formatter\OutputFormatter::escape($placeholder['value'])));
     }
 }
開發者ID:inpsyde,項目名稱:boilerplate,代碼行數:15,代碼來源:VerifyProjectParameters.php

示例6: __construct

 /**
  * @param boolean $decorated
  *
  * @param array $styles
  */
 public function __construct($decorated = false, array $styles = array())
 {
     parent::__construct($decorated, $styles);
     $this->setStyle('pending', new OutputFormatterStyle('yellow'));
     $this->setStyle('pending-bg', new OutputFormatterStyle('black', 'yellow', array('bold')));
     $this->setStyle('skipped', new OutputFormatterStyle('cyan'));
     $this->setStyle('skipped-bg', new OutputFormatterStyle('white', 'cyan', array('bold')));
     $this->setStyle('failed', new OutputFormatterStyle('red'));
     $this->setStyle('failed-bg', new OutputFormatterStyle('white', 'red', array('bold')));
     $this->setStyle('broken', new OutputFormatterStyle('magenta'));
     $this->setStyle('broken-bg', new OutputFormatterStyle('white', 'magenta', array('bold')));
     $this->setStyle('passed', new OutputFormatterStyle('green'));
     $this->setStyle('passed-bg', new OutputFormatterStyle('black', 'green', array('bold')));
     $this->setStyle('value', new OutputFormatterStyle('yellow'));
     $this->setStyle('lineno', new OutputFormatterStyle(null, 'black'));
     $this->setStyle('code', new OutputFormatterStyle('white'));
     $this->setStyle('hl', new OutputFormatterStyle('black', 'yellow', array('bold')));
     $this->setStyle('question', new OutputFormatterStyle('black', 'yellow', array('bold')));
     $this->setStyle('trace', new OutputFormatterStyle());
     $this->setStyle('trace-class', new OutputFormatterStyle('cyan'));
     $this->setStyle('trace-func', new OutputFormatterStyle('cyan'));
     $this->setStyle('trace-type', new OutputFormatterStyle());
     $this->setStyle('trace-args', new OutputFormatterStyle());
     $this->setStyle('diff-add', new OutputFormatterStyle('green'));
     $this->setStyle('diff-del', new OutputFormatterStyle('red'));
 }
開發者ID:duxor,項目名稱:GUSLE,代碼行數:31,代碼來源:Formatter.php

示例7: block

 /**
  * Formats a message as a block of text.
  *
  * @param string|array $messages The message to write in the block
  * @param string|null $type The block type (added in [] on first line)
  * @param string|null $style The style to apply to the whole block
  * @param string $prefix The prefix for the block
  * @param bool $padding Whether to add vertical padding
  */
 public function block($messages, $type = null, $style = null, $prefix = ' ', $padding = false)
 {
     $this->autoPrependBlock();
     $messages = is_array($messages) ? array_values($messages) : array($messages);
     $lines = array();
     // add type
     if (null !== $type) {
         $messages[0] = sprintf('[%s] %s', $type, $messages[0]);
     }
     // wrap and add newlines for each element
     foreach ($messages as $key => $message) {
         $message = OutputFormatter::escape($message);
         $lines = array_merge($lines, explode(PHP_EOL, wordwrap($message, $this->lineLength - Helper::strlen($prefix), PHP_EOL, true)));
         if (count($messages) > 1 && $key < count($messages) - 1) {
             $lines[] = '';
         }
     }
     if ($padding && $this->isDecorated()) {
         array_unshift($lines, '');
         $lines[] = '';
     }
     foreach ($lines as &$line) {
         $line = sprintf('%s%s', $prefix, $line);
         $line .= str_repeat(' ', $this->lineLength - Helper::strlenWithoutDecoration($this->getFormatter(), $line));
         if ($style) {
             $line = sprintf('<%s>%s</>', $style, $line);
         }
     }
     $this->writeln($lines);
     $this->newLine();
 }
開發者ID:a53ali,項目名稱:CakePhP,代碼行數:40,代碼來源:SymfonyStyle.php

示例8: getBacktrace

 /**
  * Get a backtrace for an exception.
  *
  * Optionally limit the number of rows to include with $count, and exclude
  * Psy from the trace.
  *
  * @param \Exception $e          The exception with a backtrace.
  * @param int        $count      (default: PHP_INT_MAX)
  * @param bool       $includePsy (default: true)
  *
  * @return array Formatted stacktrace lines.
  */
 protected function getBacktrace(\Exception $e, $count = null, $includePsy = true)
 {
     if ($cwd = getcwd()) {
         $cwd = rtrim($cwd, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
     }
     if ($count === null) {
         $count = PHP_INT_MAX;
     }
     $lines = array();
     $trace = $e->getTrace();
     array_unshift($trace, array('function' => '', 'file' => $e->getFile() !== null ? $e->getFile() : 'n/a', 'line' => $e->getLine() !== null ? $e->getLine() : 'n/a', 'args' => array()));
     if (!$includePsy) {
         for ($i = count($trace) - 1; $i >= 0; $i--) {
             $thing = isset($trace[$i]['class']) ? $trace[$i]['class'] : $trace[$i]['function'];
             if (preg_match('/\\\\?Psy\\\\/', $thing)) {
                 $trace = array_slice($trace, $i + 1);
                 break;
             }
         }
     }
     for ($i = 0, $count = min($count, count($trace)); $i < $count; $i++) {
         $class = isset($trace[$i]['class']) ? $trace[$i]['class'] : '';
         $type = isset($trace[$i]['type']) ? $trace[$i]['type'] : '';
         $function = $trace[$i]['function'];
         $file = isset($trace[$i]['file']) ? $this->replaceCwd($cwd, $trace[$i]['file']) : 'n/a';
         $line = isset($trace[$i]['line']) ? $trace[$i]['line'] : 'n/a';
         $lines[] = sprintf(' <class>%s</class>%s%s() at <info>%s:%s</info>', OutputFormatter::escape($class), OutputFormatter::escape($type), OutputFormatter::escape($function), OutputFormatter::escape($file), OutputFormatter::escape($line));
     }
     return $lines;
 }
開發者ID:EnmanuelCode,項目名稱:backend-laravel,代碼行數:42,代碼來源:TraceCommand.php

示例9: testContentWithLineBreaks

    public function testContentWithLineBreaks()
    {
        $formatter = new OutputFormatter(true);
        $this->assertEquals(<<<EOF
[32m
some text[0m
EOF
, $formatter->format(<<<EOF
<info>
some text</info>
EOF
));
        $this->assertEquals(<<<EOF
[32msome text
[0m
EOF
, $formatter->format(<<<EOF
<info>some text
</info>
EOF
));
        $this->assertEquals(<<<EOF
[32m
some text
[0m
EOF
, $formatter->format(<<<EOF
<info>
some text
</info>
EOF
));
        $this->assertEquals(<<<EOF
[32m
some text
more text
[0m
EOF
, $formatter->format(<<<EOF
<info>
some text
more text
</info>
EOF
));
    }
開發者ID:robertowest,項目名稱:CuteFlow-V4,代碼行數:46,代碼來源:OutputFormatterTest.php

示例10: __construct

 /**
  * OutputFormatter constructor.
  *
  * @param bool  $decorated
  * @param array $styles
  */
 public function __construct($decorated = false, array $styles = array())
 {
     parent::__construct($decorated, $styles);
     $this->setStyle('passed', new OutputFormatterStyle('green', null, array()));
     $this->setStyle('passed-bg', new OutputFormatterStyle('black', 'green', array('bold')));
     $this->setStyle('broken', new OutputFormatterStyle('red', null, array()));
     $this->setStyle('broken-bg', new OutputFormatterStyle('white', 'red', array('bold')));
     $this->setStyle('blink', new OutputFormatterStyle(null, null, array('blink')));
 }
開發者ID:akeneo,項目名稱:php-coupling-detector,代碼行數:15,代碼來源:OutputFormatter.php

示例11: __construct

 public function __construct($decorated = false, array $styles = array())
 {
     parent::__construct(true, $styles);
     $this->setStyle('logo', new OutputFormatterStyle('magenta'));
     $this->setStyle('error', new OutputFormatterStyle('white', 'red'));
     $this->setStyle('comment', new OutputFormatterStyle('magenta', null, array('underscore')));
     $this->setStyle('info', new OutputFormatterStyle('cyan'));
     $this->setStyle('question', new OutputFormatterStyle('black', 'cyan'));
 }
開發者ID:glynnforrest,項目名稱:neptune,代碼行數:9,代碼來源:OutputFormatter.php

示例12: isset

 function __construct($config)
 {
     $this->config = array_merge($this->config, $config);
     // enable interactive output mode for CLI
     $this->isInteractive = $this->config['interactive'] && isset($_SERVER['TERM']) && php_sapi_name() == 'cli' && $_SERVER['TERM'] != 'linux';
     $formatter = new OutputFormatter($this->config['colors']);
     $formatter->setStyle('bold', new OutputFormatterStyle(null, null, ['bold']));
     $formatter->setStyle('focus', new OutputFormatterStyle('magenta', null, ['bold']));
     $formatter->setStyle('ok', new OutputFormatterStyle('white', 'magenta'));
     $formatter->setStyle('error', new OutputFormatterStyle('white', 'red'));
     $formatter->setStyle('debug', new OutputFormatterStyle('cyan'));
     $formatter->setStyle('comment', new OutputFormatterStyle('yellow'));
     $formatter->setStyle('info', new OutputFormatterStyle('green'));
     $this->formatHelper = new FormatterHelper();
     parent::__construct($this->config['verbosity'], $this->config['colors'], $formatter);
 }
開發者ID:hitechdk,項目名稱:Codeception,代碼行數:16,代碼來源:Output.php

示例13: getOutputFormatter

 /**
  * Initialize and get console output formatter
  *
  * @return OutputFormatter
  */
 protected function getOutputFormatter()
 {
     if (null === $this->outputFormatter) {
         $formatter = new OutputFormatter(true);
         $formatter->setStyle(LogLevel::EMERGENCY, new OutputFormatterStyle('white', 'red'));
         $formatter->setStyle(LogLevel::ALERT, new OutputFormatterStyle('white', 'red'));
         $formatter->setStyle(LogLevel::CRITICAL, new OutputFormatterStyle('red'));
         $formatter->setStyle(LogLevel::ERROR, new OutputFormatterStyle('red'));
         $formatter->setStyle(LogLevel::WARNING, new OutputFormatterStyle('yellow'));
         $formatter->setStyle(LogLevel::NOTICE, new OutputFormatterStyle());
         $formatter->setStyle(LogLevel::INFO, new OutputFormatterStyle());
         $formatter->setStyle(LogLevel::DEBUG, new OutputFormatterStyle('cyan'));
         $this->outputFormatter = $formatter;
     }
     return $this->outputFormatter;
 }
開發者ID:solverat,項目名稱:pimcore,代碼行數:21,代碼來源:ConsoleColorFormatter.php

示例14: OutputFormatter

 function __construct($config)
 {
     $this->config = array_merge($this->config, $config);
     $formatter = new OutputFormatter($this->config['colors']);
     $formatter->setStyle('bold', new OutputFormatterStyle(null, null, array('bold')));
     $formatter->setStyle('focus', new OutputFormatterStyle('magenta', null, array('bold')));
     $formatter->setStyle('ok', new OutputFormatterStyle('white', 'magenta'));
     $formatter->setStyle('error', new OutputFormatterStyle('white', 'red'));
     $formatter->setStyle('debug', new OutputFormatterStyle('cyan'));
     $formatter->setStyle('info', new OutputFormatterStyle('yellow'));
     $this->formatHelper = new FormatterHelper();
     parent::__construct($this->config['verbosity'], $this->config['colors'], $formatter);
 }
開發者ID:Eli-TW,項目名稱:Codeception,代碼行數:13,代碼來源:Output.php

示例15: presentRef

 /**
  * Present a reference to the value.
  *
  * @param mixed $value
  *
  * @return string
  */
 public function presentRef($value, $color = false)
 {
     $type = get_resource_type($value);
     if ($type === 'stream') {
         $meta = stream_get_meta_data($value);
         $type = sprintf('%s stream', $meta['stream_type']);
     }
     $id = str_replace('Resource id #', '', (string) $value);
     $format = $color ? self::COLOR_FMT : self::FMT;
     return sprintf($format, OutputFormatter::escape('<'), $type, $id);
 }
開發者ID:fulore,項目名稱:psysh,代碼行數:18,代碼來源:ResourcePresenter.php


注:本文中的Symfony\Component\Console\Formatter\OutputFormatter類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。