OutputStyle.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Console\Style;
  11. use Symfony\Component\Console\Formatter\OutputFormatterInterface;
  12. use Symfony\Component\Console\Helper\ProgressBar;
  13. use Symfony\Component\Console\Output\ConsoleOutputInterface;
  14. use Symfony\Component\Console\Output\OutputInterface;
  15. /**
  16. * Decorates output to add console style guide helpers.
  17. *
  18. * @author Kevin Bond <kevinbond@gmail.com>
  19. */
  20. abstract class OutputStyle implements OutputInterface, StyleInterface
  21. {
  22. public function __construct(
  23. private OutputInterface $output,
  24. ) {
  25. }
  26. public function newLine(int $count = 1): void
  27. {
  28. $this->output->write(str_repeat(\PHP_EOL, $count));
  29. }
  30. public function createProgressBar(int $max = 0): ProgressBar
  31. {
  32. return new ProgressBar($this->output, $max);
  33. }
  34. public function write(string|iterable $messages, bool $newline = false, int $type = self::OUTPUT_NORMAL): void
  35. {
  36. $this->output->write($messages, $newline, $type);
  37. }
  38. public function writeln(string|iterable $messages, int $type = self::OUTPUT_NORMAL): void
  39. {
  40. $this->output->writeln($messages, $type);
  41. }
  42. public function setVerbosity(int $level): void
  43. {
  44. $this->output->setVerbosity($level);
  45. }
  46. public function getVerbosity(): int
  47. {
  48. return $this->output->getVerbosity();
  49. }
  50. public function setDecorated(bool $decorated): void
  51. {
  52. $this->output->setDecorated($decorated);
  53. }
  54. public function isDecorated(): bool
  55. {
  56. return $this->output->isDecorated();
  57. }
  58. public function setFormatter(OutputFormatterInterface $formatter): void
  59. {
  60. $this->output->setFormatter($formatter);
  61. }
  62. public function getFormatter(): OutputFormatterInterface
  63. {
  64. return $this->output->getFormatter();
  65. }
  66. public function isQuiet(): bool
  67. {
  68. return $this->output->isQuiet();
  69. }
  70. public function isVerbose(): bool
  71. {
  72. return $this->output->isVerbose();
  73. }
  74. public function isVeryVerbose(): bool
  75. {
  76. return $this->output->isVeryVerbose();
  77. }
  78. public function isDebug(): bool
  79. {
  80. return $this->output->isDebug();
  81. }
  82. protected function getErrorOutput(): OutputInterface
  83. {
  84. if (!$this->output instanceof ConsoleOutputInterface) {
  85. return $this->output;
  86. }
  87. return $this->output->getErrorOutput();
  88. }
  89. }