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

ConsoleBootstrapper::boot()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 3
cp 0
crap 2
rs 10
c 0
b 0
f 0
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