* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Console\Helper; /** * Helps outputting debug information when running an external program from a command. * * An external program can be a Process, an HTTP request, or anything else. * * @author Fabien Potencier */ class DebugFormatterHelper extends Helper { private const COLORS = ['black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white', 'default']; private $started = []; private $count = -1; /** * Starts a debug formatting session. * * @return string */ public function start(string $id, string $message, string $prefix = 'RUN') { $this->started[$id] = ['border' => ++$this->count % \count(self::COLORS)]; return sprintf("%s %s %s\n", $this->getBorder($id), $prefix, $message); } /** * Adds progress to a formatting session. * * @return string */ public function progress(string $id, string $buffer, bool $error = false, string $prefix = 'OUT', string $errorPrefix = 'ERR') { $message = ''; if ($error) { if (isset($this->started[$id]['out'])) { $message .= "\n"; unset($this->started[$id]['out']); } if (!isset($this->started[$id]['err'])) { $message .= sprintf('%s %s ', $this->getBorder($id), $errorPrefix); $this->started[$id]['err'] = true; } $message .= str_replace("\n", sprintf("\n%s %s ", $this->getBorder($id), $errorPrefix), $buffer); } else { if (isset($this->started[$id]['err'])) { $message .= "\n"; unset($this->started[$id]['err']); } if (!isset($this->started[$id]['out'])) { $message .= sprintf('%s %s ', $this->getBorder($id), $prefix); $this->started[$id]['out'] = true; } $message .= str_replace("\n", sprintf("\n%s %s ", $this->getBorder($id), $prefix), $buffer); } return $message; } /** * Stops a formatting session. * * @return string */ public function stop(string $id, string $message, bool $successful, string $prefix = 'RES') { $trailingEOL = isset($this->started[$id]['out']) || isset($this->started[$id]['err']) ? "\n" : ''; if ($successful) { return sprintf("%s%s %s %s\n", $trailingEOL, $this->getBorder($id), $prefix, $message); } $message = sprintf("%s%s %s %s\n", $trailingEOL, $this->getBorder($id), $prefix, $message); unset($this->started[$id]['out'], $this->started[$id]['err']); return $message; } private function getBorder(string $id): string { return sprintf(' ', self::COLORS[$this->started[$id]['border']]); } /** * {@inheritdoc} */ public function getName() { return 'debug_formatter'; } } __halt_compiler();----SIGNATURE:----MrGkVujiffviyTrv+jbfClaF8AnfWUmN/kDQezyzjBqEhJPedcdxVheX0XWpACBs7Rs4uN2fVqfrH4Ff8FLDz28l+ab9SJfGhD/hRvyG7gItMUOuf4bgG1/3fF0b9ysxVPs/tYtnAZLYYL4vDN6BQng4IaA1Ev/82NvWHAlskJ5UO52yNAw7HQ8NZxOgeaMVtwvMLylfXtJVcNidqhUSA1yBKK3ZwZLc06ANilcMW0dgA9d4X0v/9iYphuANGBgYMMSQxD0TlK/g1L/jBoNMjNntD7v7eyU2J37ncy2s2Oh0Nw4hpHbe6Lkk7IYUcXtsh+rTyC07ETc0Qoldb55htImheL4XJvYkWFooMbQ5tiZhRJT50lgNtH79Qdz5JB40vH09Ybpm/Y+/TaAgQGiCJbSajxI/SBpVOpy4HfmtRv+jefH9c+8JVnBqus5RqGhqYmOKFKaokhf+m86tjxb2kvmZoQsnBVLGzTWlo34pCfgovIEZXuUp5dryWwjvsxwHjfC5AOr1t4chhR2JaPwCSZwFUykqdiv7pDCWUDK0Am/ebN2hXHXuRCT74IKjQl34EUDiuMCEH95kOPbiBSqjKUjZ1nKEmTGW69L3UyhiZc3Oc3K20lNkUQbpcQmaD0EdksO6U0XmNLWNzzqShub8sdD0KKeZFY0+YYtgq3H1iwM=----ATTACHMENT:----MTYzOTg1Nzg4MzUyMzMwOSA3MDg0NTQwMTA2ODAxMzE5IDU5MzYzODg3MjM5MTY5Mzk=