Security update for permissions_by_term
[yaffs-website] / vendor / behat / behat / src / Behat / Behat / Output / Printer / Formatter / ConsoleFormatter.php
1 <?php
2
3 /*
4  * This file is part of the Behat.
5  * (c) Konstantin Kudryashov <ever.zet@gmail.com>
6  *
7  * For the full copyright and license information, please view the LICENSE
8  * file that was distributed with this source code.
9  */
10
11 namespace Behat\Behat\Output\Printer\Formatter;
12
13 use Symfony\Component\Console\Formatter\OutputFormatter as BaseOutputFormatter;
14
15 /**
16  * Symfony2 Console output formatter extended with custom highlighting tokens support.
17  *
18  * @author Konstantin Kudryashov <ever.zet@gmail.com>
19  */
20 final class ConsoleFormatter extends BaseOutputFormatter
21 {
22     const CUSTOM_PATTERN = '/{\+([a-z-_]+)}(.*?){\-\\1}/si';
23
24     /**
25      * Formats a message according to the given styles.
26      *
27      * @param string $message The message to style
28      *
29      * @return string The styled message
30      */
31     public function format($message)
32     {
33         return preg_replace_callback(self::CUSTOM_PATTERN, array($this, 'replaceStyle'), $message);
34     }
35
36     /**
37      * Replaces style of the output.
38      *
39      * @param array $match
40      *
41      * @return string The replaced style
42      */
43     private function replaceStyle($match)
44     {
45         if (!$this->isDecorated()) {
46             return $match[2];
47         }
48
49         if ($this->hasStyle($match[1])) {
50             $style = $this->getStyle($match[1]);
51         } else {
52             return $match[0];
53         }
54
55         return $style->apply($match[2]);
56     }
57 }