@@ -18,61 +18,61 @@ |
||
| 18 | 18 | */ |
| 19 | 19 | class TableCell |
| 20 | 20 | { |
| 21 | - private $value; |
|
| 22 | - private $options = [ |
|
| 23 | - 'rowspan' => 1, |
|
| 24 | - 'colspan' => 1, |
|
| 25 | - 'style' => null, |
|
| 26 | - ]; |
|
| 21 | + private $value; |
|
| 22 | + private $options = [ |
|
| 23 | + 'rowspan' => 1, |
|
| 24 | + 'colspan' => 1, |
|
| 25 | + 'style' => null, |
|
| 26 | + ]; |
|
| 27 | 27 | |
| 28 | - public function __construct(string $value = '', array $options = []) |
|
| 29 | - { |
|
| 30 | - $this->value = $value; |
|
| 28 | + public function __construct(string $value = '', array $options = []) |
|
| 29 | + { |
|
| 30 | + $this->value = $value; |
|
| 31 | 31 | |
| 32 | - // check option names |
|
| 33 | - if ($diff = array_diff(array_keys($options), array_keys($this->options))) { |
|
| 34 | - throw new InvalidArgumentException(sprintf('The TableCell does not support the following options: \'%s\'.', implode('\', \'', $diff))); |
|
| 35 | - } |
|
| 32 | + // check option names |
|
| 33 | + if ($diff = array_diff(array_keys($options), array_keys($this->options))) { |
|
| 34 | + throw new InvalidArgumentException(sprintf('The TableCell does not support the following options: \'%s\'.', implode('\', \'', $diff))); |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - if (isset($options['style']) && !$options['style'] instanceof TableCellStyle) { |
|
| 38 | - throw new InvalidArgumentException('The style option must be an instance of "TableCellStyle".'); |
|
| 39 | - } |
|
| 37 | + if (isset($options['style']) && !$options['style'] instanceof TableCellStyle) { |
|
| 38 | + throw new InvalidArgumentException('The style option must be an instance of "TableCellStyle".'); |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | - $this->options = array_merge($this->options, $options); |
|
| 42 | - } |
|
| 41 | + $this->options = array_merge($this->options, $options); |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * Returns the cell value. |
|
| 46 | - * |
|
| 47 | - * @return string |
|
| 48 | - */ |
|
| 49 | - public function __toString() |
|
| 50 | - { |
|
| 51 | - return $this->value; |
|
| 52 | - } |
|
| 44 | + /** |
|
| 45 | + * Returns the cell value. |
|
| 46 | + * |
|
| 47 | + * @return string |
|
| 48 | + */ |
|
| 49 | + public function __toString() |
|
| 50 | + { |
|
| 51 | + return $this->value; |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * Gets number of colspan. |
|
| 56 | - * |
|
| 57 | - * @return int |
|
| 58 | - */ |
|
| 59 | - public function getColspan() |
|
| 60 | - { |
|
| 61 | - return (int) $this->options['colspan']; |
|
| 62 | - } |
|
| 54 | + /** |
|
| 55 | + * Gets number of colspan. |
|
| 56 | + * |
|
| 57 | + * @return int |
|
| 58 | + */ |
|
| 59 | + public function getColspan() |
|
| 60 | + { |
|
| 61 | + return (int) $this->options['colspan']; |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | - /** |
|
| 65 | - * Gets number of rowspan. |
|
| 66 | - * |
|
| 67 | - * @return int |
|
| 68 | - */ |
|
| 69 | - public function getRowspan() |
|
| 70 | - { |
|
| 71 | - return (int) $this->options['rowspan']; |
|
| 72 | - } |
|
| 64 | + /** |
|
| 65 | + * Gets number of rowspan. |
|
| 66 | + * |
|
| 67 | + * @return int |
|
| 68 | + */ |
|
| 69 | + public function getRowspan() |
|
| 70 | + { |
|
| 71 | + return (int) $this->options['rowspan']; |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | - public function getStyle(): ?TableCellStyle |
|
| 75 | - { |
|
| 76 | - return $this->options['style']; |
|
| 77 | - } |
|
| 74 | + public function getStyle(): ?TableCellStyle |
|
| 75 | + { |
|
| 76 | + return $this->options['style']; |
|
| 77 | + } |
|
| 78 | 78 | } |
@@ -25,85 +25,85 @@ |
||
| 25 | 25 | */ |
| 26 | 26 | class SymfonyQuestionHelper extends QuestionHelper |
| 27 | 27 | { |
| 28 | - /** |
|
| 29 | - * {@inheritdoc} |
|
| 30 | - */ |
|
| 31 | - protected function writePrompt(OutputInterface $output, Question $question) |
|
| 32 | - { |
|
| 33 | - $text = OutputFormatter::escapeTrailingBackslash($question->getQuestion()); |
|
| 34 | - $default = $question->getDefault(); |
|
| 28 | + /** |
|
| 29 | + * {@inheritdoc} |
|
| 30 | + */ |
|
| 31 | + protected function writePrompt(OutputInterface $output, Question $question) |
|
| 32 | + { |
|
| 33 | + $text = OutputFormatter::escapeTrailingBackslash($question->getQuestion()); |
|
| 34 | + $default = $question->getDefault(); |
|
| 35 | 35 | |
| 36 | - if ($question->isMultiline()) { |
|
| 37 | - $text .= sprintf(' (press %s to continue)', $this->getEofShortcut()); |
|
| 38 | - } |
|
| 36 | + if ($question->isMultiline()) { |
|
| 37 | + $text .= sprintf(' (press %s to continue)', $this->getEofShortcut()); |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - switch (true) { |
|
| 41 | - case null === $default: |
|
| 42 | - $text = sprintf(' <info>%s</info>:', $text); |
|
| 40 | + switch (true) { |
|
| 41 | + case null === $default: |
|
| 42 | + $text = sprintf(' <info>%s</info>:', $text); |
|
| 43 | 43 | |
| 44 | - break; |
|
| 44 | + break; |
|
| 45 | 45 | |
| 46 | - case $question instanceof ConfirmationQuestion: |
|
| 47 | - $text = sprintf(' <info>%s (yes/no)</info> [<comment>%s</comment>]:', $text, $default ? 'yes' : 'no'); |
|
| 46 | + case $question instanceof ConfirmationQuestion: |
|
| 47 | + $text = sprintf(' <info>%s (yes/no)</info> [<comment>%s</comment>]:', $text, $default ? 'yes' : 'no'); |
|
| 48 | 48 | |
| 49 | - break; |
|
| 49 | + break; |
|
| 50 | 50 | |
| 51 | - case $question instanceof ChoiceQuestion && $question->isMultiselect(): |
|
| 52 | - $choices = $question->getChoices(); |
|
| 53 | - $default = explode(',', $default); |
|
| 51 | + case $question instanceof ChoiceQuestion && $question->isMultiselect(): |
|
| 52 | + $choices = $question->getChoices(); |
|
| 53 | + $default = explode(',', $default); |
|
| 54 | 54 | |
| 55 | - foreach ($default as $key => $value) { |
|
| 56 | - $default[$key] = $choices[trim($value)]; |
|
| 57 | - } |
|
| 55 | + foreach ($default as $key => $value) { |
|
| 56 | + $default[$key] = $choices[trim($value)]; |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - $text = sprintf(' <info>%s</info> [<comment>%s</comment>]:', $text, OutputFormatter::escape(implode(', ', $default))); |
|
| 59 | + $text = sprintf(' <info>%s</info> [<comment>%s</comment>]:', $text, OutputFormatter::escape(implode(', ', $default))); |
|
| 60 | 60 | |
| 61 | - break; |
|
| 61 | + break; |
|
| 62 | 62 | |
| 63 | - case $question instanceof ChoiceQuestion: |
|
| 64 | - $choices = $question->getChoices(); |
|
| 65 | - $text = sprintf(' <info>%s</info> [<comment>%s</comment>]:', $text, OutputFormatter::escape($choices[$default] ?? $default)); |
|
| 63 | + case $question instanceof ChoiceQuestion: |
|
| 64 | + $choices = $question->getChoices(); |
|
| 65 | + $text = sprintf(' <info>%s</info> [<comment>%s</comment>]:', $text, OutputFormatter::escape($choices[$default] ?? $default)); |
|
| 66 | 66 | |
| 67 | - break; |
|
| 67 | + break; |
|
| 68 | 68 | |
| 69 | - default: |
|
| 70 | - $text = sprintf(' <info>%s</info> [<comment>%s</comment>]:', $text, OutputFormatter::escape($default)); |
|
| 71 | - } |
|
| 69 | + default: |
|
| 70 | + $text = sprintf(' <info>%s</info> [<comment>%s</comment>]:', $text, OutputFormatter::escape($default)); |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | - $output->writeln($text); |
|
| 73 | + $output->writeln($text); |
|
| 74 | 74 | |
| 75 | - $prompt = ' > '; |
|
| 75 | + $prompt = ' > '; |
|
| 76 | 76 | |
| 77 | - if ($question instanceof ChoiceQuestion) { |
|
| 78 | - $output->writeln($this->formatChoiceQuestionChoices($question, 'comment')); |
|
| 77 | + if ($question instanceof ChoiceQuestion) { |
|
| 78 | + $output->writeln($this->formatChoiceQuestionChoices($question, 'comment')); |
|
| 79 | 79 | |
| 80 | - $prompt = $question->getPrompt(); |
|
| 81 | - } |
|
| 80 | + $prompt = $question->getPrompt(); |
|
| 81 | + } |
|
| 82 | 82 | |
| 83 | - $output->write($prompt); |
|
| 84 | - } |
|
| 83 | + $output->write($prompt); |
|
| 84 | + } |
|
| 85 | 85 | |
| 86 | - /** |
|
| 87 | - * {@inheritdoc} |
|
| 88 | - */ |
|
| 89 | - protected function writeError(OutputInterface $output, \Exception $error) |
|
| 90 | - { |
|
| 91 | - if ($output instanceof SymfonyStyle) { |
|
| 92 | - $output->newLine(); |
|
| 93 | - $output->error($error->getMessage()); |
|
| 86 | + /** |
|
| 87 | + * {@inheritdoc} |
|
| 88 | + */ |
|
| 89 | + protected function writeError(OutputInterface $output, \Exception $error) |
|
| 90 | + { |
|
| 91 | + if ($output instanceof SymfonyStyle) { |
|
| 92 | + $output->newLine(); |
|
| 93 | + $output->error($error->getMessage()); |
|
| 94 | 94 | |
| 95 | - return; |
|
| 96 | - } |
|
| 95 | + return; |
|
| 96 | + } |
|
| 97 | 97 | |
| 98 | - parent::writeError($output, $error); |
|
| 99 | - } |
|
| 98 | + parent::writeError($output, $error); |
|
| 99 | + } |
|
| 100 | 100 | |
| 101 | - private function getEofShortcut(): string |
|
| 102 | - { |
|
| 103 | - if ('Windows' === \PHP_OS_FAMILY) { |
|
| 104 | - return '<comment>Ctrl+Z</comment> then <comment>Enter</comment>'; |
|
| 105 | - } |
|
| 101 | + private function getEofShortcut(): string |
|
| 102 | + { |
|
| 103 | + if ('Windows' === \PHP_OS_FAMILY) { |
|
| 104 | + return '<comment>Ctrl+Z</comment> then <comment>Enter</comment>'; |
|
| 105 | + } |
|
| 106 | 106 | |
| 107 | - return '<comment>Ctrl+D</comment>'; |
|
| 108 | - } |
|
| 107 | + return '<comment>Ctrl+D</comment>'; |
|
| 108 | + } |
|
| 109 | 109 | } |
@@ -18,13 +18,13 @@ |
||
| 18 | 18 | */ |
| 19 | 19 | interface SignalableCommandInterface |
| 20 | 20 | { |
| 21 | - /** |
|
| 22 | - * Returns the list of signals to subscribe. |
|
| 23 | - */ |
|
| 24 | - public function getSubscribedSignals(): array; |
|
| 21 | + /** |
|
| 22 | + * Returns the list of signals to subscribe. |
|
| 23 | + */ |
|
| 24 | + public function getSubscribedSignals(): array; |
|
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * The method will be called when the application is signaled. |
|
| 28 | - */ |
|
| 29 | - public function handleSignal(int $signal): void; |
|
| 26 | + /** |
|
| 27 | + * The method will be called when the application is signaled. |
|
| 28 | + */ |
|
| 29 | + public function handleSignal(int $signal): void; |
|
| 30 | 30 | } |
@@ -16,30 +16,30 @@ |
||
| 16 | 16 | */ |
| 17 | 17 | class BufferedOutput extends Output |
| 18 | 18 | { |
| 19 | - private $buffer = ''; |
|
| 19 | + private $buffer = ''; |
|
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * Empties buffer and returns its content. |
|
| 23 | - * |
|
| 24 | - * @return string |
|
| 25 | - */ |
|
| 26 | - public function fetch() |
|
| 27 | - { |
|
| 28 | - $content = $this->buffer; |
|
| 29 | - $this->buffer = ''; |
|
| 21 | + /** |
|
| 22 | + * Empties buffer and returns its content. |
|
| 23 | + * |
|
| 24 | + * @return string |
|
| 25 | + */ |
|
| 26 | + public function fetch() |
|
| 27 | + { |
|
| 28 | + $content = $this->buffer; |
|
| 29 | + $this->buffer = ''; |
|
| 30 | 30 | |
| 31 | - return $content; |
|
| 32 | - } |
|
| 31 | + return $content; |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * {@inheritdoc} |
|
| 36 | - */ |
|
| 37 | - protected function doWrite(string $message, bool $newline) |
|
| 38 | - { |
|
| 39 | - $this->buffer .= $message; |
|
| 34 | + /** |
|
| 35 | + * {@inheritdoc} |
|
| 36 | + */ |
|
| 37 | + protected function doWrite(string $message, bool $newline) |
|
| 38 | + { |
|
| 39 | + $this->buffer .= $message; |
|
| 40 | 40 | |
| 41 | - if ($newline) { |
|
| 42 | - $this->buffer .= \PHP_EOL; |
|
| 43 | - } |
|
| 44 | - } |
|
| 41 | + if ($newline) { |
|
| 42 | + $this->buffer .= \PHP_EOL; |
|
| 43 | + } |
|
| 44 | + } |
|
| 45 | 45 | } |
@@ -19,14 +19,14 @@ |
||
| 19 | 19 | */ |
| 20 | 20 | interface ConsoleOutputInterface extends OutputInterface |
| 21 | 21 | { |
| 22 | - /** |
|
| 23 | - * Gets the OutputInterface for errors. |
|
| 24 | - * |
|
| 25 | - * @return OutputInterface |
|
| 26 | - */ |
|
| 27 | - public function getErrorOutput(); |
|
| 22 | + /** |
|
| 23 | + * Gets the OutputInterface for errors. |
|
| 24 | + * |
|
| 25 | + * @return OutputInterface |
|
| 26 | + */ |
|
| 27 | + public function getErrorOutput(); |
|
| 28 | 28 | |
| 29 | - public function setErrorOutput(OutputInterface $error); |
|
| 29 | + public function setErrorOutput(OutputInterface $error); |
|
| 30 | 30 | |
| 31 | - public function section(): ConsoleSectionOutput; |
|
| 31 | + public function section(): ConsoleSectionOutput; |
|
| 32 | 32 | } |
@@ -29,138 +29,138 @@ |
||
| 29 | 29 | */ |
| 30 | 30 | class ConsoleOutput extends StreamOutput implements ConsoleOutputInterface |
| 31 | 31 | { |
| 32 | - private $stderr; |
|
| 33 | - private $consoleSectionOutputs = []; |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * @param int $verbosity The verbosity level (one of the VERBOSITY constants in OutputInterface) |
|
| 37 | - * @param bool|null $decorated Whether to decorate messages (null for auto-guessing) |
|
| 38 | - * @param OutputFormatterInterface|null $formatter Output formatter instance (null to use default OutputFormatter) |
|
| 39 | - */ |
|
| 40 | - public function __construct(int $verbosity = self::VERBOSITY_NORMAL, bool $decorated = null, OutputFormatterInterface $formatter = null) |
|
| 41 | - { |
|
| 42 | - parent::__construct($this->openOutputStream(), $verbosity, $decorated, $formatter); |
|
| 43 | - |
|
| 44 | - if (null === $formatter) { |
|
| 45 | - // for BC reasons, stdErr has it own Formatter only when user don't inject a specific formatter. |
|
| 46 | - $this->stderr = new StreamOutput($this->openErrorStream(), $verbosity, $decorated); |
|
| 47 | - |
|
| 48 | - return; |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - $actualDecorated = $this->isDecorated(); |
|
| 52 | - $this->stderr = new StreamOutput($this->openErrorStream(), $verbosity, $decorated, $this->getFormatter()); |
|
| 53 | - |
|
| 54 | - if (null === $decorated) { |
|
| 55 | - $this->setDecorated($actualDecorated && $this->stderr->isDecorated()); |
|
| 56 | - } |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - /** |
|
| 60 | - * Creates a new output section. |
|
| 61 | - */ |
|
| 62 | - public function section(): ConsoleSectionOutput |
|
| 63 | - { |
|
| 64 | - return new ConsoleSectionOutput($this->getStream(), $this->consoleSectionOutputs, $this->getVerbosity(), $this->isDecorated(), $this->getFormatter()); |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * {@inheritdoc} |
|
| 69 | - */ |
|
| 70 | - public function setDecorated(bool $decorated) |
|
| 71 | - { |
|
| 72 | - parent::setDecorated($decorated); |
|
| 73 | - $this->stderr->setDecorated($decorated); |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * {@inheritdoc} |
|
| 78 | - */ |
|
| 79 | - public function setFormatter(OutputFormatterInterface $formatter) |
|
| 80 | - { |
|
| 81 | - parent::setFormatter($formatter); |
|
| 82 | - $this->stderr->setFormatter($formatter); |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - /** |
|
| 86 | - * {@inheritdoc} |
|
| 87 | - */ |
|
| 88 | - public function setVerbosity(int $level) |
|
| 89 | - { |
|
| 90 | - parent::setVerbosity($level); |
|
| 91 | - $this->stderr->setVerbosity($level); |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - /** |
|
| 95 | - * {@inheritdoc} |
|
| 96 | - */ |
|
| 97 | - public function getErrorOutput() |
|
| 98 | - { |
|
| 99 | - return $this->stderr; |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * {@inheritdoc} |
|
| 104 | - */ |
|
| 105 | - public function setErrorOutput(OutputInterface $error) |
|
| 106 | - { |
|
| 107 | - $this->stderr = $error; |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * Returns true if current environment supports writing console output to |
|
| 112 | - * STDOUT. |
|
| 113 | - * |
|
| 114 | - * @return bool |
|
| 115 | - */ |
|
| 116 | - protected function hasStdoutSupport() |
|
| 117 | - { |
|
| 118 | - return false === $this->isRunningOS400(); |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - /** |
|
| 122 | - * Returns true if current environment supports writing console output to |
|
| 123 | - * STDERR. |
|
| 124 | - * |
|
| 125 | - * @return bool |
|
| 126 | - */ |
|
| 127 | - protected function hasStderrSupport() |
|
| 128 | - { |
|
| 129 | - return false === $this->isRunningOS400(); |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - /** |
|
| 133 | - * Checks if current executing environment is IBM iSeries (OS400), which |
|
| 134 | - * doesn't properly convert character-encodings between ASCII to EBCDIC. |
|
| 135 | - */ |
|
| 136 | - private function isRunningOS400(): bool |
|
| 137 | - { |
|
| 138 | - $checks = [ |
|
| 139 | - \function_exists('php_uname') ? php_uname('s') : '', |
|
| 140 | - getenv('OSTYPE'), |
|
| 141 | - \PHP_OS, |
|
| 142 | - ]; |
|
| 143 | - |
|
| 144 | - return false !== stripos(implode(';', $checks), 'OS400'); |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - /** |
|
| 148 | - * @return resource |
|
| 149 | - */ |
|
| 150 | - private function openOutputStream() |
|
| 151 | - { |
|
| 152 | - if (!$this->hasStdoutSupport()) { |
|
| 153 | - return fopen('php://output', 'w'); |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - return @fopen('php://stdout', 'w') ?: fopen('php://output', 'w'); |
|
| 157 | - } |
|
| 158 | - |
|
| 159 | - /** |
|
| 160 | - * @return resource |
|
| 161 | - */ |
|
| 162 | - private function openErrorStream() |
|
| 163 | - { |
|
| 164 | - return fopen($this->hasStderrSupport() ? 'php://stderr' : 'php://output', 'w'); |
|
| 165 | - } |
|
| 32 | + private $stderr; |
|
| 33 | + private $consoleSectionOutputs = []; |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * @param int $verbosity The verbosity level (one of the VERBOSITY constants in OutputInterface) |
|
| 37 | + * @param bool|null $decorated Whether to decorate messages (null for auto-guessing) |
|
| 38 | + * @param OutputFormatterInterface|null $formatter Output formatter instance (null to use default OutputFormatter) |
|
| 39 | + */ |
|
| 40 | + public function __construct(int $verbosity = self::VERBOSITY_NORMAL, bool $decorated = null, OutputFormatterInterface $formatter = null) |
|
| 41 | + { |
|
| 42 | + parent::__construct($this->openOutputStream(), $verbosity, $decorated, $formatter); |
|
| 43 | + |
|
| 44 | + if (null === $formatter) { |
|
| 45 | + // for BC reasons, stdErr has it own Formatter only when user don't inject a specific formatter. |
|
| 46 | + $this->stderr = new StreamOutput($this->openErrorStream(), $verbosity, $decorated); |
|
| 47 | + |
|
| 48 | + return; |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + $actualDecorated = $this->isDecorated(); |
|
| 52 | + $this->stderr = new StreamOutput($this->openErrorStream(), $verbosity, $decorated, $this->getFormatter()); |
|
| 53 | + |
|
| 54 | + if (null === $decorated) { |
|
| 55 | + $this->setDecorated($actualDecorated && $this->stderr->isDecorated()); |
|
| 56 | + } |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + /** |
|
| 60 | + * Creates a new output section. |
|
| 61 | + */ |
|
| 62 | + public function section(): ConsoleSectionOutput |
|
| 63 | + { |
|
| 64 | + return new ConsoleSectionOutput($this->getStream(), $this->consoleSectionOutputs, $this->getVerbosity(), $this->isDecorated(), $this->getFormatter()); |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * {@inheritdoc} |
|
| 69 | + */ |
|
| 70 | + public function setDecorated(bool $decorated) |
|
| 71 | + { |
|
| 72 | + parent::setDecorated($decorated); |
|
| 73 | + $this->stderr->setDecorated($decorated); |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * {@inheritdoc} |
|
| 78 | + */ |
|
| 79 | + public function setFormatter(OutputFormatterInterface $formatter) |
|
| 80 | + { |
|
| 81 | + parent::setFormatter($formatter); |
|
| 82 | + $this->stderr->setFormatter($formatter); |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + /** |
|
| 86 | + * {@inheritdoc} |
|
| 87 | + */ |
|
| 88 | + public function setVerbosity(int $level) |
|
| 89 | + { |
|
| 90 | + parent::setVerbosity($level); |
|
| 91 | + $this->stderr->setVerbosity($level); |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + /** |
|
| 95 | + * {@inheritdoc} |
|
| 96 | + */ |
|
| 97 | + public function getErrorOutput() |
|
| 98 | + { |
|
| 99 | + return $this->stderr; |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * {@inheritdoc} |
|
| 104 | + */ |
|
| 105 | + public function setErrorOutput(OutputInterface $error) |
|
| 106 | + { |
|
| 107 | + $this->stderr = $error; |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + /** |
|
| 111 | + * Returns true if current environment supports writing console output to |
|
| 112 | + * STDOUT. |
|
| 113 | + * |
|
| 114 | + * @return bool |
|
| 115 | + */ |
|
| 116 | + protected function hasStdoutSupport() |
|
| 117 | + { |
|
| 118 | + return false === $this->isRunningOS400(); |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + /** |
|
| 122 | + * Returns true if current environment supports writing console output to |
|
| 123 | + * STDERR. |
|
| 124 | + * |
|
| 125 | + * @return bool |
|
| 126 | + */ |
|
| 127 | + protected function hasStderrSupport() |
|
| 128 | + { |
|
| 129 | + return false === $this->isRunningOS400(); |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + /** |
|
| 133 | + * Checks if current executing environment is IBM iSeries (OS400), which |
|
| 134 | + * doesn't properly convert character-encodings between ASCII to EBCDIC. |
|
| 135 | + */ |
|
| 136 | + private function isRunningOS400(): bool |
|
| 137 | + { |
|
| 138 | + $checks = [ |
|
| 139 | + \function_exists('php_uname') ? php_uname('s') : '', |
|
| 140 | + getenv('OSTYPE'), |
|
| 141 | + \PHP_OS, |
|
| 142 | + ]; |
|
| 143 | + |
|
| 144 | + return false !== stripos(implode(';', $checks), 'OS400'); |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + /** |
|
| 148 | + * @return resource |
|
| 149 | + */ |
|
| 150 | + private function openOutputStream() |
|
| 151 | + { |
|
| 152 | + if (!$this->hasStdoutSupport()) { |
|
| 153 | + return fopen('php://output', 'w'); |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + return @fopen('php://stdout', 'w') ?: fopen('php://output', 'w'); |
|
| 157 | + } |
|
| 158 | + |
|
| 159 | + /** |
|
| 160 | + * @return resource |
|
| 161 | + */ |
|
| 162 | + private function openErrorStream() |
|
| 163 | + { |
|
| 164 | + return fopen($this->hasStderrSupport() ? 'php://stderr' : 'php://output', 'w'); |
|
| 165 | + } |
|
| 166 | 166 | } |
@@ -21,123 +21,123 @@ |
||
| 21 | 21 | */ |
| 22 | 22 | class ConsoleSectionOutput extends StreamOutput |
| 23 | 23 | { |
| 24 | - private $content = []; |
|
| 25 | - private $lines = 0; |
|
| 26 | - private $sections; |
|
| 27 | - private $terminal; |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * @param resource $stream |
|
| 31 | - * @param ConsoleSectionOutput[] $sections |
|
| 32 | - */ |
|
| 33 | - public function __construct($stream, array &$sections, int $verbosity, bool $decorated, OutputFormatterInterface $formatter) |
|
| 34 | - { |
|
| 35 | - parent::__construct($stream, $verbosity, $decorated, $formatter); |
|
| 36 | - array_unshift($sections, $this); |
|
| 37 | - $this->sections = &$sections; |
|
| 38 | - $this->terminal = new Terminal(); |
|
| 39 | - } |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * Clears previous output for this section. |
|
| 43 | - * |
|
| 44 | - * @param int $lines Number of lines to clear. If null, then the entire output of this section is cleared |
|
| 45 | - */ |
|
| 46 | - public function clear(int $lines = null) |
|
| 47 | - { |
|
| 48 | - if (empty($this->content) || !$this->isDecorated()) { |
|
| 49 | - return; |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - if ($lines) { |
|
| 53 | - array_splice($this->content, -($lines * 2)); // Multiply lines by 2 to cater for each new line added between content |
|
| 54 | - } else { |
|
| 55 | - $lines = $this->lines; |
|
| 56 | - $this->content = []; |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - $this->lines -= $lines; |
|
| 60 | - |
|
| 61 | - parent::doWrite($this->popStreamContentUntilCurrentSection($lines), false); |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * Overwrites the previous output with a new message. |
|
| 66 | - * |
|
| 67 | - * @param array|string $message |
|
| 68 | - */ |
|
| 69 | - public function overwrite($message) |
|
| 70 | - { |
|
| 71 | - $this->clear(); |
|
| 72 | - $this->writeln($message); |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - public function getContent(): string |
|
| 76 | - { |
|
| 77 | - return implode('', $this->content); |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * @internal |
|
| 82 | - */ |
|
| 83 | - public function addContent(string $input) |
|
| 84 | - { |
|
| 85 | - foreach (explode(\PHP_EOL, $input) as $lineContent) { |
|
| 86 | - $this->lines += ceil($this->getDisplayLength($lineContent) / $this->terminal->getWidth()) ?: 1; |
|
| 87 | - $this->content[] = $lineContent; |
|
| 88 | - $this->content[] = \PHP_EOL; |
|
| 89 | - } |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - /** |
|
| 93 | - * {@inheritdoc} |
|
| 94 | - */ |
|
| 95 | - protected function doWrite(string $message, bool $newline) |
|
| 96 | - { |
|
| 97 | - if (!$this->isDecorated()) { |
|
| 98 | - parent::doWrite($message, $newline); |
|
| 99 | - |
|
| 100 | - return; |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - $erasedContent = $this->popStreamContentUntilCurrentSection(); |
|
| 104 | - |
|
| 105 | - $this->addContent($message); |
|
| 106 | - |
|
| 107 | - parent::doWrite($message, true); |
|
| 108 | - parent::doWrite($erasedContent, false); |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - /** |
|
| 112 | - * At initial stage, cursor is at the end of stream output. This method makes cursor crawl upwards until it hits |
|
| 113 | - * current section. Then it erases content it crawled through. Optionally, it erases part of current section too. |
|
| 114 | - */ |
|
| 115 | - private function popStreamContentUntilCurrentSection(int $numberOfLinesToClearFromCurrentSection = 0): string |
|
| 116 | - { |
|
| 117 | - $numberOfLinesToClear = $numberOfLinesToClearFromCurrentSection; |
|
| 118 | - $erasedContent = []; |
|
| 119 | - |
|
| 120 | - foreach ($this->sections as $section) { |
|
| 121 | - if ($section === $this) { |
|
| 122 | - break; |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - $numberOfLinesToClear += $section->lines; |
|
| 126 | - $erasedContent[] = $section->getContent(); |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - if ($numberOfLinesToClear > 0) { |
|
| 130 | - // move cursor up n lines |
|
| 131 | - parent::doWrite(sprintf("\x1b[%dA", $numberOfLinesToClear), false); |
|
| 132 | - // erase to end of screen |
|
| 133 | - parent::doWrite("\x1b[0J", false); |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - return implode('', array_reverse($erasedContent)); |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - private function getDisplayLength(string $text): int |
|
| 140 | - { |
|
| 141 | - return Helper::width(Helper::removeDecoration($this->getFormatter(), str_replace("\t", ' ', $text))); |
|
| 142 | - } |
|
| 24 | + private $content = []; |
|
| 25 | + private $lines = 0; |
|
| 26 | + private $sections; |
|
| 27 | + private $terminal; |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * @param resource $stream |
|
| 31 | + * @param ConsoleSectionOutput[] $sections |
|
| 32 | + */ |
|
| 33 | + public function __construct($stream, array &$sections, int $verbosity, bool $decorated, OutputFormatterInterface $formatter) |
|
| 34 | + { |
|
| 35 | + parent::__construct($stream, $verbosity, $decorated, $formatter); |
|
| 36 | + array_unshift($sections, $this); |
|
| 37 | + $this->sections = &$sections; |
|
| 38 | + $this->terminal = new Terminal(); |
|
| 39 | + } |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * Clears previous output for this section. |
|
| 43 | + * |
|
| 44 | + * @param int $lines Number of lines to clear. If null, then the entire output of this section is cleared |
|
| 45 | + */ |
|
| 46 | + public function clear(int $lines = null) |
|
| 47 | + { |
|
| 48 | + if (empty($this->content) || !$this->isDecorated()) { |
|
| 49 | + return; |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + if ($lines) { |
|
| 53 | + array_splice($this->content, -($lines * 2)); // Multiply lines by 2 to cater for each new line added between content |
|
| 54 | + } else { |
|
| 55 | + $lines = $this->lines; |
|
| 56 | + $this->content = []; |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + $this->lines -= $lines; |
|
| 60 | + |
|
| 61 | + parent::doWrite($this->popStreamContentUntilCurrentSection($lines), false); |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * Overwrites the previous output with a new message. |
|
| 66 | + * |
|
| 67 | + * @param array|string $message |
|
| 68 | + */ |
|
| 69 | + public function overwrite($message) |
|
| 70 | + { |
|
| 71 | + $this->clear(); |
|
| 72 | + $this->writeln($message); |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + public function getContent(): string |
|
| 76 | + { |
|
| 77 | + return implode('', $this->content); |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * @internal |
|
| 82 | + */ |
|
| 83 | + public function addContent(string $input) |
|
| 84 | + { |
|
| 85 | + foreach (explode(\PHP_EOL, $input) as $lineContent) { |
|
| 86 | + $this->lines += ceil($this->getDisplayLength($lineContent) / $this->terminal->getWidth()) ?: 1; |
|
| 87 | + $this->content[] = $lineContent; |
|
| 88 | + $this->content[] = \PHP_EOL; |
|
| 89 | + } |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + /** |
|
| 93 | + * {@inheritdoc} |
|
| 94 | + */ |
|
| 95 | + protected function doWrite(string $message, bool $newline) |
|
| 96 | + { |
|
| 97 | + if (!$this->isDecorated()) { |
|
| 98 | + parent::doWrite($message, $newline); |
|
| 99 | + |
|
| 100 | + return; |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + $erasedContent = $this->popStreamContentUntilCurrentSection(); |
|
| 104 | + |
|
| 105 | + $this->addContent($message); |
|
| 106 | + |
|
| 107 | + parent::doWrite($message, true); |
|
| 108 | + parent::doWrite($erasedContent, false); |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + /** |
|
| 112 | + * At initial stage, cursor is at the end of stream output. This method makes cursor crawl upwards until it hits |
|
| 113 | + * current section. Then it erases content it crawled through. Optionally, it erases part of current section too. |
|
| 114 | + */ |
|
| 115 | + private function popStreamContentUntilCurrentSection(int $numberOfLinesToClearFromCurrentSection = 0): string |
|
| 116 | + { |
|
| 117 | + $numberOfLinesToClear = $numberOfLinesToClearFromCurrentSection; |
|
| 118 | + $erasedContent = []; |
|
| 119 | + |
|
| 120 | + foreach ($this->sections as $section) { |
|
| 121 | + if ($section === $this) { |
|
| 122 | + break; |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + $numberOfLinesToClear += $section->lines; |
|
| 126 | + $erasedContent[] = $section->getContent(); |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + if ($numberOfLinesToClear > 0) { |
|
| 130 | + // move cursor up n lines |
|
| 131 | + parent::doWrite(sprintf("\x1b[%dA", $numberOfLinesToClear), false); |
|
| 132 | + // erase to end of screen |
|
| 133 | + parent::doWrite("\x1b[0J", false); |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + return implode('', array_reverse($erasedContent)); |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + private function getDisplayLength(string $text): int |
|
| 140 | + { |
|
| 141 | + return Helper::width(Helper::removeDecoration($this->getFormatter(), str_replace("\t", ' ', $text))); |
|
| 142 | + } |
|
| 143 | 143 | } |
@@ -24,105 +24,105 @@ |
||
| 24 | 24 | */ |
| 25 | 25 | class NullOutput implements OutputInterface |
| 26 | 26 | { |
| 27 | - private $formatter; |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * {@inheritdoc} |
|
| 31 | - */ |
|
| 32 | - public function setFormatter(OutputFormatterInterface $formatter) |
|
| 33 | - { |
|
| 34 | - // do nothing |
|
| 35 | - } |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * {@inheritdoc} |
|
| 39 | - */ |
|
| 40 | - public function getFormatter() |
|
| 41 | - { |
|
| 42 | - if ($this->formatter) { |
|
| 43 | - return $this->formatter; |
|
| 44 | - } |
|
| 45 | - // to comply with the interface we must return a OutputFormatterInterface |
|
| 46 | - return $this->formatter = new NullOutputFormatter(); |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * {@inheritdoc} |
|
| 51 | - */ |
|
| 52 | - public function setDecorated(bool $decorated) |
|
| 53 | - { |
|
| 54 | - // do nothing |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * {@inheritdoc} |
|
| 59 | - */ |
|
| 60 | - public function isDecorated() |
|
| 61 | - { |
|
| 62 | - return false; |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * {@inheritdoc} |
|
| 67 | - */ |
|
| 68 | - public function setVerbosity(int $level) |
|
| 69 | - { |
|
| 70 | - // do nothing |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * {@inheritdoc} |
|
| 75 | - */ |
|
| 76 | - public function getVerbosity() |
|
| 77 | - { |
|
| 78 | - return self::VERBOSITY_QUIET; |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * {@inheritdoc} |
|
| 83 | - */ |
|
| 84 | - public function isQuiet() |
|
| 85 | - { |
|
| 86 | - return true; |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - /** |
|
| 90 | - * {@inheritdoc} |
|
| 91 | - */ |
|
| 92 | - public function isVerbose() |
|
| 93 | - { |
|
| 94 | - return false; |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - /** |
|
| 98 | - * {@inheritdoc} |
|
| 99 | - */ |
|
| 100 | - public function isVeryVerbose() |
|
| 101 | - { |
|
| 102 | - return false; |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - /** |
|
| 106 | - * {@inheritdoc} |
|
| 107 | - */ |
|
| 108 | - public function isDebug() |
|
| 109 | - { |
|
| 110 | - return false; |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - /** |
|
| 114 | - * {@inheritdoc} |
|
| 115 | - */ |
|
| 116 | - public function writeln($messages, int $options = self::OUTPUT_NORMAL) |
|
| 117 | - { |
|
| 118 | - // do nothing |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - /** |
|
| 122 | - * {@inheritdoc} |
|
| 123 | - */ |
|
| 124 | - public function write($messages, bool $newline = false, int $options = self::OUTPUT_NORMAL) |
|
| 125 | - { |
|
| 126 | - // do nothing |
|
| 127 | - } |
|
| 27 | + private $formatter; |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * {@inheritdoc} |
|
| 31 | + */ |
|
| 32 | + public function setFormatter(OutputFormatterInterface $formatter) |
|
| 33 | + { |
|
| 34 | + // do nothing |
|
| 35 | + } |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * {@inheritdoc} |
|
| 39 | + */ |
|
| 40 | + public function getFormatter() |
|
| 41 | + { |
|
| 42 | + if ($this->formatter) { |
|
| 43 | + return $this->formatter; |
|
| 44 | + } |
|
| 45 | + // to comply with the interface we must return a OutputFormatterInterface |
|
| 46 | + return $this->formatter = new NullOutputFormatter(); |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * {@inheritdoc} |
|
| 51 | + */ |
|
| 52 | + public function setDecorated(bool $decorated) |
|
| 53 | + { |
|
| 54 | + // do nothing |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * {@inheritdoc} |
|
| 59 | + */ |
|
| 60 | + public function isDecorated() |
|
| 61 | + { |
|
| 62 | + return false; |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * {@inheritdoc} |
|
| 67 | + */ |
|
| 68 | + public function setVerbosity(int $level) |
|
| 69 | + { |
|
| 70 | + // do nothing |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * {@inheritdoc} |
|
| 75 | + */ |
|
| 76 | + public function getVerbosity() |
|
| 77 | + { |
|
| 78 | + return self::VERBOSITY_QUIET; |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * {@inheritdoc} |
|
| 83 | + */ |
|
| 84 | + public function isQuiet() |
|
| 85 | + { |
|
| 86 | + return true; |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + /** |
|
| 90 | + * {@inheritdoc} |
|
| 91 | + */ |
|
| 92 | + public function isVerbose() |
|
| 93 | + { |
|
| 94 | + return false; |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + /** |
|
| 98 | + * {@inheritdoc} |
|
| 99 | + */ |
|
| 100 | + public function isVeryVerbose() |
|
| 101 | + { |
|
| 102 | + return false; |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + /** |
|
| 106 | + * {@inheritdoc} |
|
| 107 | + */ |
|
| 108 | + public function isDebug() |
|
| 109 | + { |
|
| 110 | + return false; |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + /** |
|
| 114 | + * {@inheritdoc} |
|
| 115 | + */ |
|
| 116 | + public function writeln($messages, int $options = self::OUTPUT_NORMAL) |
|
| 117 | + { |
|
| 118 | + // do nothing |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + /** |
|
| 122 | + * {@inheritdoc} |
|
| 123 | + */ |
|
| 124 | + public function write($messages, bool $newline = false, int $options = self::OUTPUT_NORMAL) |
|
| 125 | + { |
|
| 126 | + // do nothing |
|
| 127 | + } |
|
| 128 | 128 | } |
@@ -24,45 +24,45 @@ |
||
| 24 | 24 | */ |
| 25 | 25 | class StringInput extends ArgvInput |
| 26 | 26 | { |
| 27 | - public const REGEX_STRING = '([^\s]+?)(?:\s|(?<!\\\\)"|(?<!\\\\)\'|$)'; |
|
| 28 | - public const REGEX_QUOTED_STRING = '(?:"([^"\\\\]*(?:\\\\.[^"\\\\]*)*)"|\'([^\'\\\\]*(?:\\\\.[^\'\\\\]*)*)\')'; |
|
| 27 | + public const REGEX_STRING = '([^\s]+?)(?:\s|(?<!\\\\)"|(?<!\\\\)\'|$)'; |
|
| 28 | + public const REGEX_QUOTED_STRING = '(?:"([^"\\\\]*(?:\\\\.[^"\\\\]*)*)"|\'([^\'\\\\]*(?:\\\\.[^\'\\\\]*)*)\')'; |
|
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * @param string $input A string representing the parameters from the CLI |
|
| 32 | - */ |
|
| 33 | - public function __construct(string $input) |
|
| 34 | - { |
|
| 35 | - parent::__construct([]); |
|
| 30 | + /** |
|
| 31 | + * @param string $input A string representing the parameters from the CLI |
|
| 32 | + */ |
|
| 33 | + public function __construct(string $input) |
|
| 34 | + { |
|
| 35 | + parent::__construct([]); |
|
| 36 | 36 | |
| 37 | - $this->setTokens($this->tokenize($input)); |
|
| 38 | - } |
|
| 37 | + $this->setTokens($this->tokenize($input)); |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * Tokenizes a string. |
|
| 42 | - * |
|
| 43 | - * @throws InvalidArgumentException When unable to parse input (should never happen) |
|
| 44 | - */ |
|
| 45 | - private function tokenize(string $input): array |
|
| 46 | - { |
|
| 47 | - $tokens = []; |
|
| 48 | - $length = \strlen($input); |
|
| 49 | - $cursor = 0; |
|
| 50 | - while ($cursor < $length) { |
|
| 51 | - if (preg_match('/\s+/A', $input, $match, 0, $cursor)) { |
|
| 52 | - } elseif (preg_match('/([^="\'\s]+?)(=?)('.self::REGEX_QUOTED_STRING.'+)/A', $input, $match, 0, $cursor)) { |
|
| 53 | - $tokens[] = $match[1].$match[2].stripcslashes(str_replace(['"\'', '\'"', '\'\'', '""'], '', substr($match[3], 1, -1))); |
|
| 54 | - } elseif (preg_match('/'.self::REGEX_QUOTED_STRING.'/A', $input, $match, 0, $cursor)) { |
|
| 55 | - $tokens[] = stripcslashes(substr($match[0], 1, -1)); |
|
| 56 | - } elseif (preg_match('/'.self::REGEX_STRING.'/A', $input, $match, 0, $cursor)) { |
|
| 57 | - $tokens[] = stripcslashes($match[1]); |
|
| 58 | - } else { |
|
| 59 | - // should never happen |
|
| 60 | - throw new InvalidArgumentException(sprintf('Unable to parse input near "... %s ...".', substr($input, $cursor, 10))); |
|
| 61 | - } |
|
| 40 | + /** |
|
| 41 | + * Tokenizes a string. |
|
| 42 | + * |
|
| 43 | + * @throws InvalidArgumentException When unable to parse input (should never happen) |
|
| 44 | + */ |
|
| 45 | + private function tokenize(string $input): array |
|
| 46 | + { |
|
| 47 | + $tokens = []; |
|
| 48 | + $length = \strlen($input); |
|
| 49 | + $cursor = 0; |
|
| 50 | + while ($cursor < $length) { |
|
| 51 | + if (preg_match('/\s+/A', $input, $match, 0, $cursor)) { |
|
| 52 | + } elseif (preg_match('/([^="\'\s]+?)(=?)('.self::REGEX_QUOTED_STRING.'+)/A', $input, $match, 0, $cursor)) { |
|
| 53 | + $tokens[] = $match[1].$match[2].stripcslashes(str_replace(['"\'', '\'"', '\'\'', '""'], '', substr($match[3], 1, -1))); |
|
| 54 | + } elseif (preg_match('/'.self::REGEX_QUOTED_STRING.'/A', $input, $match, 0, $cursor)) { |
|
| 55 | + $tokens[] = stripcslashes(substr($match[0], 1, -1)); |
|
| 56 | + } elseif (preg_match('/'.self::REGEX_STRING.'/A', $input, $match, 0, $cursor)) { |
|
| 57 | + $tokens[] = stripcslashes($match[1]); |
|
| 58 | + } else { |
|
| 59 | + // should never happen |
|
| 60 | + throw new InvalidArgumentException(sprintf('Unable to parse input near "... %s ...".', substr($input, $cursor, 10))); |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - $cursor += \strlen($match[0]); |
|
| 64 | - } |
|
| 63 | + $cursor += \strlen($match[0]); |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - return $tokens; |
|
| 67 | - } |
|
| 66 | + return $tokens; |
|
| 67 | + } |
|
| 68 | 68 | } |