|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace AbterPhp\Admin\Config; |
|
6
|
|
|
|
|
7
|
|
|
use AbterPhp\Admin\Constant\Env; |
|
8
|
|
|
use AbterPhp\Framework\Config\Routes as FrameworkRoutes; |
|
9
|
|
|
use AbterPhp\Framework\Exception\Config as ConfigException; |
|
10
|
|
|
use Opulence\Environments\Environment; |
|
11
|
|
|
|
|
12
|
|
|
class Routes extends FrameworkRoutes |
|
13
|
|
|
{ |
|
14
|
|
|
public const DASHBOARD_PATH = '/dashboard'; |
|
15
|
|
|
public const PROFILE_PATH = '/profile'; |
|
16
|
|
|
|
|
17
|
|
|
/** @var string|null */ |
|
18
|
|
|
protected static $loginPath; |
|
19
|
|
|
|
|
20
|
|
|
/** @var string|null */ |
|
21
|
|
|
protected static $logoutPath; |
|
22
|
|
|
|
|
23
|
|
|
/** @var string|null */ |
|
24
|
|
|
protected static $adminBasePath; |
|
25
|
|
|
|
|
26
|
|
|
/** @var string|null */ |
|
27
|
|
|
protected static $apiBasePath; |
|
28
|
|
|
|
|
29
|
|
|
/** @var string|null */ |
|
30
|
|
|
protected static $uploadUrl; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @param string $loginPath |
|
34
|
|
|
*/ |
|
35
|
|
|
public static function setLoginPath(string $loginPath): void |
|
36
|
|
|
{ |
|
37
|
|
|
static::$loginPath = $loginPath; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @return string |
|
42
|
|
|
*/ |
|
43
|
|
|
public static function getLoginPath(): string |
|
44
|
|
|
{ |
|
45
|
|
|
if (null !== static::$loginPath) { |
|
46
|
|
|
return static::$loginPath; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
$loginPath = Environment::getVar(Env::ADMIN_LOGIN_PATH); |
|
50
|
|
|
if (null === $loginPath) { |
|
51
|
|
|
throw new ConfigException(__CLASS__, [Env::ADMIN_LOGIN_PATH]); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
static::$loginPath = (string)$loginPath; |
|
55
|
|
|
|
|
56
|
|
|
return static::$loginPath; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* @param string $logoutPath |
|
61
|
|
|
*/ |
|
62
|
|
|
public static function setLogoutPath(string $logoutPath): void |
|
63
|
|
|
{ |
|
64
|
|
|
static::$logoutPath = $logoutPath; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* @return string |
|
69
|
|
|
*/ |
|
70
|
|
|
public static function getLogoutPath(): string |
|
71
|
|
|
{ |
|
72
|
|
|
if (null !== static::$logoutPath) { |
|
73
|
|
|
return static::$logoutPath; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
$logoutPath = Environment::getVar(Env::ADMIN_LOGOUT_PATH); |
|
77
|
|
|
if (null === $logoutPath) { |
|
78
|
|
|
throw new ConfigException(__CLASS__, [Env::ADMIN_LOGOUT_PATH]); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
static::$logoutPath = (string)$logoutPath; |
|
82
|
|
|
|
|
83
|
|
|
return static::$logoutPath; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* @param string $adminBasePath |
|
88
|
|
|
*/ |
|
89
|
|
|
public static function setAdminBasePath(string $adminBasePath): void |
|
90
|
|
|
{ |
|
91
|
|
|
static::$adminBasePath = $adminBasePath; |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* @return string |
|
96
|
|
|
*/ |
|
97
|
|
|
public static function getAdminBasePath(): string |
|
98
|
|
|
{ |
|
99
|
|
|
if (null !== static::$adminBasePath) { |
|
100
|
|
|
return static::$adminBasePath; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
$adminBasePath = Environment::getVar(Env::ADMIN_BASE_PATH); |
|
104
|
|
|
if (null === $adminBasePath) { |
|
105
|
|
|
throw new ConfigException(__CLASS__, [Env::ADMIN_BASE_PATH]); |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
static::$adminBasePath = (string)$adminBasePath; |
|
109
|
|
|
|
|
110
|
|
|
return static::$adminBasePath; |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* @param string $apiBasePath |
|
115
|
|
|
*/ |
|
116
|
|
|
public static function setApiBasePath(string $apiBasePath): void |
|
117
|
|
|
{ |
|
118
|
|
|
static::$apiBasePath = $apiBasePath; |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
/** |
|
122
|
|
|
* @return string |
|
123
|
|
|
*/ |
|
124
|
|
|
public static function getApiBasePath(): string |
|
125
|
|
|
{ |
|
126
|
|
|
if (null !== static::$apiBasePath) { |
|
127
|
|
|
return static::$apiBasePath; |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
$apiBasePath = Environment::getVar(Env::API_BASE_PATH); |
|
131
|
|
|
if (null === $apiBasePath) { |
|
132
|
|
|
throw new ConfigException(__CLASS__, [Env::API_BASE_PATH]); |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
static::$apiBasePath = (string)$apiBasePath; |
|
136
|
|
|
|
|
137
|
|
|
return static::$apiBasePath; |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
/** |
|
141
|
|
|
* @return string |
|
142
|
|
|
*/ |
|
143
|
|
|
public static function getLoginFailurePath(): string |
|
144
|
|
|
{ |
|
145
|
|
|
return static::getLoginPath(); |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
/** |
|
149
|
|
|
* @return string |
|
150
|
|
|
*/ |
|
151
|
|
|
public static function getLoginSuccessPath(): string |
|
152
|
|
|
{ |
|
153
|
|
|
return static::getAdminBasePath() . static::DASHBOARD_PATH; |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
/** |
|
157
|
|
|
* @return string |
|
158
|
|
|
*/ |
|
159
|
|
|
public static function getProfilePath(): string |
|
160
|
|
|
{ |
|
161
|
|
|
return static::getAdminBasePath() . static::PROFILE_PATH; |
|
162
|
|
|
} |
|
163
|
|
|
|
|
164
|
|
|
/** |
|
165
|
|
|
* @param string $uploadUrl |
|
166
|
|
|
*/ |
|
167
|
|
|
public static function setUploadUrl(string $uploadUrl): void |
|
168
|
|
|
{ |
|
169
|
|
|
static::$uploadUrl = $uploadUrl; |
|
170
|
|
|
} |
|
171
|
|
|
|
|
172
|
|
|
/** |
|
173
|
|
|
* @return string |
|
174
|
|
|
*/ |
|
175
|
|
|
public static function getUploadUrl(): string |
|
176
|
|
|
{ |
|
177
|
|
|
if (null !== static::$uploadUrl) { |
|
178
|
|
|
return static::$uploadUrl; |
|
179
|
|
|
} |
|
180
|
|
|
|
|
181
|
|
|
$uploadUrl = sprintf( |
|
182
|
|
|
'%s%s%s', |
|
183
|
|
|
rtrim(static::getMediaUrl(), DIRECTORY_SEPARATOR), |
|
184
|
|
|
DIRECTORY_SEPARATOR, |
|
185
|
|
|
ltrim(Environment::getVar(Env::EDITOR_BASE_PATH), DIRECTORY_SEPARATOR) |
|
186
|
|
|
); |
|
187
|
|
|
|
|
188
|
|
|
static::$uploadUrl = (string)$uploadUrl; |
|
189
|
|
|
|
|
190
|
|
|
return static::$uploadUrl; |
|
191
|
|
|
} |
|
192
|
|
|
} |
|
193
|
|
|
|