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