| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- <?php
- namespace Michel\Console;
- use RuntimeException;
- use const PHP_EOL;
- final class Output implements OutputInterface
- {
- /**
- * @var callable
- */
- private $output;
- public function __construct(callable $output = null)
- {
- if ($output === null) {
- $output = function ($message, $error = false) {
- if ($error) {
- fwrite(STDERR, $message);
- return;
- }
- fwrite(STDOUT, $message);
- };
- }
- $this->output = $output;
- }
- /**
- * @var bool
- */
- private bool $verbose = false;
- public function error(string $message): void
- {
- $output = $this->output;
- $output($message, true);
- }
- public function write(string $message): void
- {
- $output = $this->output;
- $output($message);
- }
- public function writeln(string $message): void
- {
- $this->write($message);
- $this->write(PHP_EOL);
- }
- public function setVerbose(bool $verbose): void
- {
- $this->verbose = $verbose;
- }
- public function isVerbose(): bool
- {
- return $this->verbose;
- }
- }
|