PluginProbe
Independent Analytics – WordPress Analytics Plugin / 1.28.0
Independent Analytics – WordPress Analytics Plugin v1.28.0
2.15.5 2.15.4 2.15.3 2.15.2 2.15.1 2.15.0 2.14.10 trunk 1.1 1.10 1.10.1 1.11 1.12 1.13 1.14 1.15 1.16 1.17 1.17.1 1.17.2 1.17.3 1.17.4 1.18 1.18.1 1.19.0 All 120 releases
independent-analytics / vendor / symfony / console / Helper / DebugFormatterHelper.php
DebugFormatterHelper.php
93 lines 3.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 namespace IAWP_SCOPED\Symfony\Component\Console\Helper;
12
13 /**
14 * Helps outputting debug information when running an external program from a command.
15 *
16 * An external program can be a Process, an HTTP request, or anything else.
17 *
18 * @author Fabien Potencier <fabien@symfony.com>
19 */
20 class DebugFormatterHelper extends Helper
21 {
22 private const COLORS = ['black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white', 'default'];
23 private $started = [];
24 private $count = -1;
25 /**
26 * Starts a debug formatting session.
27 *
28 * @return string
29 */
30 public function start(string $id, string $message, string $prefix = 'RUN')
31 {
32 $this->started[$id] = ['border' => ++$this->count % \count(self::COLORS)];
33 return \sprintf("%s<bg=blue;fg=white> %s </> <fg=blue>%s</>\n", $this->getBorder($id), $prefix, $message);
34 }
35 /**
36 * Adds progress to a formatting session.
37 *
38 * @return string
39 */
40 public function progress(string $id, string $buffer, bool $error = \false, string $prefix = 'OUT', string $errorPrefix = 'ERR')
41 {
42 $message = '';
43 if ($error) {
44 if (isset($this->started[$id]['out'])) {
45 $message .= "\n";
46 unset($this->started[$id]['out']);
47 }
48 if (!isset($this->started[$id]['err'])) {
49 $message .= \sprintf('%s<bg=red;fg=white> %s </> ', $this->getBorder($id), $errorPrefix);
50 $this->started[$id]['err'] = \true;
51 }
52 $message .= \str_replace("\n", \sprintf("\n%s<bg=red;fg=white> %s </> ", $this->getBorder($id), $errorPrefix), $buffer);
53 } else {
54 if (isset($this->started[$id]['err'])) {
55 $message .= "\n";
56 unset($this->started[$id]['err']);
57 }
58 if (!isset($this->started[$id]['out'])) {
59 $message .= \sprintf('%s<bg=green;fg=white> %s </> ', $this->getBorder($id), $prefix);
60 $this->started[$id]['out'] = \true;
61 }
62 $message .= \str_replace("\n", \sprintf("\n%s<bg=green;fg=white> %s </> ", $this->getBorder($id), $prefix), $buffer);
63 }
64 return $message;
65 }
66 /**
67 * Stops a formatting session.
68 *
69 * @return string
70 */
71 public function stop(string $id, string $message, bool $successful, string $prefix = 'RES')
72 {
73 $trailingEOL = isset($this->started[$id]['out']) || isset($this->started[$id]['err']) ? "\n" : '';
74 if ($successful) {
75 return \sprintf("%s%s<bg=green;fg=white> %s </> <fg=green>%s</>\n", $trailingEOL, $this->getBorder($id), $prefix, $message);
76 }
77 $message = \sprintf("%s%s<bg=red;fg=white> %s </> <fg=red>%s</>\n", $trailingEOL, $this->getBorder($id), $prefix, $message);
78 unset($this->started[$id]['out'], $this->started[$id]['err']);
79 return $message;
80 }
81 private function getBorder(string $id) : string
82 {
83 return \sprintf('<bg=%s> </>', self::COLORS[$this->started[$id]['border']]);
84 }
85 /**
86 * {@inheritdoc}
87 */
88 public function getName()
89 {
90 return 'debug_formatter';
91 }
92 }
93