Completed
Push — master ( 04e760...b100d6 )
by Park Jong-Hun
19:01
created

Application::setDisplayError()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 4
Bugs 0 Features 0
Metric Value
c 4
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
namespace Core;
4
5
use Doctrine\ORM\Tools\Setup;
6
use Doctrine\ORM\EntityManager;
7
use JBZoo\Event\EventManager;
8
use Core\ControllerDispatcher\Dispatcher;
9
use Psr\Http\Message\ServerRequestInterface;
10
11
class Application
12
{
13
    private $routerConfig = [];
14
    private $siteConfig = [];
15
    private $viewEngineConfig = [];
16
17
    private $viewResolvers = [];
18
19
    /**
20
     * Singleton: private constructor
21
     */
22
    private function __construct()
23
    {
24
    }
25
26
    /**
27
     * @return Application
28
     */
29
    public static function getInstance()
30
    {
31
        static $instance = null;
32
33
        if ($instance === null) {
34
            $instance = new self();
35
        }
36
37
        return $instance;
38
    }
39
40
    public function setSiteConfig(array $siteConfig)
41
    {
42
        $this->siteConfig = $siteConfig;
43
    }
44
45
    public function setViewEngineConfig(array $viewEngineConfig)
46
    {
47
        $this->viewEngineConfig = $viewEngineConfig;
48
    }
49
50
    public function setViewResolver(array $viewResolvers)
51
    {
52
        $this->viewResolvers = $viewResolvers;
53
    }
54
55
    public function setRouterConfig(array $routerConfig)
56
    {
57
        $this->routerConfig = $routerConfig;
58
    }
59
60
61
    public function dispatch(ServerRequestInterface $request)
62
    {
63
        $dispatcher = new Dispatcher();
64
65
        $dispatcher->setRequest($request);
66
        $dispatcher->setRouterConfig($this->routerConfig);
67
        $dispatcher->setViewEngineConfig($this->viewEngineConfig);
68
        $dispatcher->setViewResolver($this->viewResolvers);
69
70
        $dispatcher->dispatch();
71
    }
72
73
74
    /**
75
     * Return url path with site url
76
     * @param  string $url sub url
77
     * @return string
78
     */
79
    public function url($url = '')
80
    {
81
        $url = $url === '/' ? '' : $url;
82
        return $this->siteConfig['url'] . $url;
83
    }
84
85
86
    /**
87
     * @return EventManager
88
     */
89
    public function getEventManager()
90
    {
91
        static $instance = null;
92
93
        if ($instance === null) {
94
            $instance = new EventManager();
95
        }
96
97
        return $instance;
98
    }
99
}
100