TYPO3  7.6
DebugFormatterHelper.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11 
12 namespace Symfony\Component\Console\Helper;
13 
22 {
23  private $colors = array('black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white', 'default');
24  private $started = array();
25  private $count = -1;
26 
36  public function start($id, $message, $prefix = 'RUN')
37  {
38  $this->started[$id] = array('border' => ++$this->count % count($this->colors));
39 
40  return sprintf("%s<bg=blue;fg=white> %s </> <fg=blue>%s</>\n", $this->getBorder($id), $prefix, $message);
41  }
42 
54  public function progress($id, $buffer, $error = false, $prefix = 'OUT', $errorPrefix = 'ERR')
55  {
56  $message = '';
57 
58  if ($error) {
59  if (isset($this->started[$id]['out'])) {
60  $message .= "\n";
61  unset($this->started[$id]['out']);
62  }
63  if (!isset($this->started[$id]['err'])) {
64  $message .= sprintf('%s<bg=red;fg=white> %s </> ', $this->getBorder($id), $errorPrefix);
65  $this->started[$id]['err'] = true;
66  }
67 
68  $message .= str_replace("\n", sprintf("\n%s<bg=red;fg=white> %s </> ", $this->getBorder($id), $errorPrefix), $buffer);
69  } else {
70  if (isset($this->started[$id]['err'])) {
71  $message .= "\n";
72  unset($this->started[$id]['err']);
73  }
74  if (!isset($this->started[$id]['out'])) {
75  $message .= sprintf('%s<bg=green;fg=white> %s </> ', $this->getBorder($id), $prefix);
76  $this->started[$id]['out'] = true;
77  }
78 
79  $message .= str_replace("\n", sprintf("\n%s<bg=green;fg=white> %s </> ", $this->getBorder($id), $prefix), $buffer);
80  }
81 
82  return $message;
83  }
84 
95  public function stop($id, $message, $successful, $prefix = 'RES')
96  {
97  $trailingEOL = isset($this->started[$id]['out']) || isset($this->started[$id]['err']) ? "\n" : '';
98 
99  if ($successful) {
100  return sprintf("%s%s<bg=green;fg=white> %s </> <fg=green>%s</>\n", $trailingEOL, $this->getBorder($id), $prefix, $message);
101  }
102 
103  $message = sprintf("%s%s<bg=red;fg=white> %s </> <fg=red>%s</>\n", $trailingEOL, $this->getBorder($id), $prefix, $message);
104 
105  unset($this->started[$id]['out'], $this->started[$id]['err']);
106 
107  return $message;
108  }
109 
115  private function getBorder($id)
116  {
117  return sprintf('<bg=%s> </>', $this->colors[$this->started[$id]['border']]);
118  }
119 
123  public function getName()
124  {
125  return 'debug_formatter';
126  }
127 }