Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
namespace Illuminate\Console;
4
 
5
use Psr\Container\ContainerInterface;
6
use Symfony\Component\Console\Command\Command;
7
use Symfony\Component\Console\CommandLoader\CommandLoaderInterface;
8
use Symfony\Component\Console\Exception\CommandNotFoundException;
9
 
10
class ContainerCommandLoader implements CommandLoaderInterface
11
{
12
    /**
13
     * The container instance.
14
     *
15
     * @var \Psr\Container\ContainerInterface
16
     */
17
    protected $container;
18
 
19
    /**
20
     * A map of command names to classes.
21
     *
22
     * @var array
23
     */
24
    protected $commandMap;
25
 
26
    /**
27
     * Create a new command loader instance.
28
     *
29
     * @param  \Psr\Container\ContainerInterface  $container
30
     * @param  array  $commandMap
31
     * @return void
32
     */
33
    public function __construct(ContainerInterface $container, array $commandMap)
34
    {
35
        $this->container = $container;
36
        $this->commandMap = $commandMap;
37
    }
38
 
39
    /**
40
     * Resolve a command from the container.
41
     *
42
     * @param  string  $name
43
     * @return \Symfony\Component\Console\Command\Command
44
     *
45
     * @throws \Symfony\Component\Console\Exception\CommandNotFoundException
46
     */
47
    public function get(string $name): Command
48
    {
49
        if (! $this->has($name)) {
50
            throw new CommandNotFoundException(sprintf('Command "%s" does not exist.', $name));
51
        }
52
 
53
        return $this->container->get($this->commandMap[$name]);
54
    }
55
 
56
    /**
57
     * Determines if a command exists.
58
     *
59
     * @param  string  $name
60
     * @return bool
61
     */
62
    public function has(string $name): bool
63
    {
64
        return $name && isset($this->commandMap[$name]);
65
    }
66
 
67
    /**
68
     * Get the command names.
69
     *
70
     * @return string[]
71
     */
72
    public function getNames(): array
73
    {
74
        return array_keys($this->commandMap);
75
    }
76
}