Skip to content

[Console] Added support for lazy-loaded commands (with Command resolver) #13989

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions src/Symfony/Component/Console/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

namespace Symfony\Component\Console;

use Symfony\Component\Console\Command\CommandConfiguration;
use Symfony\Component\Console\Command\Resolver\CommandResolverInterface;
use Symfony\Component\Console\Descriptor\TextDescriptor;
use Symfony\Component\Console\Descriptor\XmlDescriptor;
use Symfony\Component\Console\Helper\DebugFormatterHelper;
Expand Down Expand Up @@ -60,6 +62,7 @@
class Application
{
private $commands = array();
private $commandResolver;
private $wantHelps = false;
private $runningCommand;
private $name;
Expand Down Expand Up @@ -93,11 +96,22 @@ public function __construct($name = 'UNKNOWN', $version = 'UNKNOWN')
}
}

/**
* @param EventDispatcherInterface $dispatcher
*/
public function setDispatcher(EventDispatcherInterface $dispatcher)
{
$this->dispatcher = $dispatcher;
}

/**
* @param CommandResolverInterface $commandResolver
*/
public function setCommandResolver(CommandResolverInterface $commandResolver)
{
$this->commandResolver = $commandResolver;
}

/**
* Runs the current application.
*
Expand Down Expand Up @@ -404,6 +418,21 @@ public function add(Command $command)
return $command;
}

/**
* Adds command configuration.
*
* @param CommandConfiguration $configuration
* @return Command
*/
public function addCommandConfiguration(CommandConfiguration $configuration)
{
if (null === $this->commandResolver) {
throw new \RuntimeException('You have to specify command resolver in order to register separate command configuration');
}

return $this->add(Command::registerLazyLoaded($configuration, $this->commandResolver));
}

/**
* Returns a registered command by name or alias.
*
Expand Down
Loading