Passed
Push — master ( 3a6f6e...572404 )
by Alexander
03:10 queued 01:20
created

ConsoleApplicationRunner::withConfig()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 5
ccs 0
cts 4
cp 0
crap 2
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Yii\Runner\Console;
6
7
use ErrorException;
8
use Exception;
9
use Psr\Container\ContainerExceptionInterface;
10
use Psr\Container\NotFoundExceptionInterface;
11
use Throwable;
12
use Yiisoft\Definitions\Exception\CircularReferenceException;
13
use Yiisoft\Definitions\Exception\InvalidConfigException;
14
use Yiisoft\Definitions\Exception\NotInstantiableException;
15
use Yiisoft\Di\NotFoundException;
16
use Yiisoft\Yii\Console\Application;
17
use Yiisoft\Yii\Console\ExitCode;
18
use Yiisoft\Yii\Console\Output\ConsoleBufferedOutput;
19
use Yiisoft\Yii\Runner\ApplicationRunner;
20
21
/**
22
 * `ConsoleApplicationRunner` runs the Yii console application.
23
 */
24
final class ConsoleApplicationRunner extends ApplicationRunner
25
{
26
    /**
27
     * @param string $rootPath The absolute path to the project root.
28
     * @param bool $debug Whether the debug mode is enabled.
29
     * @param string|null $environment The environment name.
30
     */
31
    public function __construct(string $rootPath, bool $debug, ?string $environment)
32
    {
33
        parent::__construct($rootPath, $debug, $environment);
34
        $this->bootstrapGroup = 'bootstrap-console';
35
        $this->eventsGroup = 'events-console';
36
    }
37
38
    /**
39
     * {@inheritDoc}
40
     *
41
     * @throws CircularReferenceException|ErrorException|Exception|InvalidConfigException
42
     * @throws ContainerExceptionInterface|NotFoundException|NotFoundExceptionInterface|NotInstantiableException
43
     */
44
    public function run(): void
45
    {
46
        $config = $this->getConfig();
47
        $container = $this->getContainer($config, 'console');
48
49
        $this->runBootstrap($config, $container);
50
        $this->checkEvents($config, $container);
51
52
        /** @var Application */
53
        $application = $container->get(Application::class);
54
        $exitCode = ExitCode::UNSPECIFIED_ERROR;
55
56
        try {
57
            $application->start();
58
            $exitCode = $application->run(null, new ConsoleBufferedOutput());
59
        } catch (Throwable $throwable) {
60
            $application->renderThrowable($throwable, new ConsoleBufferedOutput());
61
        } finally {
62
            $application->shutdown($exitCode);
63
            exit($exitCode);
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
64
        }
65
    }
66
}
67