@@ -232,7 +232,7 @@ |
||
| 232 | 232 | return hash_equals( |
| 233 | 233 | hash_hmac('sha256', $payload['hmac'], $bytes, true), |
| 234 | 234 | $calc |
| 235 | - ); |
|
| 235 | + ); |
|
| 236 | 236 | } |
| 237 | 237 | |
| 238 | 238 | /** |
@@ -65,7 +65,7 @@ |
||
| 65 | 65 | if (static::supported($key, $cipher)) { |
| 66 | 66 | $this->key = $key; |
| 67 | 67 | $this->cipher = $cipher; |
| 68 | - } else { |
|
| 68 | + } else { |
|
| 69 | 69 | throw new RuntimeException('The only supported ciphers are AES-128-CBC and AES-256-CBC with the correct key lengths'); |
| 70 | 70 | } |
| 71 | 71 | } |
@@ -44,14 +44,14 @@ discard block |
||
| 44 | 44 | $text = ''; |
| 45 | 45 | |
| 46 | 46 | $options = \array_merge([ |
| 47 | - 'leftChar' => '', // e.g ' ', ' * ' |
|
| 48 | - 'sepChar' => ' ', // e.g ' | ' OUT: key | value |
|
| 49 | - 'keyStyle' => '', // e.g 'info','comment' |
|
| 50 | - 'valStyle' => '', // e.g 'info','comment' |
|
| 47 | + 'leftChar' => '', // e.g ' ', ' * ' |
|
| 48 | + 'sepChar' => ' ', // e.g ' | ' OUT: key | value |
|
| 49 | + 'keyStyle' => '', // e.g 'info','comment' |
|
| 50 | + 'valStyle' => '', // e.g 'info','comment' |
|
| 51 | 51 | 'keyMinWidth' => 8, |
| 52 | 52 | 'keyMaxWidth' => 0, |
| 53 | 53 | 'keyPadPos' => 'right', |
| 54 | - 'ucFirst' => true, // upper first char for value |
|
| 54 | + 'ucFirst' => true, // upper first char for value |
|
| 55 | 55 | ], $options); |
| 56 | 56 | |
| 57 | 57 | $keyStyle = \trim($options['keyStyle']); |
@@ -86,10 +86,10 @@ discard block |
||
| 86 | 86 | $val = \is_scalar($val) ? (string) $val : $val; |
| 87 | 87 | } |
| 88 | 88 | |
| 89 | - $temp .= ( ! \is_numeric($k) ? "$k: " : '') . "$val, "; |
|
| 89 | + $temp .= ( ! \is_numeric($k) ? "$k: " : '')."$val, "; |
|
| 90 | 90 | } |
| 91 | 91 | |
| 92 | - $value = \rtrim($temp, ' ,') . ']'; |
|
| 92 | + $value = \rtrim($temp, ' ,').']'; |
|
| 93 | 93 | } elseif (\is_bool($value)) { |
| 94 | 94 | $value = $value ? '(True)' : '(False)'; |
| 95 | 95 | } else { |
@@ -36,15 +36,15 @@ |
||
| 36 | 36 | * @param |
| 37 | 37 | */ |
| 38 | 38 | /** |
| 39 | - * Returns a well formatted table. |
|
| 40 | - * |
|
| 41 | - * @param array $tbody List of rows |
|
| 42 | - * @param array $thead List of columns |
|
| 43 | - * |
|
| 44 | - * @return void |
|
| 45 | - */ |
|
| 46 | - public static function table(array $tbody, array $thead = []) |
|
| 47 | - { |
|
| 39 | + * Returns a well formatted table. |
|
| 40 | + * |
|
| 41 | + * @param array $tbody List of rows |
|
| 42 | + * @param array $thead List of columns |
|
| 43 | + * |
|
| 44 | + * @return void |
|
| 45 | + */ |
|
| 46 | + public static function table(array $tbody, array $thead = []) |
|
| 47 | + { |
|
| 48 | 48 | |
| 49 | - } |
|
| 49 | + } |
|
| 50 | 50 | } |
| 51 | 51 | \ No newline at end of file |
@@ -59,7 +59,7 @@ |
||
| 59 | 59 | 'blink' => 5, |
| 60 | 60 | 'reverse' => 7, |
| 61 | 61 | 'conceal' => 8, |
| 62 | - ]; |
|
| 62 | + ]; |
|
| 63 | 63 | |
| 64 | 64 | /** |
| 65 | 65 | * Gets the background of CLI command. |
@@ -519,7 +519,7 @@ |
||
| 519 | 519 | * |
| 520 | 520 | * @param \Syscodes\Components\Console\Command\Command $command The command name |
| 521 | 521 | * @param \Syscodes\Components\Contracts\Console\Input\Input $input The input interface implemented |
| 522 | - * @param \Syscodes\Components\Contracts\Console\Output\Output $output The output interface implemented |
|
| 522 | + * @param \Syscodes\Components\Contracts\Console\Output\Output $output The output interface implemented |
|
| 523 | 523 | * |
| 524 | 524 | * @return int 0 if everything went fine, or an error code |
| 525 | 525 | */ |
@@ -281,7 +281,7 @@ discard block |
||
| 281 | 281 | try { |
| 282 | 282 | $this->runningCommand = null; |
| 283 | 283 | $command = $this->findCommand($name); |
| 284 | - } catch(Throwable $e) { |
|
| 284 | + } catch (Throwable $e) { |
|
| 285 | 285 | if ( ! ($e instanceof CommandNotFoundException && ! $e instanceof NamespaceNotFoundException) || 1 !== \count($alternatives = $e->getAlternatives()) || ! $input->isInteractive()) { |
| 286 | 286 | throw $e; |
| 287 | 287 | } |
@@ -436,7 +436,7 @@ discard block |
||
| 436 | 436 | |
| 437 | 437 | if ($alternatives = $this->findCommandAlternatives($name, $allCommands)) { |
| 438 | 438 | // remove hidden commands |
| 439 | - $alternatives = array_filter($alternatives, function ($name) { |
|
| 439 | + $alternatives = array_filter($alternatives, function($name) { |
|
| 440 | 440 | return ! $this->get($name)->isHidden(); |
| 441 | 441 | }); |
| 442 | 442 | |
@@ -582,7 +582,7 @@ discard block |
||
| 582 | 582 | |
| 583 | 583 | $commands = $this->commands; |
| 584 | 584 | foreach ($this->commandLoader->getNames() as $name) { |
| 585 | - if (!isset($commands[$name]) && $this->has($name)) { |
|
| 585 | + if ( ! isset($commands[$name]) && $this->has($name)) { |
|
| 586 | 586 | $commands[$name] = $this->get($name); |
| 587 | 587 | } |
| 588 | 588 | } |
@@ -754,7 +754,7 @@ discard block |
||
| 754 | 754 | } |
| 755 | 755 | } |
| 756 | 756 | |
| 757 | - $alternatives = array_filter($alternatives, function ($levenhtein) use ($threshold) { |
|
| 757 | + $alternatives = array_filter($alternatives, function($levenhtein) use ($threshold) { |
|
| 758 | 758 | return $levenhtein < 2 * $threshold; |
| 759 | 759 | }); |
| 760 | 760 | |
@@ -67,14 +67,14 @@ |
||
| 67 | 67 | ), $options); |
| 68 | 68 | } |
| 69 | 69 | |
| 70 | - /** |
|
| 71 | - * Describes an InputOption instance. |
|
| 72 | - * |
|
| 73 | - * @param \Syscodes\Components\Console\Input\InputOption $option The option implemented |
|
| 74 | - * @param array $options The options of the console |
|
| 75 | - * |
|
| 76 | - * @return void |
|
| 77 | - */ |
|
| 70 | + /** |
|
| 71 | + * Describes an InputOption instance. |
|
| 72 | + * |
|
| 73 | + * @param \Syscodes\Components\Console\Input\InputOption $option The option implemented |
|
| 74 | + * @param array $options The options of the console |
|
| 75 | + * |
|
| 76 | + * @return void |
|
| 77 | + */ |
|
| 78 | 78 | protected function describeOption(InputOption $option, array $options = []) |
| 79 | 79 | { |
| 80 | 80 | if ($option->isAcceptValue() && null !== $option->getDefault() && ( ! is_array($option->getDefault()) || count($option->getDefault()))) { |
@@ -27,136 +27,136 @@ |
||
| 27 | 27 | */ |
| 28 | 28 | trait InteractsIO |
| 29 | 29 | { |
| 30 | - /** |
|
| 31 | - * The output interface implementation. |
|
| 32 | - * |
|
| 33 | - * @var \Syscodes\Components\Contracts\Console\Output $output |
|
| 34 | - */ |
|
| 35 | - protected $output; |
|
| 30 | + /** |
|
| 31 | + * The output interface implementation. |
|
| 32 | + * |
|
| 33 | + * @var \Syscodes\Components\Contracts\Console\Output $output |
|
| 34 | + */ |
|
| 35 | + protected $output; |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * Enter a number of empty lines. |
|
| 39 | - * |
|
| 40 | - * @param int $num Number of lines to output |
|
| 41 | - * |
|
| 42 | - * @return string |
|
| 43 | - */ |
|
| 44 | - public function newline(int $num = 1) |
|
| 45 | - { |
|
| 46 | - $this->newLine($num); |
|
| 47 | - } |
|
| 37 | + /** |
|
| 38 | + * Enter a number of empty lines. |
|
| 39 | + * |
|
| 40 | + * @param int $num Number of lines to output |
|
| 41 | + * |
|
| 42 | + * @return string |
|
| 43 | + */ |
|
| 44 | + public function newline(int $num = 1) |
|
| 45 | + { |
|
| 46 | + $this->newLine($num); |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * Writes a string formatting for comment output. |
|
| 51 | - * |
|
| 52 | - * @param string $message |
|
| 53 | - * |
|
| 54 | - * @return void |
|
| 55 | - */ |
|
| 56 | - public function comment(string $message) |
|
| 57 | - { |
|
| 58 | - $this->commandline($message, 'comment'); |
|
| 59 | - } |
|
| 49 | + /** |
|
| 50 | + * Writes a string formatting for comment output. |
|
| 51 | + * |
|
| 52 | + * @param string $message |
|
| 53 | + * |
|
| 54 | + * @return void |
|
| 55 | + */ |
|
| 56 | + public function comment(string $message) |
|
| 57 | + { |
|
| 58 | + $this->commandline($message, 'comment'); |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - /** |
|
| 62 | - * Writes a string formatting for note output. |
|
| 63 | - * |
|
| 64 | - * @param string $message |
|
| 65 | - * |
|
| 66 | - * @return void |
|
| 67 | - */ |
|
| 68 | - public function note(string $message) |
|
| 69 | - { |
|
| 70 | - $this->commandline($message, 'note'); |
|
| 71 | - } |
|
| 61 | + /** |
|
| 62 | + * Writes a string formatting for note output. |
|
| 63 | + * |
|
| 64 | + * @param string $message |
|
| 65 | + * |
|
| 66 | + * @return void |
|
| 67 | + */ |
|
| 68 | + public function note(string $message) |
|
| 69 | + { |
|
| 70 | + $this->commandline($message, 'note'); |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | - /** |
|
| 74 | - * Writes a string formatting for success output. |
|
| 75 | - * |
|
| 76 | - * @param string $message |
|
| 77 | - * |
|
| 78 | - * @return void |
|
| 79 | - */ |
|
| 80 | - public function success(string $message) |
|
| 81 | - { |
|
| 82 | - $this->commandline($message, 'success'); |
|
| 83 | - } |
|
| 73 | + /** |
|
| 74 | + * Writes a string formatting for success output. |
|
| 75 | + * |
|
| 76 | + * @param string $message |
|
| 77 | + * |
|
| 78 | + * @return void |
|
| 79 | + */ |
|
| 80 | + public function success(string $message) |
|
| 81 | + { |
|
| 82 | + $this->commandline($message, 'success'); |
|
| 83 | + } |
|
| 84 | 84 | |
| 85 | - /** |
|
| 86 | - * Writes a string formatting for info output. |
|
| 87 | - * |
|
| 88 | - * @param string $message |
|
| 89 | - * |
|
| 90 | - * @return void |
|
| 91 | - */ |
|
| 92 | - public function info(string $message) |
|
| 93 | - { |
|
| 94 | - $this->commandline($message, 'info'); |
|
| 95 | - } |
|
| 85 | + /** |
|
| 86 | + * Writes a string formatting for info output. |
|
| 87 | + * |
|
| 88 | + * @param string $message |
|
| 89 | + * |
|
| 90 | + * @return void |
|
| 91 | + */ |
|
| 92 | + public function info(string $message) |
|
| 93 | + { |
|
| 94 | + $this->commandline($message, 'info'); |
|
| 95 | + } |
|
| 96 | 96 | |
| 97 | - /** |
|
| 98 | - * Writes a string formatting for question output. |
|
| 99 | - * |
|
| 100 | - * @param string $message |
|
| 101 | - * |
|
| 102 | - * @return void |
|
| 103 | - */ |
|
| 104 | - public function question(string $message) |
|
| 105 | - { |
|
| 106 | - $this->commandline($message, 'question'); |
|
| 107 | - } |
|
| 97 | + /** |
|
| 98 | + * Writes a string formatting for question output. |
|
| 99 | + * |
|
| 100 | + * @param string $message |
|
| 101 | + * |
|
| 102 | + * @return void |
|
| 103 | + */ |
|
| 104 | + public function question(string $message) |
|
| 105 | + { |
|
| 106 | + $this->commandline($message, 'question'); |
|
| 107 | + } |
|
| 108 | 108 | |
| 109 | - /** |
|
| 110 | - * Writes a string formatting for warning output. |
|
| 111 | - * |
|
| 112 | - * @param string $message |
|
| 113 | - * |
|
| 114 | - * @return void |
|
| 115 | - */ |
|
| 116 | - public function warning(string $message) |
|
| 117 | - { |
|
| 118 | - $this->commandline($message, 'warning'); |
|
| 119 | - } |
|
| 109 | + /** |
|
| 110 | + * Writes a string formatting for warning output. |
|
| 111 | + * |
|
| 112 | + * @param string $message |
|
| 113 | + * |
|
| 114 | + * @return void |
|
| 115 | + */ |
|
| 116 | + public function warning(string $message) |
|
| 117 | + { |
|
| 118 | + $this->commandline($message, 'warning'); |
|
| 119 | + } |
|
| 120 | 120 | |
| 121 | - /** |
|
| 122 | - * Writes a string formatting for error output. |
|
| 123 | - * |
|
| 124 | - * @param string $message |
|
| 125 | - * |
|
| 126 | - * @return void |
|
| 127 | - */ |
|
| 128 | - public function error(string $message) |
|
| 129 | - { |
|
| 130 | - $this->commandline($message, 'error'); |
|
| 131 | - } |
|
| 121 | + /** |
|
| 122 | + * Writes a string formatting for error output. |
|
| 123 | + * |
|
| 124 | + * @param string $message |
|
| 125 | + * |
|
| 126 | + * @return void |
|
| 127 | + */ |
|
| 128 | + public function error(string $message) |
|
| 129 | + { |
|
| 130 | + $this->commandline($message, 'error'); |
|
| 131 | + } |
|
| 132 | 132 | |
| 133 | - /** |
|
| 134 | - * Writes a string formatting for stantard output. |
|
| 135 | - * |
|
| 136 | - * @param string $message |
|
| 137 | - * @param string|null $style |
|
| 138 | - * |
|
| 139 | - * @return void |
|
| 140 | - */ |
|
| 141 | - public function commandline(string $message, string $style = null) |
|
| 142 | - { |
|
| 143 | - $styled = $style ? "<$style>$message</>" : $message; |
|
| 133 | + /** |
|
| 134 | + * Writes a string formatting for stantard output. |
|
| 135 | + * |
|
| 136 | + * @param string $message |
|
| 137 | + * @param string|null $style |
|
| 138 | + * |
|
| 139 | + * @return void |
|
| 140 | + */ |
|
| 141 | + public function commandline(string $message, string $style = null) |
|
| 142 | + { |
|
| 143 | + $styled = $style ? "<$style>$message</>" : $message; |
|
| 144 | 144 | |
| 145 | - return $this->writeln($styled); |
|
| 146 | - } |
|
| 145 | + return $this->writeln($styled); |
|
| 146 | + } |
|
| 147 | 147 | |
| 148 | - /** |
|
| 149 | - * Outputs series of minus characters to CLI output, specified as a visual separator. |
|
| 150 | - * |
|
| 151 | - * @param int $newlines Number of lines to output, defaults to 0 |
|
| 152 | - * @param int $width Width of the line, default to 79 |
|
| 153 | - * |
|
| 154 | - * @return string |
|
| 155 | - */ |
|
| 156 | - public function hr(int $newlines = 0, $width = 79) |
|
| 157 | - { |
|
| 158 | - $this->writeln('', $newlines); |
|
| 159 | - $this->writeln(str_repeat('-', $width)); |
|
| 160 | - $this->write('', $newlines); |
|
| 161 | - } |
|
| 148 | + /** |
|
| 149 | + * Outputs series of minus characters to CLI output, specified as a visual separator. |
|
| 150 | + * |
|
| 151 | + * @param int $newlines Number of lines to output, defaults to 0 |
|
| 152 | + * @param int $width Width of the line, default to 79 |
|
| 153 | + * |
|
| 154 | + * @return string |
|
| 155 | + */ |
|
| 156 | + public function hr(int $newlines = 0, $width = 79) |
|
| 157 | + { |
|
| 158 | + $this->writeln('', $newlines); |
|
| 159 | + $this->writeln(str_repeat('-', $width)); |
|
| 160 | + $this->write('', $newlines); |
|
| 161 | + } |
|
| 162 | 162 | } |
| 163 | 163 | \ No newline at end of file |
@@ -69,10 +69,10 @@ discard block |
||
| 69 | 69 | |
| 70 | 70 | /** |
| 71 | 71 | * Sets the decorated flag. |
| 72 | - * |
|
| 73 | - * @param bool $decorated Whether to decorated messages |
|
| 74 | - * |
|
| 75 | - * @return void |
|
| 72 | + * |
|
| 73 | + * @param bool $decorated Whether to decorated messages |
|
| 74 | + * |
|
| 75 | + * @return void |
|
| 76 | 76 | */ |
| 77 | 77 | public function setDecorated(bool $decorated): void |
| 78 | 78 | { |
@@ -83,10 +83,10 @@ discard block |
||
| 83 | 83 | |
| 84 | 84 | /** |
| 85 | 85 | * Sets a output formatter instance. |
| 86 | - * |
|
| 87 | - * @param \Syscodes\Components\Contracts\Console\Output\OutputFormatter $formatter; |
|
| 88 | - * |
|
| 89 | - * @return void |
|
| 86 | + * |
|
| 87 | + * @param \Syscodes\Components\Contracts\Console\Output\OutputFormatter $formatter; |
|
| 88 | + * |
|
| 89 | + * @return void |
|
| 90 | 90 | */ |
| 91 | 91 | public function setFormatter(OutputFormatterInterface $formatter): void |
| 92 | 92 | { |
@@ -97,10 +97,10 @@ discard block |
||
| 97 | 97 | |
| 98 | 98 | /** |
| 99 | 99 | * Sets the verbosity of the output. |
| 100 | - * |
|
| 101 | - * @param int $level |
|
| 102 | - * |
|
| 103 | - * @return void |
|
| 100 | + * |
|
| 101 | + * @param int $level |
|
| 102 | + * |
|
| 103 | + * @return void |
|
| 104 | 104 | */ |
| 105 | 105 | public function setVerbosity(int $level): void |
| 106 | 106 | { |
@@ -33,215 +33,215 @@ |
||
| 33 | 33 | */ |
| 34 | 34 | abstract class Output implements OutputInterface |
| 35 | 35 | { |
| 36 | - use InteractsIO; |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * Gets formatter for output console. |
|
| 40 | - * |
|
| 41 | - * @var \Syscodes\Components\Contracts\Console\Output\OutputFormatter $formatter |
|
| 42 | - */ |
|
| 43 | - protected $formatter; |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * Gets the verbosity level. |
|
| 47 | - * |
|
| 48 | - * @var int $verbosity |
|
| 49 | - */ |
|
| 50 | - protected $verbosity; |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * Constructor. Create a new Output instance. |
|
| 54 | - * |
|
| 55 | - * @param int|null $verbosity The verbosity level |
|
| 56 | - * @param bool $decorated Whether to decorated messages |
|
| 57 | - * @param \Syscodes\Components\Contracts\Console\Output\OutputFormatter|null $formatter The output formatter instance |
|
| 58 | - * |
|
| 59 | - * @return void |
|
| 60 | - */ |
|
| 61 | - public function __construct(?int $verbosity = OutputInterface::VERBOSITY_NORMAL, bool $decorated = false, OutputFormatterInterface $formatter = null) |
|
| 62 | - { |
|
| 63 | - $this->verbosity = $verbosity ?? OutputInterface::VERBOSITY_NORMAL; |
|
| 64 | - $this->formatter = $formatter ?? new OutputFormatter(); |
|
| 36 | + use InteractsIO; |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * Gets formatter for output console. |
|
| 40 | + * |
|
| 41 | + * @var \Syscodes\Components\Contracts\Console\Output\OutputFormatter $formatter |
|
| 42 | + */ |
|
| 43 | + protected $formatter; |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * Gets the verbosity level. |
|
| 47 | + * |
|
| 48 | + * @var int $verbosity |
|
| 49 | + */ |
|
| 50 | + protected $verbosity; |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * Constructor. Create a new Output instance. |
|
| 54 | + * |
|
| 55 | + * @param int|null $verbosity The verbosity level |
|
| 56 | + * @param bool $decorated Whether to decorated messages |
|
| 57 | + * @param \Syscodes\Components\Contracts\Console\Output\OutputFormatter|null $formatter The output formatter instance |
|
| 58 | + * |
|
| 59 | + * @return void |
|
| 60 | + */ |
|
| 61 | + public function __construct(?int $verbosity = OutputInterface::VERBOSITY_NORMAL, bool $decorated = false, OutputFormatterInterface $formatter = null) |
|
| 62 | + { |
|
| 63 | + $this->verbosity = $verbosity ?? OutputInterface::VERBOSITY_NORMAL; |
|
| 64 | + $this->formatter = $formatter ?? new OutputFormatter(); |
|
| 65 | 65 | |
| 66 | - $this->formatter->setDecorated($decorated); |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * Gets the decorated flag. |
|
| 71 | - * |
|
| 72 | - * @return bool |
|
| 73 | - */ |
|
| 74 | - public function getDecorated(): bool |
|
| 75 | - { |
|
| 76 | - return $this->formatter->getDecorated(); |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * Sets the decorated flag. |
|
| 81 | - * |
|
| 82 | - * @param bool $decorated Whether to decorated messages |
|
| 83 | - * |
|
| 84 | - * @return void |
|
| 85 | - */ |
|
| 86 | - public function setDecorated(bool $decorated): void |
|
| 87 | - { |
|
| 88 | - $this->formatter->setDecorated($decorated); |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * Returns a output formatter instance. |
|
| 93 | - * |
|
| 94 | - * @return \Syscodes\Components\Contracts\Console\Output\OutputFormatter |
|
| 95 | - */ |
|
| 96 | - public function getFormatter(): OutputFormatterInterface |
|
| 97 | - { |
|
| 98 | - return $this->formatter; |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - /** |
|
| 102 | - * Sets a output formatter instance. |
|
| 103 | - * |
|
| 104 | - * @param \Syscodes\Components\Contracts\Console\Output\OutputFormatter $formatter; |
|
| 105 | - * |
|
| 106 | - * @return void |
|
| 107 | - */ |
|
| 108 | - public function setFormatter(OutputFormatterInterface $formatter): void |
|
| 109 | - { |
|
| 110 | - $this->formatter = $formatter; |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - /** |
|
| 114 | - * Gets the current verbosity of the output. |
|
| 115 | - * |
|
| 116 | - * @return int |
|
| 117 | - */ |
|
| 118 | - public function getVerbosity(): int |
|
| 119 | - { |
|
| 120 | - return $this->verbosity; |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - /** |
|
| 124 | - * Sets the verbosity of the output. |
|
| 125 | - * |
|
| 126 | - * @param int $level |
|
| 127 | - * |
|
| 128 | - * @return void |
|
| 129 | - */ |
|
| 130 | - public function setVerbosity(int $level): void |
|
| 131 | - { |
|
| 132 | - $this->verbosity = $level; |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - /** |
|
| 136 | - * Returns whether verbosity is quiet (-q). |
|
| 137 | - * |
|
| 138 | - * @return bool |
|
| 139 | - */ |
|
| 140 | - public function isQuiet(): bool |
|
| 141 | - { |
|
| 142 | - return OutputInterface::VERBOSITY_QUIET === $this->verbosity; |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - /** |
|
| 146 | - * Returns whether verbosity is verbose (-v). |
|
| 147 | - * |
|
| 148 | - * @return bool |
|
| 149 | - */ |
|
| 150 | - public function isVerbose(): bool |
|
| 151 | - { |
|
| 152 | - return OutputInterface::VERBOSITY_VERBOSE <= $this->verbosity; |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - /** |
|
| 156 | - * Returns whether verbosity is very verbose (-vv). |
|
| 157 | - * |
|
| 158 | - * @return bool |
|
| 159 | - */ |
|
| 160 | - public function isVeryVerbose(): bool |
|
| 161 | - { |
|
| 162 | - return OutputInterface::VERBOSITY_VERY_VERBOSE <= $this->verbosity; |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - /** |
|
| 166 | - * Returns whether verbosity is debug (-vvv). |
|
| 167 | - * |
|
| 168 | - * @return bool |
|
| 169 | - */ |
|
| 170 | - public function isDebug(): bool |
|
| 171 | - { |
|
| 172 | - return OutputInterface::VERBOSITY_QUIET <= $this->verbosity; |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - /** |
|
| 176 | - * Enter a number of empty lines. |
|
| 177 | - * |
|
| 178 | - * @param int $num Number of lines to output |
|
| 179 | - * |
|
| 180 | - * @return string |
|
| 181 | - */ |
|
| 182 | - public function newLine(int $num = 1) |
|
| 183 | - { |
|
| 184 | - return $this->write(str_repeat(\PHP_EOL, max($num, 1))); |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - /** |
|
| 188 | - * Writes a message to the output and adds a newline at the end. |
|
| 189 | - * |
|
| 190 | - * @param string|iterable $messages The message as an iterable of strings or a single string |
|
| 191 | - * @param int $options A bitmask of options (0 is considered the same as self::OUTPUT_NORMAL) |
|
| 192 | - * |
|
| 193 | - * @return string |
|
| 194 | - */ |
|
| 195 | - public function writeln($messages, int $options = OutputInterface::OUTPUT_NORMAL) |
|
| 196 | - { |
|
| 197 | - return $this->write($messages, true, $options); |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - /** |
|
| 201 | - * Outputs a string to the cli. If you send an array it will implode them |
|
| 202 | - * with a line break. |
|
| 203 | - * |
|
| 204 | - * @param string|iterable $messages The text to output, or array of lines |
|
| 205 | - * @param bool $newline Add a newline command |
|
| 206 | - * @param int $options A bitmask of options (0 is considered the same as self::OUTPUT_NORMAL) |
|
| 207 | - * |
|
| 208 | - * @return string |
|
| 209 | - */ |
|
| 210 | - public function write($messages, bool $newline = false, int $options = OutputInterface::OUTPUT_NORMAL) |
|
| 211 | - { |
|
| 212 | - if ( ! is_iterable($messages)) { |
|
| 213 | - $messages = [$messages]; |
|
| 214 | - } |
|
| 66 | + $this->formatter->setDecorated($decorated); |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * Gets the decorated flag. |
|
| 71 | + * |
|
| 72 | + * @return bool |
|
| 73 | + */ |
|
| 74 | + public function getDecorated(): bool |
|
| 75 | + { |
|
| 76 | + return $this->formatter->getDecorated(); |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * Sets the decorated flag. |
|
| 81 | + * |
|
| 82 | + * @param bool $decorated Whether to decorated messages |
|
| 83 | + * |
|
| 84 | + * @return void |
|
| 85 | + */ |
|
| 86 | + public function setDecorated(bool $decorated): void |
|
| 87 | + { |
|
| 88 | + $this->formatter->setDecorated($decorated); |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * Returns a output formatter instance. |
|
| 93 | + * |
|
| 94 | + * @return \Syscodes\Components\Contracts\Console\Output\OutputFormatter |
|
| 95 | + */ |
|
| 96 | + public function getFormatter(): OutputFormatterInterface |
|
| 97 | + { |
|
| 98 | + return $this->formatter; |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + /** |
|
| 102 | + * Sets a output formatter instance. |
|
| 103 | + * |
|
| 104 | + * @param \Syscodes\Components\Contracts\Console\Output\OutputFormatter $formatter; |
|
| 105 | + * |
|
| 106 | + * @return void |
|
| 107 | + */ |
|
| 108 | + public function setFormatter(OutputFormatterInterface $formatter): void |
|
| 109 | + { |
|
| 110 | + $this->formatter = $formatter; |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + /** |
|
| 114 | + * Gets the current verbosity of the output. |
|
| 115 | + * |
|
| 116 | + * @return int |
|
| 117 | + */ |
|
| 118 | + public function getVerbosity(): int |
|
| 119 | + { |
|
| 120 | + return $this->verbosity; |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + /** |
|
| 124 | + * Sets the verbosity of the output. |
|
| 125 | + * |
|
| 126 | + * @param int $level |
|
| 127 | + * |
|
| 128 | + * @return void |
|
| 129 | + */ |
|
| 130 | + public function setVerbosity(int $level): void |
|
| 131 | + { |
|
| 132 | + $this->verbosity = $level; |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + /** |
|
| 136 | + * Returns whether verbosity is quiet (-q). |
|
| 137 | + * |
|
| 138 | + * @return bool |
|
| 139 | + */ |
|
| 140 | + public function isQuiet(): bool |
|
| 141 | + { |
|
| 142 | + return OutputInterface::VERBOSITY_QUIET === $this->verbosity; |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + /** |
|
| 146 | + * Returns whether verbosity is verbose (-v). |
|
| 147 | + * |
|
| 148 | + * @return bool |
|
| 149 | + */ |
|
| 150 | + public function isVerbose(): bool |
|
| 151 | + { |
|
| 152 | + return OutputInterface::VERBOSITY_VERBOSE <= $this->verbosity; |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + /** |
|
| 156 | + * Returns whether verbosity is very verbose (-vv). |
|
| 157 | + * |
|
| 158 | + * @return bool |
|
| 159 | + */ |
|
| 160 | + public function isVeryVerbose(): bool |
|
| 161 | + { |
|
| 162 | + return OutputInterface::VERBOSITY_VERY_VERBOSE <= $this->verbosity; |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + /** |
|
| 166 | + * Returns whether verbosity is debug (-vvv). |
|
| 167 | + * |
|
| 168 | + * @return bool |
|
| 169 | + */ |
|
| 170 | + public function isDebug(): bool |
|
| 171 | + { |
|
| 172 | + return OutputInterface::VERBOSITY_QUIET <= $this->verbosity; |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + /** |
|
| 176 | + * Enter a number of empty lines. |
|
| 177 | + * |
|
| 178 | + * @param int $num Number of lines to output |
|
| 179 | + * |
|
| 180 | + * @return string |
|
| 181 | + */ |
|
| 182 | + public function newLine(int $num = 1) |
|
| 183 | + { |
|
| 184 | + return $this->write(str_repeat(\PHP_EOL, max($num, 1))); |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + /** |
|
| 188 | + * Writes a message to the output and adds a newline at the end. |
|
| 189 | + * |
|
| 190 | + * @param string|iterable $messages The message as an iterable of strings or a single string |
|
| 191 | + * @param int $options A bitmask of options (0 is considered the same as self::OUTPUT_NORMAL) |
|
| 192 | + * |
|
| 193 | + * @return string |
|
| 194 | + */ |
|
| 195 | + public function writeln($messages, int $options = OutputInterface::OUTPUT_NORMAL) |
|
| 196 | + { |
|
| 197 | + return $this->write($messages, true, $options); |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + /** |
|
| 201 | + * Outputs a string to the cli. If you send an array it will implode them |
|
| 202 | + * with a line break. |
|
| 203 | + * |
|
| 204 | + * @param string|iterable $messages The text to output, or array of lines |
|
| 205 | + * @param bool $newline Add a newline command |
|
| 206 | + * @param int $options A bitmask of options (0 is considered the same as self::OUTPUT_NORMAL) |
|
| 207 | + * |
|
| 208 | + * @return string |
|
| 209 | + */ |
|
| 210 | + public function write($messages, bool $newline = false, int $options = OutputInterface::OUTPUT_NORMAL) |
|
| 211 | + { |
|
| 212 | + if ( ! is_iterable($messages)) { |
|
| 213 | + $messages = [$messages]; |
|
| 214 | + } |
|
| 215 | 215 | |
| 216 | - $types = OutputInterface::OUTPUT_NORMAL | OutputInterface::OUTPUT_RAW | OutputInterface::OUTPUT_PLAIN; |
|
| 217 | - $type = $types & $options ?: OutputInterface::OUTPUT_NORMAL; |
|
| 216 | + $types = OutputInterface::OUTPUT_NORMAL | OutputInterface::OUTPUT_RAW | OutputInterface::OUTPUT_PLAIN; |
|
| 217 | + $type = $types & $options ?: OutputInterface::OUTPUT_NORMAL; |
|
| 218 | 218 | |
| 219 | - $verbosities = OutputInterface::VERBOSITY_QUIET | OutputInterface::VERBOSITY_NORMAL | OutputInterface::VERBOSITY_VERBOSE | OutputInterface::VERBOSITY_VERY_VERBOSE | OutputInterface::VERBOSITY_DEBUG; |
|
| 219 | + $verbosities = OutputInterface::VERBOSITY_QUIET | OutputInterface::VERBOSITY_NORMAL | OutputInterface::VERBOSITY_VERBOSE | OutputInterface::VERBOSITY_VERY_VERBOSE | OutputInterface::VERBOSITY_DEBUG; |
|
| 220 | 220 | |
| 221 | - $verbosity = $verbosities & $options ?: OutputInterface::VERBOSITY_NORMAL; |
|
| 221 | + $verbosity = $verbosities & $options ?: OutputInterface::VERBOSITY_NORMAL; |
|
| 222 | 222 | |
| 223 | - if ($verbosity > $this->getVerbosity()) { |
|
| 224 | - return; |
|
| 225 | - } |
|
| 223 | + if ($verbosity > $this->getVerbosity()) { |
|
| 224 | + return; |
|
| 225 | + } |
|
| 226 | 226 | |
| 227 | - foreach ($messages as $message) { |
|
| 228 | - match ($type) { |
|
| 229 | - OutputInterface::OUTPUT_NORMAL => $message = $this->formatter->format($message), |
|
| 230 | - OutputInterface::OUTPUT_RAW, |
|
| 231 | - OutputInterface::OUTPUT_PLAIN => $message = strip_tags($this->formatter->format($message)), |
|
| 232 | - }; |
|
| 233 | - } |
|
| 227 | + foreach ($messages as $message) { |
|
| 228 | + match ($type) { |
|
| 229 | + OutputInterface::OUTPUT_NORMAL => $message = $this->formatter->format($message), |
|
| 230 | + OutputInterface::OUTPUT_RAW, |
|
| 231 | + OutputInterface::OUTPUT_PLAIN => $message = strip_tags($this->formatter->format($message)), |
|
| 232 | + }; |
|
| 233 | + } |
|
| 234 | 234 | |
| 235 | - $this->toWrite($message ?? '', $newline); |
|
| 236 | - } |
|
| 237 | - |
|
| 238 | - /** |
|
| 239 | - * Writes a message to the output. |
|
| 240 | - * |
|
| 241 | - * @param string $message The text to output |
|
| 242 | - * @param bool $newline Add a newline command |
|
| 243 | - * |
|
| 244 | - * @return void |
|
| 245 | - */ |
|
| 246 | - abstract protected function toWrite(string $message, bool $newline): void; |
|
| 235 | + $this->toWrite($message ?? '', $newline); |
|
| 236 | + } |
|
| 237 | + |
|
| 238 | + /** |
|
| 239 | + * Writes a message to the output. |
|
| 240 | + * |
|
| 241 | + * @param string $message The text to output |
|
| 242 | + * @param bool $newline Add a newline command |
|
| 243 | + * |
|
| 244 | + * @return void |
|
| 245 | + */ |
|
| 246 | + abstract protected function toWrite(string $message, bool $newline): void; |
|
| 247 | 247 | } |
| 248 | 248 | \ No newline at end of file |