Bootstrap::locateExceptionHandlerTemplate()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 2
nc 1
nop 0
1
<?php
2
declare(strict_types=1);
3
4
namespace TogglJira;
5
6
use Zend\Console\Console;
7
use Zend\Mvc\Application as MvcApplication;
8
use ZF\Console\Application as ConsoleApplication;
9
use ZF\Console\Dispatcher;
10
11
class Bootstrap
12
{
13
    /**
14
     * @var MvcApplication
15
     */
16
    private $mvcApp;
17
18
    /**
19
     * Bootstrap constructor.
20
     * @param array $configuration
21
     */
22
    public function __construct(array $configuration)
23
    {
24
        $this->mvcApp = MvcApplication::init($configuration);
25
    }
26
27
    /**
28
     * @return ConsoleApplication
29
     * @throws \Zend\Console\Exception\RuntimeException
30
     * @throws \Zend\Console\Exception\InvalidArgumentException
31
     */
32
    public function setupConsoleApp(): ConsoleApplication
33
    {
34
        $services = $this->mvcApp->getServiceManager();
35
36
        $version = $services->get('Config')['version'];
37
38
        $application = new ConsoleApplication(
39
            'TogglJira',
40
            $version,
41
            $this->readRoutesFromMvc(),
42
            Console::getInstance(),
43
            new Dispatcher($services)
44
        );
45
46
        $application->getExceptionHandler()->setMessageTemplate(
47
            file_get_contents($this->locateExceptionHandlerTemplate())
48
        );
49
50
        return $application;
51
    }
52
53
    /**
54
     * @return array
55
     */
56
    private function readRoutesFromMvc(): array
57
    {
58
        return $this->mvcApp->getConfig()['console']['routes'] ?: [];
59
    }
60
61
    /**
62
     * @return string
63
     */
64
    private function locateExceptionHandlerTemplate(): string
65
    {
66
        return $this->mvcApp->getConfig()['exception_handler']['template'] ?: '';
67
    }
68
}
69