4 * This file is part of the Behat.
5 * (c) Konstantin Kudryashov <ever.zet@gmail.com>
7 * For the full copyright and license information, please view the LICENSE
8 * file that was distributed with this source code.
11 namespace Behat\Behat\Output\Printer\Formatter;
13 use Symfony\Component\Console\Formatter\OutputFormatter as BaseOutputFormatter;
16 * Symfony2 Console output formatter extended with custom highlighting tokens support.
18 * @author Konstantin Kudryashov <ever.zet@gmail.com>
20 final class ConsoleFormatter extends BaseOutputFormatter
22 const CUSTOM_PATTERN = '/{\+([a-z-_]+)}(.*?){\-\\1}/si';
25 * Formats a message according to the given styles.
27 * @param string $message The message to style
29 * @return string The styled message
31 public function format($message)
33 return preg_replace_callback(self::CUSTOM_PATTERN, array($this, 'replaceStyle'), $message);
37 * Replaces style of the output.
41 * @return string The replaced style
43 private function replaceStyle($match)
45 if (!$this->isDecorated()) {
49 if ($this->hasStyle($match[1])) {
50 $style = $this->getStyle($match[1]);
55 return $style->apply($match[2]);