You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

153 lines
3.0 KiB

3 years ago
  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. private $output;
  23. public function __construct(OutputInterface $output)
  24. {
  25. $this->output = $output;
  26. }
  27. /**
  28. * {@inheritdoc}
  29. */
  30. public function newLine(int $count = 1)
  31. {
  32. $this->output->write(str_repeat(\PHP_EOL, $count));
  33. }
  34. /**
  35. * @return ProgressBar
  36. */
  37. public function createProgressBar(int $max = 0)
  38. {
  39. return new ProgressBar($this->output, $max);
  40. }
  41. /**
  42. * {@inheritdoc}
  43. */
  44. public function write($messages, bool $newline = false, int $type = self::OUTPUT_NORMAL)
  45. {
  46. $this->output->write($messages, $newline, $type);
  47. }
  48. /**
  49. * {@inheritdoc}
  50. */
  51. public function writeln($messages, int $type = self::OUTPUT_NORMAL)
  52. {
  53. $this->output->writeln($messages, $type);
  54. }
  55. /**
  56. * {@inheritdoc}
  57. */
  58. public function setVerbosity(int $level)
  59. {
  60. $this->output->setVerbosity($level);
  61. }
  62. /**
  63. * {@inheritdoc}
  64. */
  65. public function getVerbosity()
  66. {
  67. return $this->output->getVerbosity();
  68. }
  69. /**
  70. * {@inheritdoc}
  71. */
  72. public function setDecorated(bool $decorated)
  73. {
  74. $this->output->setDecorated($decorated);
  75. }
  76. /**
  77. * {@inheritdoc}
  78. */
  79. public function isDecorated()
  80. {
  81. return $this->output->isDecorated();
  82. }
  83. /**
  84. * {@inheritdoc}
  85. */
  86. public function setFormatter(OutputFormatterInterface $formatter)
  87. {
  88. $this->output->setFormatter($formatter);
  89. }
  90. /**
  91. * {@inheritdoc}
  92. */
  93. public function getFormatter()
  94. {
  95. return $this->output->getFormatter();
  96. }
  97. /**
  98. * {@inheritdoc}
  99. */
  100. public function isQuiet()
  101. {
  102. return $this->output->isQuiet();
  103. }
  104. /**
  105. * {@inheritdoc}
  106. */
  107. public function isVerbose()
  108. {
  109. return $this->output->isVerbose();
  110. }
  111. /**
  112. * {@inheritdoc}
  113. */
  114. public function isVeryVerbose()
  115. {
  116. return $this->output->isVeryVerbose();
  117. }
  118. /**
  119. * {@inheritdoc}
  120. */
  121. public function isDebug()
  122. {
  123. return $this->output->isDebug();
  124. }
  125. protected function getErrorOutput()
  126. {
  127. if (!$this->output instanceof ConsoleOutputInterface) {
  128. return $this->output;
  129. }
  130. return $this->output->getErrorOutput();
  131. }
  132. }