OutputStyle.php 3.0 KB

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