本文整理汇总了PHP中Symfony\Component\Console\Formatter\OutputFormatter::format方法的典型用法代码示例。如果您正苦于以下问题:PHP OutputFormatter::format方法的具体用法?PHP OutputFormatter::format怎么用?PHP OutputFormatter::format使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Console\Formatter\OutputFormatter
的用法示例。
在下文中一共展示了OutputFormatter::format方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: removeFormat
/**
* {@inheritdoc}
*/
public function removeFormat($string)
{
$this->innerFormatter->setDecorated(false);
$formatted = $this->innerFormatter->format($string);
$this->innerFormatter->setDecorated(true);
return $formatted;
}
示例2: format
public function format($message)
{
$message = preg_replace('/<info>(.*),\\s*(.*)<\\/info>/i', '<info>$2 ($1)</info>', $message);
$formatted = parent::format($message);
$clearEscapeCodes = '(?:39|49|0|22|24|25|27|28)';
return preg_replace_callback("{\\[([0-9;]+)m(.*?)\\[(?:" . $clearEscapeCodes . ";)*?" . $clearEscapeCodes . "m}s", array($this, 'formatHtml'), $formatted);
}
示例3: testNotDecoratedFormatter
public function testNotDecoratedFormatter()
{
$formatter = new OutputFormatter(false);
$this->assertTrue($formatter->hasStyle('error'));
$this->assertTrue($formatter->hasStyle('info'));
$this->assertTrue($formatter->hasStyle('comment'));
$this->assertTrue($formatter->hasStyle('question'));
$this->assertEquals("some error", $formatter->format('<error>some error</error>'));
$this->assertEquals("some info", $formatter->format('<info>some info</info>'));
$this->assertEquals("some comment", $formatter->format('<comment>some comment</comment>'));
$this->assertEquals("some question", $formatter->format('<question>some question</question>'));
$formatter->setDecorated(true);
$this->assertEquals("[37;41msome error[0m", $formatter->format('<error>some error</error>'));
$this->assertEquals("[32msome info[0m", $formatter->format('<info>some info</info>'));
$this->assertEquals("[33msome comment[0m", $formatter->format('<comment>some comment</comment>'));
$this->assertEquals("[30;46msome question[0m", $formatter->format('<question>some question</question>'));
}
示例4: 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
));
}
示例5: renderCodeCoverage
private function renderCodeCoverage(array $reportLines, $widestLine)
{
$output = '';
$widestLineNum = mb_strlen(count($reportLines));
foreach ($reportLines as $i => $line) {
$source = $this->formatter->escape(str_pad($line['line'], $widestLine));
$lineNum = str_pad((string) ($i + 1), $widestLineNum, ' ', STR_PAD_LEFT);
switch ($line['code']) {
case self::COVERAGE_COVERED:
$output .= $this->formatter->format(sprintf('<bg=white;fg=green>[%s] %s</>', $lineNum, $source));
break;
case self::COVERAGE_NOT_COVERED:
$output .= $this->formatter->format(sprintf('<bg=white;fg=red>[%s] %s</>', $lineNum, $source));
break;
case self::COVERAGE_META:
$output .= $this->formatter->format(sprintf('<bg=white;fg=black>[%s] %s</>', $lineNum, $source));
break;
}
$output .= PHP_EOL;
}
return $output;
}
示例6: getMessageFormat
/**
* @see Stream::getMessageFormat()
* @param mixed $level
* @param array $context
* @return string
*/
protected function getMessageFormat($level, array $context = array())
{
$parentFormat = parent::getMessageFormat($level, $context);
$consoleFormat = "<{$level}>{$parentFormat}</{$level}>";
return $this->formatter->format($consoleFormat);
}
示例7: format
public function format($message)
{
$formatted = parent::format($message);
return preg_replace_callback("{\\[([0-9;]+)m(.*?)\\[0m}s", array($this, 'formatHtml'), $formatted);
}
示例8: write
public function write($message)
{
$this->messages[] = $this->outputFormatter->format($message);
}
示例9: write
/**
* Writes a line.
* @param string $line
* @return void
*/
private function write($line = '')
{
echo $this->formatter->format($line);
}
示例10: format
public function format($message)
{
$formatted = parent::format($message);
$clearEscapeCodes = '(?:39|49|0|22|24|25|27|28)';
return preg_replace_callback("{\\[([0-9;]+)m(.*?)\\[(?:" . $clearEscapeCodes . ";)*?" . $clearEscapeCodes . "m}s", array($this, 'formatHtml'), $formatted);
}
示例11: loadFileOrEmpty
/**
* @param string $filename
*
* @return array
*/
private static function loadFileOrEmpty($filename)
{
if (!file_exists($filename)) {
return [];
}
try {
if (!is_array($content = Yaml::parse(file_get_contents($filename)))) {
$content = [];
}
return $content;
} catch (ParseException $exception) {
$errorFormatter = new OutputFormatter(true);
echo $errorFormatter->format(sprintf('<error>[WARNING] YAML File "%s" is invalid, falling back to "[]" as parsed-value.</error>' . PHP_EOL . '<error>Error: %s</error>' . PHP_EOL, $errorFormatter->escape($filename), $errorFormatter->escape($exception->getMessage()))) . PHP_EOL;
return [];
}
}
示例12: format
public function format($event)
{
$message = parent::format($event);
$colorizer = new OutputFormatter(true);
return $colorizer->format($message);
}
示例13: removeFormat
/**
* {@inheritdoc}
*/
public function removeFormat($string)
{
return $this->innerFormatter->format($string);
}
示例14: testNestedStyles
public function testNestedStyles()
{
$formatter = new OutputFormatter(true);
$this->assertSame("[32mTest [39m[37;41merror[39;49m[32m and [39m[33mcomment[39m[32m inside a info.[39m", $formatter->format('<info>Test <error>error</error> and <comment>comment</comment> inside a info.</info>'));
}