|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App; |
|
4
|
|
|
|
|
5
|
|
|
use Core\Application; |
|
6
|
|
|
use App\Auth\AuthManager; |
|
7
|
|
|
use Zend\Diactoros\ServerRequestFactory; |
|
8
|
|
|
use Zend\Diactoros\Uri; |
|
9
|
|
|
|
|
10
|
|
|
class Bootstrap |
|
11
|
|
|
{ |
|
12
|
|
|
|
|
13
|
|
|
public static function boot() |
|
14
|
|
|
{ |
|
15
|
|
|
self::setUpApplication(); |
|
16
|
|
|
self::setUpAuthService(); |
|
17
|
|
|
|
|
18
|
|
|
Application::getInstance()->dispatch(self::getServerRequest()); |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
public static function setUpApplication() |
|
22
|
|
|
{ |
|
23
|
|
|
$application = Application::getInstance(); |
|
24
|
|
|
|
|
25
|
|
|
$application->setSiteConfig(self::getSiteConfig()); |
|
26
|
|
|
$application->setErrorReporterConfig(self::getErrorReporterConfig()); |
|
27
|
|
|
$application->setDbConfig(self::getDbConfig()); |
|
28
|
|
|
$application->setViewEngineConfig(self::getViewEngineConfig()); |
|
29
|
|
|
|
|
30
|
|
|
$application->setDisplayError(self::getSiteConfig()['displayErrors']); |
|
31
|
|
|
$application->registerErrorReporters(); |
|
32
|
|
|
|
|
33
|
|
|
$application->setEventListener(self::getEventListener()); |
|
34
|
|
|
$application->registerEventListener(); |
|
35
|
|
|
|
|
36
|
|
|
$application->setRouterConfig(self::getRouterConfig()); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public static function setUpAuthService() |
|
40
|
|
|
{ |
|
41
|
|
|
$auth = AuthManager::getInstance(); |
|
42
|
|
|
|
|
43
|
|
|
$auth->setConfig(self::getAuthConfig()); |
|
44
|
|
|
$auth->setAccountManagerConfig(self::getAccountManagerConfig()); |
|
45
|
|
|
$auth->setLoginManagerConfig(self::getLoginManagerConfig()); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public static function getServerRequest() |
|
49
|
|
|
{ |
|
50
|
|
|
$request = ServerRequestFactory::fromGlobals(); |
|
51
|
|
|
|
|
52
|
|
|
$stripedUri = new Uri( |
|
53
|
|
|
self::stripUrlPrefix($request->getUri()->getPath()) |
|
54
|
|
|
); |
|
55
|
|
|
|
|
56
|
|
|
return $request->withUri($stripedUri); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
public static function stripUrlPrefix($url) |
|
60
|
|
|
{ |
|
61
|
|
|
if (substr($url, 0, strlen(self::getSiteConfig()['url'])) === self::getSiteConfig()['url']) { |
|
62
|
|
|
return '/' . substr($url, strlen(self::getSiteConfig()['url'])) ?: '/'; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
return $url; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
public static function getSiteConfig() |
|
69
|
|
|
{ |
|
70
|
|
|
return require '../config/site.php'; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
public static function getErrorReporterConfig() |
|
74
|
|
|
{ |
|
75
|
|
|
return require '../config/errorReporter.php'; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
public static function getDbConfig() |
|
79
|
|
|
{ |
|
80
|
|
|
return require '../config/db.php'; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
public static function getViewEngineConfig() |
|
84
|
|
|
{ |
|
85
|
|
|
return require '../config/viewEngine.php'; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
public static function getEventListener() |
|
89
|
|
|
{ |
|
90
|
|
|
return require '../config/event.php'; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
public static function getRouterConfig() |
|
94
|
|
|
{ |
|
95
|
|
|
return require '../config/router.php'; |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
|
|
99
|
|
|
public static function getAuthConfig() |
|
100
|
|
|
{ |
|
101
|
|
|
return require 'Auth/config/config.php'; |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
public static function getAccountManagerConfig() |
|
105
|
|
|
{ |
|
106
|
|
|
return require 'Auth/config/accountManager.php'; |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
public static function getLoginManagerConfig() |
|
110
|
|
|
{ |
|
111
|
|
|
return require 'Auth/config/loginManager.php'; |
|
112
|
|
|
} |
|
113
|
|
|
} |
|
114
|
|
|
|