4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Console\CommandLoader;
14 use Symfony\Component\Console\Exception\CommandNotFoundException;
17 * A simple command loader using factories to instantiate commands lazily.
19 * @author Maxime Steinhausser <maxime.steinhausser@gmail.com>
21 class FactoryCommandLoader implements CommandLoaderInterface
26 * @param callable[] $factories Indexed by command names
28 public function __construct(array $factories)
30 $this->factories = $factories;
36 public function has($name)
38 return isset($this->factories[$name]);
44 public function get($name)
46 if (!isset($this->factories[$name])) {
47 throw new CommandNotFoundException(sprintf('Command "%s" does not exist.', $name));
50 $factory = $this->factories[$name];
58 public function getNames()
60 return array_keys($this->factories);