1: | <?php |
2: | |
3: | |
4: | |
5: | |
6: | |
7: | |
8: | namespace Aurora\System; |
9: | |
10: | |
11: | |
12: | |
13: | |
14: | |
15: | |
16: | |
17: | class Application |
18: | { |
19: | |
20: | |
21: | |
22: | public const AUTH_TOKEN_KEY = 'AuthToken'; |
23: | |
24: | |
25: | |
26: | |
27: | protected $oModuleManager; |
28: | |
29: | protected static $sBaseUrl = ''; |
30: | |
31: | |
32: | |
33: | |
34: | protected function __construct() |
35: | { |
36: | |
37: | \MailSo\Config::$SystemLogger = Api::SystemLogger(); |
38: | \register_shutdown_function([$this, '__ApplicationShutdown']); |
39: | } |
40: | |
41: | public function __ApplicationShutdown() |
42: | { |
43: | $aStatistic = \MailSo\Base\Loader::Statistic(); |
44: | if (\is_array($aStatistic)) { |
45: | if (isset($aStatistic['php']['memory_get_peak_usage'])) { |
46: | \Aurora\Api::Log('INFO[MEMORY]: Memory peak usage: '.$aStatistic['php']['memory_get_peak_usage']); |
47: | } |
48: | |
49: | if (isset($aStatistic['time'])) { |
50: | \Aurora\Api::Log('INFO[TIME]: Time delta: '.$aStatistic['time']); |
51: | } |
52: | } |
53: | } |
54: | |
55: | |
56: | |
57: | |
58: | public static function NewInstance() |
59: | { |
60: | return new self(); |
61: | } |
62: | |
63: | |
64: | |
65: | |
66: | public static function SingletonInstance() |
67: | { |
68: | static $oInstance = null; |
69: | if (null === $oInstance) { |
70: | $oInstance = self::NewInstance(); |
71: | } |
72: | |
73: | return $oInstance; |
74: | } |
75: | |
76: | public static function DebugMode($bDebug) |
77: | { |
78: | Api::$bDebug = $bDebug; |
79: | } |
80: | |
81: | public static function UseDbLogs() |
82: | { |
83: | Api::$bUseDbLog = true; |
84: | } |
85: | |
86: | public static function Start($sDefaultEntry = 'default') |
87: | { |
88: | if (!defined('AU_APP_START')) { |
89: | define('AU_APP_START', microtime(true)); |
90: | } |
91: | |
92: | try { |
93: | Api::Init(); |
94: | } catch (\Aurora\System\Exceptions\ApiException $oEx) { |
95: | \Aurora\System\Api::LogException($oEx); |
96: | } |
97: | |
98: | self::GetVersion(); |
99: | |
100: | $mResult = self::SingletonInstance()->Route( |
101: | \strtolower( |
102: | Router::getItemByIndex(0, $sDefaultEntry) |
103: | ) |
104: | ); |
105: | if (\MailSo\Base\Http::SingletonInstance()->GetRequest('Format') !== 'Raw') { |
106: | echo $mResult; |
107: | } |
108: | } |
109: | |
110: | |
111: | |
112: | |
113: | public static function GetVersion() |
114: | { |
115: | if (!defined('AU_APP_VERSION')) { |
116: | $sVersion = @\file_get_contents(AU_APP_ROOT_PATH.'VERSION'); |
117: | \define('AU_APP_VERSION', $sVersion); |
118: | } |
119: | return AU_APP_VERSION; |
120: | } |
121: | |
122: | |
123: | |
124: | |
125: | public static function GetPaths() |
126: | { |
127: | return Router::getItems(); |
128: | } |
129: | |
130: | public function Route($sRoute) |
131: | { |
132: | return Api::GetModuleManager()->RunEntry($sRoute); |
133: | } |
134: | |
135: | public static function setBaseUrl($sBaseUrl = '') |
136: | { |
137: | self::$sBaseUrl = $sBaseUrl; |
138: | } |
139: | |
140: | public static function getBaseUrl() |
141: | { |
142: | if (empty(self::$sBaseUrl)) { |
143: | self::$sBaseUrl = \MailSo\Base\Http::SingletonInstance()->GetFullUrl(); |
144: | } |
145: | return self::$sBaseUrl; |
146: | } |
147: | } |
148: | |