PluginProbe
Depicter — Popup & Slider Builder / trunk
Depicter — Popup & Slider Builder vtrunk
4.8.1 trunk 1.0.0 1.1.0 1.1.2 1.1.4 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.3.5 1.3.8 1.5.0 1.5.1 1.5.2 1.5.5 1.6.0 1.6.1 1.6.2 1.7.0 All 76 releases
depicter / vendor / symfony / console / CommandLoader / ContainerCommandLoader.php

ContainerCommandLoader.php in Depicter — Popup & Slider Builder trunk, at vendor/symfony/console/CommandLoader/ContainerCommandLoader.php

64 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.com>
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\CommandLoader;
13
14 use Psr\Container\ContainerInterface;
15 use Symfony\Component\Console\Exception\CommandNotFoundException;
16
17 /**
18 * Loads commands from a PSR-11 container.
19 *
20 * @author Robin Chalas <robin.chalas@gmail.com>
21 */
22 class ContainerCommandLoader implements CommandLoaderInterface
23 {
24 private $container;
25 private $commandMap;
26
27 /**
28 * @param array $commandMap An array with command names as keys and service ids as values
29 */
30 public function __construct(ContainerInterface $container, array $commandMap)
31 {
32 $this->container = $container;
33 $this->commandMap = $commandMap;
34 }
35
36 /**
37 * {@inheritdoc}
38 */
39 public function get(string $name)
40 {
41 if (!$this->has($name)) {
42 throw new CommandNotFoundException(sprintf('Command "%s" does not exist.', $name));
43 }
44
45 return $this->container->get($this->commandMap[$name]);
46 }
47
48 /**
49 * {@inheritdoc}
50 */
51 public function has(string $name)
52 {
53 return isset($this->commandMap[$name]) && $this->container->has($this->commandMap[$name]);
54 }
55
56 /**
57 * {@inheritdoc}
58 */
59 public function getNames()
60 {
61 return array_keys($this->commandMap);
62 }
63 }
64