diff options
| author | polo <ordipolo@gmx.fr> | 2024-08-13 23:45:21 +0200 |
|---|---|---|
| committer | polo <ordipolo@gmx.fr> | 2024-08-13 23:45:21 +0200 |
| commit | bf6655a534a6775d30cafa67bd801276bda1d98d (patch) | |
| tree | c6381e3f6c81c33eab72508f410b165ba05f7e9c /vendor/symfony/console/Helper/DebugFormatterHelper.php | |
| parent | 94d67a4b51f8e62e7d518cce26a526ae1ec48278 (diff) | |
| download | AppliGestionPHP-bf6655a534a6775d30cafa67bd801276bda1d98d.tar.gz AppliGestionPHP-bf6655a534a6775d30cafa67bd801276bda1d98d.tar.bz2 AppliGestionPHP-bf6655a534a6775d30cafa67bd801276bda1d98d.zip | |
VERSION 0.2 doctrine ORM et entités
Diffstat (limited to 'vendor/symfony/console/Helper/DebugFormatterHelper.php')
| -rw-r--r-- | vendor/symfony/console/Helper/DebugFormatterHelper.php | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/vendor/symfony/console/Helper/DebugFormatterHelper.php b/vendor/symfony/console/Helper/DebugFormatterHelper.php new file mode 100644 index 0000000..9ea7fb9 --- /dev/null +++ b/vendor/symfony/console/Helper/DebugFormatterHelper.php | |||
| @@ -0,0 +1,98 @@ | |||
| 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 | |||
| 14 | /** | ||
| 15 | * Helps outputting debug information when running an external program from a command. | ||
| 16 | * | ||
| 17 | * An external program can be a Process, an HTTP request, or anything else. | ||
| 18 | * | ||
| 19 | * @author Fabien Potencier <fabien@symfony.com> | ||
| 20 | */ | ||
| 21 | class DebugFormatterHelper extends Helper | ||
| 22 | { | ||
| 23 | private const COLORS = ['black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white', 'default']; | ||
| 24 | private array $started = []; | ||
| 25 | private int $count = -1; | ||
| 26 | |||
| 27 | /** | ||
| 28 | * Starts a debug formatting session. | ||
| 29 | */ | ||
| 30 | public function start(string $id, string $message, string $prefix = 'RUN'): string | ||
| 31 | { | ||
| 32 | $this->started[$id] = ['border' => ++$this->count % \count(self::COLORS)]; | ||
| 33 | |||
| 34 | return sprintf("%s<bg=blue;fg=white> %s </> <fg=blue>%s</>\n", $this->getBorder($id), $prefix, $message); | ||
| 35 | } | ||
| 36 | |||
| 37 | /** | ||
| 38 | * Adds progress to a formatting session. | ||
| 39 | */ | ||
| 40 | public function progress(string $id, string $buffer, bool $error = false, string $prefix = 'OUT', string $errorPrefix = 'ERR'): string | ||
| 41 | { | ||
| 42 | $message = ''; | ||
| 43 | |||
| 44 | if ($error) { | ||
| 45 | if (isset($this->started[$id]['out'])) { | ||
| 46 | $message .= "\n"; | ||
| 47 | unset($this->started[$id]['out']); | ||
| 48 | } | ||
| 49 | if (!isset($this->started[$id]['err'])) { | ||
| 50 | $message .= sprintf('%s<bg=red;fg=white> %s </> ', $this->getBorder($id), $errorPrefix); | ||
| 51 | $this->started[$id]['err'] = true; | ||
| 52 | } | ||
| 53 | |||
| 54 | $message .= str_replace("\n", sprintf("\n%s<bg=red;fg=white> %s </> ", $this->getBorder($id), $errorPrefix), $buffer); | ||
| 55 | } else { | ||
| 56 | if (isset($this->started[$id]['err'])) { | ||
| 57 | $message .= "\n"; | ||
| 58 | unset($this->started[$id]['err']); | ||
| 59 | } | ||
| 60 | if (!isset($this->started[$id]['out'])) { | ||
| 61 | $message .= sprintf('%s<bg=green;fg=white> %s </> ', $this->getBorder($id), $prefix); | ||
| 62 | $this->started[$id]['out'] = true; | ||
| 63 | } | ||
| 64 | |||
| 65 | $message .= str_replace("\n", sprintf("\n%s<bg=green;fg=white> %s </> ", $this->getBorder($id), $prefix), $buffer); | ||
| 66 | } | ||
| 67 | |||
| 68 | return $message; | ||
| 69 | } | ||
| 70 | |||
| 71 | /** | ||
| 72 | * Stops a formatting session. | ||
| 73 | */ | ||
| 74 | public function stop(string $id, string $message, bool $successful, string $prefix = 'RES'): string | ||
| 75 | { | ||
| 76 | $trailingEOL = isset($this->started[$id]['out']) || isset($this->started[$id]['err']) ? "\n" : ''; | ||
| 77 | |||
| 78 | if ($successful) { | ||
| 79 | return sprintf("%s%s<bg=green;fg=white> %s </> <fg=green>%s</>\n", $trailingEOL, $this->getBorder($id), $prefix, $message); | ||
| 80 | } | ||
| 81 | |||
| 82 | $message = sprintf("%s%s<bg=red;fg=white> %s </> <fg=red>%s</>\n", $trailingEOL, $this->getBorder($id), $prefix, $message); | ||
| 83 | |||
| 84 | unset($this->started[$id]['out'], $this->started[$id]['err']); | ||
| 85 | |||
| 86 | return $message; | ||
| 87 | } | ||
| 88 | |||
| 89 | private function getBorder(string $id): string | ||
| 90 | { | ||
| 91 | return sprintf('<bg=%s> </>', self::COLORS[$this->started[$id]['border']]); | ||
| 92 | } | ||
| 93 | |||
| 94 | public function getName(): string | ||
| 95 | { | ||
| 96 | return 'debug_formatter'; | ||
| 97 | } | ||
| 98 | } | ||
