[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/libraries/vendor/symfony/console/Command/ -> LazyCommand.php (source)

   1  <?php
   2  
   3  /*
   4   * This file is part of the Symfony package.
   5   *
   6   * (c) Fabien Potencier <[email protected]>
   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 Symfony\Component\Console\Command;
  13  
  14  use Symfony\Component\Console\Application;
  15  use Symfony\Component\Console\Completion\CompletionInput;
  16  use Symfony\Component\Console\Completion\CompletionSuggestions;
  17  use Symfony\Component\Console\Helper\HelperSet;
  18  use Symfony\Component\Console\Input\InputDefinition;
  19  use Symfony\Component\Console\Input\InputInterface;
  20  use Symfony\Component\Console\Output\OutputInterface;
  21  
  22  /**
  23   * @author Nicolas Grekas <[email protected]>
  24   */
  25  final class LazyCommand extends Command
  26  {
  27      private $command;
  28      private $isEnabled;
  29  
  30      public function __construct(string $name, array $aliases, string $description, bool $isHidden, \Closure $commandFactory, ?bool $isEnabled = true)
  31      {
  32          $this->setName($name)
  33              ->setAliases($aliases)
  34              ->setHidden($isHidden)
  35              ->setDescription($description);
  36  
  37          $this->command = $commandFactory;
  38          $this->isEnabled = $isEnabled;
  39      }
  40  
  41      public function ignoreValidationErrors(): void
  42      {
  43          $this->getCommand()->ignoreValidationErrors();
  44      }
  45  
  46      public function setApplication(Application $application = null): void
  47      {
  48          if ($this->command instanceof parent) {
  49              $this->command->setApplication($application);
  50          }
  51  
  52          parent::setApplication($application);
  53      }
  54  
  55      public function setHelperSet(HelperSet $helperSet): void
  56      {
  57          if ($this->command instanceof parent) {
  58              $this->command->setHelperSet($helperSet);
  59          }
  60  
  61          parent::setHelperSet($helperSet);
  62      }
  63  
  64      public function isEnabled(): bool
  65      {
  66          return $this->isEnabled ?? $this->getCommand()->isEnabled();
  67      }
  68  
  69      public function run(InputInterface $input, OutputInterface $output): int
  70      {
  71          return $this->getCommand()->run($input, $output);
  72      }
  73  
  74      public function complete(CompletionInput $input, CompletionSuggestions $suggestions): void
  75      {
  76          $this->getCommand()->complete($input, $suggestions);
  77      }
  78  
  79      /**
  80       * @return $this
  81       */
  82      public function setCode(callable $code): self
  83      {
  84          $this->getCommand()->setCode($code);
  85  
  86          return $this;
  87      }
  88  
  89      /**
  90       * @internal
  91       */
  92      public function mergeApplicationDefinition(bool $mergeArgs = true): void
  93      {
  94          $this->getCommand()->mergeApplicationDefinition($mergeArgs);
  95      }
  96  
  97      /**
  98       * @return $this
  99       */
 100      public function setDefinition($definition): self
 101      {
 102          $this->getCommand()->setDefinition($definition);
 103  
 104          return $this;
 105      }
 106  
 107      public function getDefinition(): InputDefinition
 108      {
 109          return $this->getCommand()->getDefinition();
 110      }
 111  
 112      public function getNativeDefinition(): InputDefinition
 113      {
 114          return $this->getCommand()->getNativeDefinition();
 115      }
 116  
 117      /**
 118       * @return $this
 119       */
 120      public function addArgument(string $name, int $mode = null, string $description = '', $default = null): self
 121      {
 122          $this->getCommand()->addArgument($name, $mode, $description, $default);
 123  
 124          return $this;
 125      }
 126  
 127      /**
 128       * @return $this
 129       */
 130      public function addOption(string $name, $shortcut = null, int $mode = null, string $description = '', $default = null): self
 131      {
 132          $this->getCommand()->addOption($name, $shortcut, $mode, $description, $default);
 133  
 134          return $this;
 135      }
 136  
 137      /**
 138       * @return $this
 139       */
 140      public function setProcessTitle(string $title): self
 141      {
 142          $this->getCommand()->setProcessTitle($title);
 143  
 144          return $this;
 145      }
 146  
 147      /**
 148       * @return $this
 149       */
 150      public function setHelp(string $help): self
 151      {
 152          $this->getCommand()->setHelp($help);
 153  
 154          return $this;
 155      }
 156  
 157      public function getHelp(): string
 158      {
 159          return $this->getCommand()->getHelp();
 160      }
 161  
 162      public function getProcessedHelp(): string
 163      {
 164          return $this->getCommand()->getProcessedHelp();
 165      }
 166  
 167      public function getSynopsis(bool $short = false): string
 168      {
 169          return $this->getCommand()->getSynopsis($short);
 170      }
 171  
 172      /**
 173       * @return $this
 174       */
 175      public function addUsage(string $usage): self
 176      {
 177          $this->getCommand()->addUsage($usage);
 178  
 179          return $this;
 180      }
 181  
 182      public function getUsages(): array
 183      {
 184          return $this->getCommand()->getUsages();
 185      }
 186  
 187      /**
 188       * @return mixed
 189       */
 190      public function getHelper(string $name)
 191      {
 192          return $this->getCommand()->getHelper($name);
 193      }
 194  
 195      public function getCommand(): parent
 196      {
 197          if (!$this->command instanceof \Closure) {
 198              return $this->command;
 199          }
 200  
 201          $command = $this->command = ($this->command)();
 202          $command->setApplication($this->getApplication());
 203  
 204          if (null !== $this->getHelperSet()) {
 205              $command->setHelperSet($this->getHelperSet());
 206          }
 207  
 208          $command->setName($this->getName())
 209              ->setAliases($this->getAliases())
 210              ->setHidden($this->isHidden())
 211              ->setDescription($this->getDescription());
 212  
 213          // Will throw if the command is not correctly initialized.
 214          $command->getDefinition();
 215  
 216          return $command;
 217      }
 218  }


Generated: Wed Sep 7 05:41:13 2022 Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer