* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Console\Command; use Symfony\Component\Console\Application; use Symfony\Component\Console\Completion\CompletionInput; use Symfony\Component\Console\Completion\CompletionSuggestions; use Symfony\Component\Console\Completion\Suggestion; use Symfony\Component\Console\Helper\HelperInterface; use Symfony\Component\Console\Helper\HelperSet; use Symfony\Component\Console\Input\InputDefinition; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; /** * @author Nicolas Grekas
*/
final class LazyCommand extends Command
{
/**
* @var \Closure|\Symfony\Component\Console\Command\Command
*/
private $command;
/**
* @var bool|null
*/
private $isEnabled;
/**
* @param string $name
* @param mixed[] $aliases
* @param string $description
* @param bool $isHidden
* @param \Closure $commandFactory
* @param bool|null $isEnabled
*/
public function __construct($name, $aliases, $description, $isHidden, $commandFactory, $isEnabled = true)
{
$this->setName($name)
->setAliases($aliases)
->setHidden($isHidden)
->setDescription($description);
$this->command = $commandFactory;
$this->isEnabled = $isEnabled;
}
public function ignoreValidationErrors()
{
$this->getCommand()->ignoreValidationErrors();
}
/**
* @param \Symfony\Component\Console\Application|null $application
*/
public function setApplication($application = null)
{
if (1 > \func_num_args()) {
trigger_deprecation('symfony/console', '6.2', 'Calling "%s()" without any arguments is deprecated, pass null explicitly instead.', __METHOD__);
}
if ($this->command instanceof parent) {
$this->command->setApplication($application);
}
parent::setApplication($application);
}
/**
* @param \Symfony\Component\Console\Helper\HelperSet $helperSet
*/
public function setHelperSet($helperSet)
{
if ($this->command instanceof parent) {
$this->command->setHelperSet($helperSet);
}
parent::setHelperSet($helperSet);
}
public function isEnabled()
{
return $this->isEnabled ?? $this->getCommand()->isEnabled();
}
/**
* @param \Symfony\Component\Console\Input\InputInterface $input
* @param \Symfony\Component\Console\Output\OutputInterface $output
*/
public function run($input, $output)
{
return $this->getCommand()->run($input, $output);
}
/**
* @param \Symfony\Component\Console\Completion\CompletionInput $input
* @param \Symfony\Component\Console\Completion\CompletionSuggestions $suggestions
*/
public function complete($input, $suggestions)
{
$this->getCommand()->complete($input, $suggestions);
}
/**
* @return $this
* @param callable $code
*/
public function setCode($code)
{
$this->getCommand()->setCode($code);
return $this;
}
/**
* @internal
* @param bool $mergeArgs
*/
public function mergeApplicationDefinition($mergeArgs = true)
{
$this->getCommand()->mergeApplicationDefinition($mergeArgs);
}
/**
* @param mixed[]|\Symfony\Component\Console\Input\InputDefinition $definition
* @return $this
*/
public function setDefinition($definition)
{
$this->getCommand()->setDefinition($definition);
return $this;
}
public function getDefinition()
{
return $this->getCommand()->getDefinition();
}
public function getNativeDefinition()
{
return $this->getCommand()->getNativeDefinition();
}
/**
* @param array|\Closure(CompletionInput,CompletionSuggestions):list