| 1 |
<?php |
| 2 |
|
| 3 |
/* |
| 4 |
* This file is part of the Symfony package. |
| 5 |
* |
| 6 |
* (c) Fabien Potencier <[email protected]> |
| 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\Style; |
| 13 |
|
| 14 |
use Symfony\Component\Console\Formatter\OutputFormatterInterface; |
| 15 |
use Symfony\Component\Console\Helper\ProgressBar; |
| 16 |
use Symfony\Component\Console\Output\ConsoleOutputInterface; |
| 17 |
use Symfony\Component\Console\Output\OutputInterface; |
| 18 |
|
| 19 |
/** |
| 20 |
* Decorates output to add console style guide helpers. |
| 21 |
* |
| 22 |
* @author Kevin Bond <[email protected]> |
| 23 |
*/ |
| 24 |
abstract class OutputStyle implements OutputInterface, StyleInterface |
| 25 |
{ |
| 26 |
public function __construct( |
| 27 |
private OutputInterface $output, |
| 28 |
) { |
| 29 |
} |
| 30 |
|
| 31 |
public function newLine(int $count = 1): void |
| 32 |
{ |
| 33 |
$this->output->write(str_repeat(\PHP_EOL, $count)); |
| 34 |
} |
| 35 |
|
| 36 |
public function createProgressBar(int $max = 0): ProgressBar |
| 37 |
{ |
| 38 |
return new ProgressBar($this->output, $max); |
| 39 |
} |
| 40 |
|
| 41 |
public function write(string|iterable $messages, bool $newline = false, int $type = self::OUTPUT_NORMAL): void |
| 42 |
{ |
| 43 |
$this->output->write($messages, $newline, $type); |
| 44 |
} |
| 45 |
|
| 46 |
public function writeln(string|iterable $messages, int $type = self::OUTPUT_NORMAL): void |
| 47 |
{ |
| 48 |
$this->output->writeln($messages, $type); |
| 49 |
} |
| 50 |
|
| 51 |
public function setVerbosity(int $level): void |
| 52 |
{ |
| 53 |
$this->output->setVerbosity($level); |
| 54 |
} |
| 55 |
|
| 56 |
public function getVerbosity(): int |
| 57 |
{ |
| 58 |
return $this->output->getVerbosity(); |
| 59 |
} |
| 60 |
|
| 61 |
public function setDecorated(bool $decorated): void |
| 62 |
{ |
| 63 |
$this->output->setDecorated($decorated); |
| 64 |
} |
| 65 |
|
| 66 |
public function isDecorated(): bool |
| 67 |
{ |
| 68 |
return $this->output->isDecorated(); |
| 69 |
} |
| 70 |
|
| 71 |
public function setFormatter(OutputFormatterInterface $formatter): void |
| 72 |
{ |
| 73 |
$this->output->setFormatter($formatter); |
| 74 |
} |
| 75 |
|
| 76 |
public function getFormatter(): OutputFormatterInterface |
| 77 |
{ |
| 78 |
return $this->output->getFormatter(); |
| 79 |
} |
| 80 |
|
| 81 |
public function isSilent(): bool |
| 82 |
{ |
| 83 |
// @deprecated since Symfony 7.2, change to $this->output->isSilent() in 8.0 |
| 84 |
return method_exists($this->output, 'isSilent') ? $this->output->isSilent() : self::VERBOSITY_SILENT === $this->output->getVerbosity(); |
| 85 |
} |
| 86 |
|
| 87 |
public function isQuiet(): bool |
| 88 |
{ |
| 89 |
return $this->output->isQuiet(); |
| 90 |
} |
| 91 |
|
| 92 |
public function isVerbose(): bool |
| 93 |
{ |
| 94 |
return $this->output->isVerbose(); |
| 95 |
} |
| 96 |
|
| 97 |
public function isVeryVerbose(): bool |
| 98 |
{ |
| 99 |
return $this->output->isVeryVerbose(); |
| 100 |
} |
| 101 |
|
| 102 |
public function isDebug(): bool |
| 103 |
{ |
| 104 |
return $this->output->isDebug(); |
| 105 |
} |
| 106 |
|
| 107 |
protected function getErrorOutput(): OutputInterface |
| 108 |
{ |
| 109 |
if (!$this->output instanceof ConsoleOutputInterface) { |
| 110 |
return $this->output; |
| 111 |
} |
| 112 |
|
| 113 |
return $this->output->getErrorOutput(); |
| 114 |
} |
| 115 |
} |