| 1 |
<?php |
| 2 |
|
| 3 |
/* |
| 4 |
* This file is part of the Symfony package. |
| 5 |
* |
| 6 |
* (c) Fabien Potencier <fabien@symfony.com> |
| 7 |
* |
| 8 |
* For the full copyright and license information, please view the LICENSE |
| 9 |
* file that was distributed with this source code. |
| 10 |
*/ |
| 11 |
|
| 12 |
namespace Symfony\Component\Console\Style; |
| 13 |
|
| 14 |
use Symfony\Component\Console\Formatter\OutputFormatterInterface; |
| 15 |
use Symfony\Component\Console\Helper\ProgressBar; |
| 16 |
use Symfony\Component\Console\Output\ConsoleOutputInterface; |
| 17 |
use Symfony\Component\Console\Output\OutputInterface; |
| 18 |
|
| 19 |
/** |
| 20 |
* Decorates output to add console style guide helpers. |
| 21 |
* |
| 22 |
* @author Kevin Bond <kevinbond@gmail.com> |
| 23 |
*/ |
| 24 |
abstract class OutputStyle implements OutputInterface, StyleInterface |
| 25 |
{ |
| 26 |
private $output; |
| 27 |
|
| 28 |
public function __construct(OutputInterface $output) |
| 29 |
{ |
| 30 |
$this->output = $output; |
| 31 |
} |
| 32 |
|
| 33 |
/** |
| 34 |
* {@inheritdoc} |
| 35 |
*/ |
| 36 |
public function newLine(int $count = 1) |
| 37 |
{ |
| 38 |
$this->output->write(str_repeat(\PHP_EOL, $count)); |
| 39 |
} |
| 40 |
|
| 41 |
/** |
| 42 |
* @return ProgressBar |
| 43 |
*/ |
| 44 |
public function createProgressBar(int $max = 0) |
| 45 |
{ |
| 46 |
return new ProgressBar($this->output, $max); |
| 47 |
} |
| 48 |
|
| 49 |
/** |
| 50 |
* {@inheritdoc} |
| 51 |
*/ |
| 52 |
public function write($messages, bool $newline = false, int $type = self::OUTPUT_NORMAL) |
| 53 |
{ |
| 54 |
$this->output->write($messages, $newline, $type); |
| 55 |
} |
| 56 |
|
| 57 |
/** |
| 58 |
* {@inheritdoc} |
| 59 |
*/ |
| 60 |
public function writeln($messages, int $type = self::OUTPUT_NORMAL) |
| 61 |
{ |
| 62 |
$this->output->writeln($messages, $type); |
| 63 |
} |
| 64 |
|
| 65 |
/** |
| 66 |
* {@inheritdoc} |
| 67 |
*/ |
| 68 |
public function setVerbosity(int $level) |
| 69 |
{ |
| 70 |
$this->output->setVerbosity($level); |
| 71 |
} |
| 72 |
|
| 73 |
/** |
| 74 |
* {@inheritdoc} |
| 75 |
*/ |
| 76 |
public function getVerbosity() |
| 77 |
{ |
| 78 |
return $this->output->getVerbosity(); |
| 79 |
} |
| 80 |
|
| 81 |
/** |
| 82 |
* {@inheritdoc} |
| 83 |
*/ |
| 84 |
public function setDecorated(bool $decorated) |
| 85 |
{ |
| 86 |
$this->output->setDecorated($decorated); |
| 87 |
} |
| 88 |
|
| 89 |
/** |
| 90 |
* {@inheritdoc} |
| 91 |
*/ |
| 92 |
public function isDecorated() |
| 93 |
{ |
| 94 |
return $this->output->isDecorated(); |
| 95 |
} |
| 96 |
|
| 97 |
/** |
| 98 |
* {@inheritdoc} |
| 99 |
*/ |
| 100 |
public function setFormatter(OutputFormatterInterface $formatter) |
| 101 |
{ |
| 102 |
$this->output->setFormatter($formatter); |
| 103 |
} |
| 104 |
|
| 105 |
/** |
| 106 |
* {@inheritdoc} |
| 107 |
*/ |
| 108 |
public function getFormatter() |
| 109 |
{ |
| 110 |
return $this->output->getFormatter(); |
| 111 |
} |
| 112 |
|
| 113 |
/** |
| 114 |
* {@inheritdoc} |
| 115 |
*/ |
| 116 |
public function isQuiet() |
| 117 |
{ |
| 118 |
return $this->output->isQuiet(); |
| 119 |
} |
| 120 |
|
| 121 |
/** |
| 122 |
* {@inheritdoc} |
| 123 |
*/ |
| 124 |
public function isVerbose() |
| 125 |
{ |
| 126 |
return $this->output->isVerbose(); |
| 127 |
} |
| 128 |
|
| 129 |
/** |
| 130 |
* {@inheritdoc} |
| 131 |
*/ |
| 132 |
public function isVeryVerbose() |
| 133 |
{ |
| 134 |
return $this->output->isVeryVerbose(); |
| 135 |
} |
| 136 |
|
| 137 |
/** |
| 138 |
* {@inheritdoc} |
| 139 |
*/ |
| 140 |
public function isDebug() |
| 141 |
{ |
| 142 |
return $this->output->isDebug(); |
| 143 |
} |
| 144 |
|
| 145 |
protected function getErrorOutput() |
| 146 |
{ |
| 147 |
if (!$this->output instanceof ConsoleOutputInterface) { |
| 148 |
return $this->output; |
| 149 |
} |
| 150 |
|
| 151 |
return $this->output->getErrorOutput(); |
| 152 |
} |
| 153 |
} |
| 154 |
|