|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * This file is part of CaptainHook |
| 5 | + * |
| 6 | + * (c) Sebastian Feldmann <sf@sebastian-feldmann.info> |
| 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 CaptainHook\App\Console\IO; |
| 13 | + |
| 14 | +use CaptainHook\App\Console\IO; |
| 15 | +use CaptainHook\App\Console\IOUtil; |
| 16 | +use SebastianFeldmann\Cli\Reader\StandardInput; |
| 17 | +use Symfony\Component\Console\Input\InputInterface; |
| 18 | +use Symfony\Component\Console\Helper\HelperSet; |
| 19 | +use Symfony\Component\Console\Output\ConsoleOutputInterface; |
| 20 | +use Symfony\Component\Console\Output\OutputInterface; |
| 21 | +use Symfony\Component\Console\Question\ConfirmationQuestion; |
| 22 | +use Symfony\Component\Console\Question\Question; |
| 23 | + |
| 24 | +/** |
| 25 | + * Class CollectorIO |
| 26 | + * |
| 27 | + * @package CaptainHook |
| 28 | + * @author Sebastian Feldmann <sf@sebastian-feldmann.info> |
| 29 | + * @link https://github.com/captainhookphp/captainhook |
| 30 | + * @since Class available since Release 5.19.0 |
| 31 | + */ |
| 32 | +class CollectorIO implements IO |
| 33 | +{ |
| 34 | + /** |
| 35 | + * @var \CaptainHook\App\Console\IO |
| 36 | + */ |
| 37 | + private IO $io; |
| 38 | + |
| 39 | + /** |
| 40 | + * @var array<\CaptainHook\App\Console\IO\Message> |
| 41 | + */ |
| 42 | + private array $messages = []; |
| 43 | + |
| 44 | + /** |
| 45 | + * Constructor |
| 46 | + * |
| 47 | + */ |
| 48 | + public function __construct(IO $io) |
| 49 | + { |
| 50 | + $this->io = $io; |
| 51 | + } |
| 52 | + |
| 53 | + |
| 54 | + /** |
| 55 | + * |
| 56 | + * @param string $messages |
| 57 | + * @param bool $newline |
| 58 | + * @param int $verbosity |
| 59 | + * @return void |
| 60 | + */ |
| 61 | + public function write($messages, $newline = true, $verbosity = IO::NORMAL) |
| 62 | + { |
| 63 | + $this->messages[] = new Message($messages, $newline, $verbosity); |
| 64 | + } |
| 65 | + |
| 66 | + /** |
| 67 | + * @param string $messages |
| 68 | + * @param bool $newline |
| 69 | + * @param int $verbosity |
| 70 | + * @return void |
| 71 | + */ |
| 72 | + public function writeError($messages, $newline = true, $verbosity = IO::NORMAL) |
| 73 | + { |
| 74 | + $this->messages[] = new Message($messages, $newline, $verbosity); |
| 75 | + } |
| 76 | + |
| 77 | + /** |
| 78 | + * @return array<\CaptainHook\App\Console\IO\Message> |
| 79 | + */ |
| 80 | + public function getMessages(): array |
| 81 | + { |
| 82 | + return $this->messages; |
| 83 | + } |
| 84 | + |
| 85 | + /** |
| 86 | + * Return the original cli arguments |
| 87 | + * |
| 88 | + * @return array<string, mixed> |
| 89 | + */ |
| 90 | + public function getArguments(): array |
| 91 | + { |
| 92 | + return $this->io->getArguments(); |
| 93 | + } |
| 94 | + |
| 95 | + /** |
| 96 | + * Return the original cli argument or a given default |
| 97 | + * |
| 98 | + * @param string $name |
| 99 | + * @param string $default |
| 100 | + * @return string |
| 101 | + */ |
| 102 | + public function getArgument(string $name, string $default = ''): string |
| 103 | + { |
| 104 | + return $this->io->getArgument($name, $default); |
| 105 | + } |
| 106 | + |
| 107 | + /** |
| 108 | + * Return the piped in standard input |
| 109 | + * |
| 110 | + * @return string[] |
| 111 | + */ |
| 112 | + public function getStandardInput(): array |
| 113 | + { |
| 114 | + return $this->io->getStandardInput(); |
| 115 | + } |
| 116 | + |
| 117 | + public function isInteractive() |
| 118 | + { |
| 119 | + return $this->io->isInteractive(); |
| 120 | + } |
| 121 | + |
| 122 | + public function isVerbose() |
| 123 | + { |
| 124 | + return $this->io->isVerbose(); |
| 125 | + } |
| 126 | + |
| 127 | + public function isVeryVerbose() |
| 128 | + { |
| 129 | + return $this->io->isVeryVerbose(); |
| 130 | + } |
| 131 | + |
| 132 | + public function isDebug() |
| 133 | + { |
| 134 | + return $this->io->isDebug(); |
| 135 | + } |
| 136 | + |
| 137 | + public function ask($question, $default = null) |
| 138 | + { |
| 139 | + return $this->io->ask($question, $default); |
| 140 | + } |
| 141 | + |
| 142 | + public function askConfirmation($question, $default = true) |
| 143 | + { |
| 144 | + return $this->io->askConfirmation($question, $default); |
| 145 | + } |
| 146 | + |
| 147 | + public function askAndValidate($question, $validator, $attempts = null, $default = null) |
| 148 | + { |
| 149 | + $this->io->askAndValidate($question, $validator, $attempts, $default); |
| 150 | + } |
| 151 | +} |
0 commit comments