Completed
Push — master ( 840fce...5ec725 )
by VEBER
03:13
created

Application::getKernel()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
/**
4
 * This file is part of the CLIFramework package.
5
 *
6
 * (c) Arnaud VEBER <[email protected]>
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 CLIFramework;
13
14
use Symfony\Component\Console\Application as BaseApplication;
15
use Symfony\Component\Console\Input\InputInterface;
16
use Symfony\Component\Console\Output\OutputInterface;
17
use Symfony\Component\Console\Input\InputOption;
18
use Symfony\Component\HttpKernel\KernelInterface;
19
20
/**
21
 * Application.
22
 */
23
class Application extends BaseApplication
24
{
25
    /**
26
     * name
27
     *
28
     * @const NAME
29
     */
30
    const NAME = 'CLIFramework';
31
32
    /**
33
     * version
34
     *
35
     * @const VERSION
36
     */
37
    const VERSION = '0.0.1-dev';
38
39
    /**
40
     * The kernel.
41
     *
42
     * @var \Symfony\Component\HttpKernel\KernelInterface $kernel
43
     */
44
    private $kernel;
45
46
    /**
47
     * The container.
48
     *
49
     * @var \Symfony\Component\DependencyInjection\ContainerInterface $container
50
     */
51
    private $container;
52
53
    /**
54
     * Construct the application.
55
     *
56
     * @param \Symfony\Component\HttpKernel\KernelInterface $kernel
57
     */
58 3
    public function __construct(KernelInterface $kernel)
59
    {
60 3
        $this->kernel = $kernel;
61 3
        $this->container = $kernel->getContainer();
62
63 3
        parent::__construct(self::NAME, self::VERSION);
64
65 3
        if ($this->container->has('event_dispatcher')) {
66
            $this->setDispatcher($this->container->get('event_dispatcher'));
67
        }
68
69 3
        $this->getDefinition()->addOption(
70 3
            new InputOption('--env', '-e', InputOption::VALUE_REQUIRED, 'The Environment name.', 'dev')
71
        );
72 3
        $this->getDefinition()->addOption(
73 3
            new InputOption('--no-debug', null, InputOption::VALUE_NONE, 'Switches off debug mode.')
74
        );
75 3
    }
76
77
    /**
78
     * Get kernel.
79
     *
80
     * @return \Symfony\Component\HttpKernel\KernelInterface
81
     */
82 1
    public function getKernel()
83
    {
84 1
        return $this->kernel;
85
    }
86
87
    /**
88
     * Runs the current application.
89
     *
90
     * @param \Symfony\Component\Console\Input\InputInterface $input
91
     * @param \Symfony\Component\Console\Output\OutputInterface $output
92
     *
93
     * @return int
94
     */
95 1
    public function doRun(InputInterface $input, OutputInterface $output)
96
    {
97 1
        $this->registerCommands();
98
99 1
        return parent::doRun($input, $output);
100
    }
101
102
    /**
103
     * Register commands into the application
104
     *
105
     * @return void
106
     */
107 1
    protected function registerCommands()
108
    {
109 1
        if ($this->container->hasParameter('app.command.ids')) {
110 1
            foreach ($this->container->getParameter('app.command.ids') as $id) {
111
                $this->add($this->container->get($id));
112
            }
113
        }
114 1
    }
115
}
116