菜谱项目

OutputStyle.php 3.0KB

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