Completed
Push — 7.5 ( 70cc97...2f9a1f )
by Łukasz
21:35
created

Application   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
dl 0
loc 32
rs 10
c 0
b 0
f 0
wmc 2
lcom 1
cbo 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A doRun() 0 13 1
1
<?php
2
3
/**
4
 * File containing the Application class.
5
 *
6
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
7
 * @license For full copyright and license information view LICENSE file distributed with this source code.
8
 */
9
namespace eZ\Bundle\EzPublishCoreBundle\Console;
10
11
use eZ\Publish\Core\MVC\Symfony\Event\ConsoleInitEvent;
12
use eZ\Publish\Core\MVC\Symfony\MVCEvents;
13
use Symfony\Bundle\FrameworkBundle\Console\Application as BaseApplication;
14
use Symfony\Component\Console\Input\InputInterface;
15
use Symfony\Component\Console\Input\InputOption;
16
use Symfony\Component\Console\Output\OutputInterface;
17
use Symfony\Component\HttpKernel\KernelInterface;
18
19
/**
20
 * eZ Publish console application.
21
 * Adds options specific to an eZ Publish environment, such as the siteaccess to use.
22
 */
23
class Application extends BaseApplication
24
{
25
    /**
26
     * @see doRun
27
     *
28
     * @var \Symfony\Component\HttpKernel\KernelInterface
29
     */
30
    private $kernel;
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
31
32
    public function __construct(KernelInterface $kernel)
33
    {
34
        $this->kernel = $kernel;
35
        parent::__construct($kernel);
36
        $this->getDefinition()->addOption(
37
            new InputOption('--siteaccess', null, InputOption::VALUE_OPTIONAL, 'SiteAccess to use for operations. If not provided, default siteaccess will be used')
38
        );
39
    }
40
41
    public function doRun(InputInterface $input, OutputInterface $output)
42
    {
43
        // boot() will be re-executed by parent, but kernel only boots once regardlessly
44
        $this->kernel->boot();
45
46
        // @todo Contribute a console.init event to Symfony4 in order to rather use that in v3 to drop doRun() overload
47
        $this->kernel->getContainer()->get('event_dispatcher')->dispatch(
48
            MVCEvents::CONSOLE_INIT,
49
            new ConsoleInitEvent($input, $output)
50
        );
51
52
        return parent::doRun($input, $output);
53
    }
54
}
55