OutputStyle.php 3.2 KB

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