Command.php
1 year ago
CompleteCommand.php
1 year ago
DumpCompletionCommand.php
2 years ago
HelpCommand.php
2 years ago
LazyCommand.php
1 year ago
ListCommand.php
2 years ago
LockableTrait.php
1 year ago
SignalableCommandInterface.php
2 years ago
LazyCommand.php
173 lines
| 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 | namespace Matomo\Dependencies\Symfony\Component\Console\Command; |
| 12 | |
| 13 | use Matomo\Dependencies\Symfony\Component\Console\Application; |
| 14 | use Matomo\Dependencies\Symfony\Component\Console\Completion\CompletionInput; |
| 15 | use Matomo\Dependencies\Symfony\Component\Console\Completion\CompletionSuggestions; |
| 16 | use Matomo\Dependencies\Symfony\Component\Console\Helper\HelperSet; |
| 17 | use Matomo\Dependencies\Symfony\Component\Console\Input\InputDefinition; |
| 18 | use Matomo\Dependencies\Symfony\Component\Console\Input\InputInterface; |
| 19 | use Matomo\Dependencies\Symfony\Component\Console\Output\OutputInterface; |
| 20 | /** |
| 21 | * @author Nicolas Grekas <p@tchwork.com> |
| 22 | */ |
| 23 | final class LazyCommand extends Command |
| 24 | { |
| 25 | private $command; |
| 26 | private $isEnabled; |
| 27 | public function __construct(string $name, array $aliases, string $description, bool $isHidden, \Closure $commandFactory, ?bool $isEnabled = \true) |
| 28 | { |
| 29 | $this->setName($name)->setAliases($aliases)->setHidden($isHidden)->setDescription($description); |
| 30 | $this->command = $commandFactory; |
| 31 | $this->isEnabled = $isEnabled; |
| 32 | } |
| 33 | public function ignoreValidationErrors() : void |
| 34 | { |
| 35 | $this->getCommand()->ignoreValidationErrors(); |
| 36 | } |
| 37 | public function setApplication(?Application $application = null) : void |
| 38 | { |
| 39 | if ($this->command instanceof parent) { |
| 40 | $this->command->setApplication($application); |
| 41 | } |
| 42 | parent::setApplication($application); |
| 43 | } |
| 44 | public function setHelperSet(HelperSet $helperSet) : void |
| 45 | { |
| 46 | if ($this->command instanceof parent) { |
| 47 | $this->command->setHelperSet($helperSet); |
| 48 | } |
| 49 | parent::setHelperSet($helperSet); |
| 50 | } |
| 51 | public function isEnabled() : bool |
| 52 | { |
| 53 | return $this->isEnabled ?? $this->getCommand()->isEnabled(); |
| 54 | } |
| 55 | public function run(InputInterface $input, OutputInterface $output) : int |
| 56 | { |
| 57 | return $this->getCommand()->run($input, $output); |
| 58 | } |
| 59 | public function complete(CompletionInput $input, CompletionSuggestions $suggestions) : void |
| 60 | { |
| 61 | $this->getCommand()->complete($input, $suggestions); |
| 62 | } |
| 63 | /** |
| 64 | * @return $this |
| 65 | */ |
| 66 | public function setCode(callable $code) : self |
| 67 | { |
| 68 | $this->getCommand()->setCode($code); |
| 69 | return $this; |
| 70 | } |
| 71 | /** |
| 72 | * @internal |
| 73 | */ |
| 74 | public function mergeApplicationDefinition(bool $mergeArgs = \true) : void |
| 75 | { |
| 76 | $this->getCommand()->mergeApplicationDefinition($mergeArgs); |
| 77 | } |
| 78 | /** |
| 79 | * @return $this |
| 80 | */ |
| 81 | public function setDefinition($definition) : self |
| 82 | { |
| 83 | $this->getCommand()->setDefinition($definition); |
| 84 | return $this; |
| 85 | } |
| 86 | public function getDefinition() : InputDefinition |
| 87 | { |
| 88 | return $this->getCommand()->getDefinition(); |
| 89 | } |
| 90 | public function getNativeDefinition() : InputDefinition |
| 91 | { |
| 92 | return $this->getCommand()->getNativeDefinition(); |
| 93 | } |
| 94 | /** |
| 95 | * @return $this |
| 96 | */ |
| 97 | public function addArgument(string $name, ?int $mode = null, string $description = '', $default = null) : self |
| 98 | { |
| 99 | $this->getCommand()->addArgument($name, $mode, $description, $default); |
| 100 | return $this; |
| 101 | } |
| 102 | /** |
| 103 | * @return $this |
| 104 | */ |
| 105 | public function addOption(string $name, $shortcut = null, ?int $mode = null, string $description = '', $default = null) : self |
| 106 | { |
| 107 | $this->getCommand()->addOption($name, $shortcut, $mode, $description, $default); |
| 108 | return $this; |
| 109 | } |
| 110 | /** |
| 111 | * @return $this |
| 112 | */ |
| 113 | public function setProcessTitle(string $title) : self |
| 114 | { |
| 115 | $this->getCommand()->setProcessTitle($title); |
| 116 | return $this; |
| 117 | } |
| 118 | /** |
| 119 | * @return $this |
| 120 | */ |
| 121 | public function setHelp(string $help) : self |
| 122 | { |
| 123 | $this->getCommand()->setHelp($help); |
| 124 | return $this; |
| 125 | } |
| 126 | public function getHelp() : string |
| 127 | { |
| 128 | return $this->getCommand()->getHelp(); |
| 129 | } |
| 130 | public function getProcessedHelp() : string |
| 131 | { |
| 132 | return $this->getCommand()->getProcessedHelp(); |
| 133 | } |
| 134 | public function getSynopsis(bool $short = \false) : string |
| 135 | { |
| 136 | return $this->getCommand()->getSynopsis($short); |
| 137 | } |
| 138 | /** |
| 139 | * @return $this |
| 140 | */ |
| 141 | public function addUsage(string $usage) : self |
| 142 | { |
| 143 | $this->getCommand()->addUsage($usage); |
| 144 | return $this; |
| 145 | } |
| 146 | public function getUsages() : array |
| 147 | { |
| 148 | return $this->getCommand()->getUsages(); |
| 149 | } |
| 150 | /** |
| 151 | * @return mixed |
| 152 | */ |
| 153 | public function getHelper(string $name) |
| 154 | { |
| 155 | return $this->getCommand()->getHelper($name); |
| 156 | } |
| 157 | public function getCommand() : parent |
| 158 | { |
| 159 | if (!$this->command instanceof \Closure) { |
| 160 | return $this->command; |
| 161 | } |
| 162 | $command = $this->command = ($this->command)(); |
| 163 | $command->setApplication($this->getApplication()); |
| 164 | if (null !== $this->getHelperSet()) { |
| 165 | $command->setHelperSet($this->getHelperSet()); |
| 166 | } |
| 167 | $command->setName($this->getName())->setAliases($this->getAliases())->setHidden($this->isHidden())->setDescription($this->getDescription()); |
| 168 | // Will throw if the command is not correctly initialized. |
| 169 | $command->getDefinition(); |
| 170 | return $command; |
| 171 | } |
| 172 | } |
| 173 |