X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Fbehat%2Fbehat%2Fsrc%2FBehat%2FBehat%2FOutput%2FPrinter%2FFormatter%2FConsoleFormatter.php;fp=vendor%2Fbehat%2Fbehat%2Fsrc%2FBehat%2FBehat%2FOutput%2FPrinter%2FFormatter%2FConsoleFormatter.php;h=9b403a68e8acf11e747c9d83c54b403f57e74609;hp=0000000000000000000000000000000000000000;hb=1270d9129ce8f27c9b28b10518e32132c58e0aca;hpb=c27c0f0cdaa3f354b1fe54a56ae7e854be6e3f68 diff --git a/vendor/behat/behat/src/Behat/Behat/Output/Printer/Formatter/ConsoleFormatter.php b/vendor/behat/behat/src/Behat/Behat/Output/Printer/Formatter/ConsoleFormatter.php new file mode 100644 index 000000000..9b403a68e --- /dev/null +++ b/vendor/behat/behat/src/Behat/Behat/Output/Printer/Formatter/ConsoleFormatter.php @@ -0,0 +1,57 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Behat\Behat\Output\Printer\Formatter; + +use Symfony\Component\Console\Formatter\OutputFormatter as BaseOutputFormatter; + +/** + * Symfony2 Console output formatter extended with custom highlighting tokens support. + * + * @author Konstantin Kudryashov + */ +final class ConsoleFormatter extends BaseOutputFormatter +{ + const CUSTOM_PATTERN = '/{\+([a-z-_]+)}(.*?){\-\\1}/si'; + + /** + * Formats a message according to the given styles. + * + * @param string $message The message to style + * + * @return string The styled message + */ + public function format($message) + { + return preg_replace_callback(self::CUSTOM_PATTERN, array($this, 'replaceStyle'), $message); + } + + /** + * Replaces style of the output. + * + * @param array $match + * + * @return string The replaced style + */ + private function replaceStyle($match) + { + if (!$this->isDecorated()) { + return $match[2]; + } + + if ($this->hasStyle($match[1])) { + $style = $this->getStyle($match[1]); + } else { + return $match[0]; + } + + return $style->apply($match[2]); + } +}