comparison vendor/symfony/console/CommandLoader/ContainerCommandLoader.php @ 14:1fec387a4317

Update Drupal core to 8.5.2 via Composer
author Chris Cannam
date Mon, 23 Apr 2018 09:46:53 +0100
parents
children
comparison
equal deleted inserted replaced
13:5fb285c0d0e3 14:1fec387a4317
1 <?php
2
3 namespace Symfony\Component\Console\CommandLoader;
4
5 use Psr\Container\ContainerInterface;
6 use Symfony\Component\Console\Exception\CommandNotFoundException;
7
8 /**
9 * Loads commands from a PSR-11 container.
10 *
11 * @author Robin Chalas <robin.chalas@gmail.com>
12 */
13 class ContainerCommandLoader implements CommandLoaderInterface
14 {
15 private $container;
16 private $commandMap;
17
18 /**
19 * @param ContainerInterface $container A container from which to load command services
20 * @param array $commandMap An array with command names as keys and service ids as values
21 */
22 public function __construct(ContainerInterface $container, array $commandMap)
23 {
24 $this->container = $container;
25 $this->commandMap = $commandMap;
26 }
27
28 /**
29 * {@inheritdoc}
30 */
31 public function get($name)
32 {
33 if (!$this->has($name)) {
34 throw new CommandNotFoundException(sprintf('Command "%s" does not exist.', $name));
35 }
36
37 return $this->container->get($this->commandMap[$name]);
38 }
39
40 /**
41 * {@inheritdoc}
42 */
43 public function has($name)
44 {
45 return isset($this->commandMap[$name]) && $this->container->has($this->commandMap[$name]);
46 }
47
48 /**
49 * {@inheritdoc}
50 */
51 public function getNames()
52 {
53 return array_keys($this->commandMap);
54 }
55 }