-
Notifications
You must be signed in to change notification settings - Fork 3
/
Application.php
147 lines (126 loc) · 3.52 KB
/
Application.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
<?php
/**
* This code is licensed under AGPLv3 license or Afterlogic Software License
* if commercial version of the product was purchased.
* For full statements of the licenses see LICENSE-AFTERLOGIC and LICENSE-AGPL3 files.
*/
namespace Aurora\System;
/**
* @license https://www.gnu.org/licenses/agpl-3.0.html AGPL-3.0
* @license https://afterlogic.com/products/common-licensing Afterlogic Software License
* @copyright Copyright (c) 2019, Afterlogic Corp.
*
* @category Core
*/
class Application
{
/**
* @type string
*/
public const AUTH_TOKEN_KEY = 'AuthToken';
/**
* @var \Aurora\System\Module\Manager
*/
protected $oModuleManager;
protected static $sBaseUrl = '';
/**
* @return void
*/
protected function __construct()
{
// \MailSo\Config::$FixIconvByMbstring = false;
\MailSo\Config::$SystemLogger = Api::SystemLogger();
\register_shutdown_function([$this, '__ApplicationShutdown']);
}
public function __ApplicationShutdown()
{
$aStatistic = \MailSo\Base\Loader::Statistic();
if (\is_array($aStatistic)) {
if (isset($aStatistic['php']['memory_get_peak_usage'])) {
\Aurora\Api::Log('INFO[MEMORY]: Memory peak usage: ' . $aStatistic['php']['memory_get_peak_usage']);
}
if (isset($aStatistic['time'])) {
\Aurora\Api::Log('INFO[TIME]: Time delta: ' . $aStatistic['time']);
}
}
}
/**
* @return \Aurora\System\Application
*/
public static function NewInstance()
{
return new self();
}
/**
* @return \Aurora\System\Application
*/
public static function SingletonInstance()
{
static $oInstance = null;
if (null === $oInstance) {
$oInstance = self::NewInstance();
}
return $oInstance;
}
public static function DebugMode($bDebug)
{
Api::$bDebug = $bDebug;
}
public static function UseDbLogs()
{
Api::$bUseDbLog = true;
}
public static function Start($sDefaultEntry = 'default')
{
if (!defined('AU_APP_START')) {
define('AU_APP_START', microtime(true));
}
try {
Api::Init();
} catch (\Aurora\System\Exceptions\ApiException $oEx) {
\Aurora\System\Api::LogException($oEx);
}
self::GetVersion();
$mResult = self::SingletonInstance()->Route(
\strtolower(
Router::getItemByIndex(0, $sDefaultEntry)
)
);
if (\MailSo\Base\Http::SingletonInstance()->GetRequest('Format') !== 'Raw') {
echo $mResult;
}
}
/**
* @return string
*/
public static function GetVersion()
{
if (!defined('AU_APP_VERSION')) {
$sVersion = @\file_get_contents(AU_APP_ROOT_PATH . 'VERSION');
\define('AU_APP_VERSION', $sVersion);
}
return AU_APP_VERSION;
}
/**
* @return array
*/
public static function GetPaths()
{
return Router::getItems();
}
public function Route($sRoute)
{
return Api::GetModuleManager()->RunEntry($sRoute);
}
public static function setBaseUrl($sBaseUrl = '')
{
self::$sBaseUrl = $sBaseUrl;
}
public static function getBaseUrl()
{
if (empty(self::$sBaseUrl)) {
self::$sBaseUrl = \MailSo\Base\Http::SingletonInstance()->GetFullUrl();
}
return self::$sBaseUrl;
}
}