Completed
Push — master ( 97318c...d75021 )
by Changwan
03:35
created

ConsoleBootstrapper   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 45
ccs 0
cts 26
cp 0
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 2

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A providers() 0 4 1
A boot() 0 3 1
A execute() 0 16 2
1
<?php
2
namespace Wandu\Foundation\Bootstrapper;
3
4
use Symfony\Component\Console\Application as SymfonyApplication;
5
use Wandu\Console\Dispatcher;
6
use Wandu\DI\ContainerInterface;
7
use Wandu\Foundation\Application;
8
use Wandu\Foundation\Contracts\Bootstrapper;
9
10
class ConsoleBootstrapper implements Bootstrapper
11
{
12
    /** @var array */
13
    protected $commands;
14
15
    public function __construct(array $commands = [])
16
    {
17
        $this->commands = $commands;
18
    }
19
20
    /**
21
     * {@inheritdoc}
22
     */
23
    public function providers(): array
24
    {
25
        return [];
26
    }
27
28
    /**
29
     * {@inheritdoc}
30
     */
31
    public function boot(ContainerInterface $app)
32
    {
33
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38
    public function execute(ContainerInterface $app): int
39
    {
40
        $dispatcher = new Dispatcher(
41
            $app,
42
            $symfonyApplication = new SymfonyApplication(
43
                Application::NAME,
44
                Application::VERSION
45
            )
46
        );
47
48
        foreach ($this->commands as $name => $command) {
49
            $dispatcher->add($name, $command);
50
        }
51
        $dispatcher->execute();
52
        return $symfonyApplication->run();
53
    }
54
}
55