1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace Plaisio\Kernel; |
5
|
|
|
|
6
|
|
|
use Plaisio\Dirs\Dirs; |
7
|
|
|
use Plaisio\Authority\Authority; |
8
|
|
|
use Plaisio\Babel\Babel; |
9
|
|
|
use Plaisio\BlobStore\BlobStore; |
10
|
|
|
use Plaisio\CanonicalHostnameResolver\CanonicalHostnameResolver; |
11
|
|
|
use Plaisio\Cgi\Cgi; |
12
|
|
|
use Plaisio\CompanyResolver\CompanyResolver; |
13
|
|
|
use Plaisio\ConfigVault\ConfigVault; |
14
|
|
|
use Plaisio\ErrorLogger\ErrorLogger; |
15
|
|
|
use Plaisio\Event\EventDispatcher; |
16
|
|
|
use Plaisio\ExceptionHandler\ExceptionHandler; |
17
|
|
|
use Plaisio\LanguageResolver\LanguageResolver; |
18
|
|
|
use Plaisio\Lock\EntityLock; |
19
|
|
|
use Plaisio\Lock\NamedLock; |
20
|
|
|
use Plaisio\Login\LoginHandler; |
21
|
|
|
use Plaisio\Mail\MailMessage; |
22
|
|
|
use Plaisio\Obfuscator\Obfuscator; |
23
|
|
|
use Plaisio\Obfuscator\ObfuscatorFactory; |
24
|
|
|
use Plaisio\Request\Request; |
25
|
|
|
use Plaisio\RequestHandler\RequestHandler; |
26
|
|
|
use Plaisio\RequestLogger\RequestLogger; |
27
|
|
|
use Plaisio\RequestParameterResolver\RequestParameterResolver; |
28
|
|
|
use Plaisio\Session\Session; |
29
|
|
|
use Plaisio\WebAssets\WebAssets; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* The heart of the PhpPlaisio system. |
33
|
|
|
* |
34
|
|
|
* Nub: |
35
|
|
|
* noun. (ˈnʌb) The choicest or most essential or most vital part of some idea or experience. |
36
|
|
|
*/ |
37
|
|
|
abstract class Nub |
38
|
|
|
{ |
39
|
|
|
//-------------------------------------------------------------------------------------------------------------------- |
40
|
|
|
/** |
41
|
|
|
* The data layer generated by PhpStratum. |
42
|
|
|
* |
43
|
|
|
* @var Object |
44
|
|
|
*/ |
45
|
|
|
public static $DL; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* A reference to the singleton instance of this class. |
49
|
|
|
* |
50
|
|
|
* @var Nub |
51
|
|
|
*/ |
52
|
|
|
public static $nub; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* The helper object for web assets. |
56
|
|
|
* |
57
|
|
|
* @var WebAssets |
58
|
|
|
*/ |
59
|
|
|
public static $assets; |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* The helper object for authorization. |
63
|
|
|
* |
64
|
|
|
* @var Authority |
65
|
|
|
*/ |
66
|
|
|
public static $authority; |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* The Babel object for retrieving linguistic entities. |
70
|
|
|
* |
71
|
|
|
* @var Babel |
72
|
|
|
*/ |
73
|
|
|
public static $babel; |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* The helper object for deriving the canonical hostname. |
77
|
|
|
* |
78
|
|
|
* @var CanonicalHostnameResolver |
79
|
|
|
*/ |
80
|
|
|
public static $canonicalHostnameResolver; |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* The helper object for get Cgi variables. |
84
|
|
|
* |
85
|
|
|
* @var Cgi |
86
|
|
|
*/ |
87
|
|
|
public static $cgi; |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* The helper object for deriving the company. |
91
|
|
|
* |
92
|
|
|
* @var CompanyResolver |
93
|
|
|
*/ |
94
|
|
|
public static $companyResolver; |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Helper object for getting directory names. |
98
|
|
|
* |
99
|
|
|
* @var Dirs |
100
|
|
|
*/ |
101
|
|
|
public static $dirs; |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* The helper object for resolving the code of the language in which the response must be drafted. |
105
|
|
|
* |
106
|
|
|
* @var LanguageResolver |
107
|
|
|
*/ |
108
|
|
|
public static $languageResolver; |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* The helper object for providing information about the HTTP request. |
112
|
|
|
* |
113
|
|
|
* @var Request |
114
|
|
|
*/ |
115
|
|
|
public static $request; |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* The helper object for handling the HTTP page request. |
119
|
|
|
* |
120
|
|
|
* @var RequestHandler |
121
|
|
|
*/ |
122
|
|
|
public static $requestHandler; |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* The helper object for logging HTTP page requests. |
126
|
|
|
* |
127
|
|
|
* @var RequestLogger |
128
|
|
|
*/ |
129
|
|
|
public static $requestLogger; |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* The helper object for resolving the CGI parameters from a clean URL. |
133
|
|
|
* |
134
|
|
|
* @var RequestParameterResolver |
135
|
|
|
*/ |
136
|
|
|
public static $requestParameterResolver; |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* The helper object for session management. |
140
|
|
|
* |
141
|
|
|
* @var Session |
142
|
|
|
*/ |
143
|
|
|
public static $session; |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* The start time of serving the page request. |
147
|
|
|
* |
148
|
|
|
* @var float |
149
|
|
|
*/ |
150
|
|
|
public static $time0; |
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* The factory for creating Obfuscators. |
154
|
|
|
* |
155
|
|
|
* @var ObfuscatorFactory |
156
|
|
|
*/ |
157
|
|
|
protected static $obfuscatorFactory; |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* Information about the requested page. |
161
|
|
|
* |
162
|
|
|
* {@deprecated} |
163
|
|
|
* |
164
|
|
|
* @var array |
165
|
|
|
*/ |
166
|
|
|
public $pageInfo; |
167
|
|
|
|
168
|
|
|
//-------------------------------------------------------------------------------------------------------------------- |
169
|
|
|
/** |
170
|
|
|
* Object constructor. |
171
|
|
|
*/ |
172
|
|
|
protected function __construct() |
173
|
|
|
{ |
174
|
|
|
self::$nub = $this; |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
//-------------------------------------------------------------------------------------------------------------------- |
178
|
|
|
/** |
179
|
|
|
* De-obfuscates an obfuscated database ID. |
180
|
|
|
* |
181
|
|
|
* @param string|null $code The obfuscated database ID. |
182
|
|
|
* @param string $alias An alias for the column holding the IDs. |
183
|
|
|
* |
184
|
|
|
* @return int|null |
185
|
|
|
*/ |
186
|
|
|
public static function deObfuscate(?string $code, string $alias): ?int |
187
|
|
|
{ |
188
|
|
|
return self::$obfuscatorFactory->decode($code, $alias); |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
//-------------------------------------------------------------------------------------------------------------------- |
192
|
|
|
/** |
193
|
|
|
* Returns an Obfuscator for obfuscating and de-obfuscating database IDs. |
194
|
|
|
* |
195
|
|
|
* @param string $alias An alias for the column holding the IDs. |
196
|
|
|
* |
197
|
|
|
* @return Obfuscator |
198
|
|
|
*/ |
199
|
|
|
public static function getObfuscator(string $alias): Obfuscator |
200
|
|
|
{ |
201
|
|
|
return self::$obfuscatorFactory->getObfuscator($alias); |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
//-------------------------------------------------------------------------------------------------------------------- |
205
|
|
|
/** |
206
|
|
|
* Obfuscates a database ID. |
207
|
|
|
* |
208
|
|
|
* @param int|null $id The database ID. |
209
|
|
|
* @param string $alias An alias for the column holding the IDs. |
210
|
|
|
* |
211
|
|
|
* @return string |
212
|
|
|
*/ |
213
|
|
|
public static function obfuscate(?int $id, string $alias): ?string |
214
|
|
|
{ |
215
|
|
|
return self::$obfuscatorFactory->encode($id, $alias); |
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
//-------------------------------------------------------------------------------------------------------------------- |
219
|
|
|
/** |
220
|
|
|
* Acquires a lock on a database entity and returns the object holding the lock. |
221
|
|
|
* |
222
|
|
|
* @param int $nameId The ID of the name of the entity lock. |
223
|
|
|
* @param int $entityId The ID of the entity. |
224
|
|
|
* |
225
|
|
|
* @return EntityLock |
226
|
|
|
*/ |
227
|
|
|
public function createEntityLock(int $nameId, int $entityId): EntityLock |
228
|
|
|
{ |
229
|
|
|
unset($nameId); |
230
|
|
|
unset($entityId); |
231
|
|
|
|
232
|
|
|
throw new \LogicException('Not implemented'); |
233
|
|
|
} |
234
|
|
|
|
235
|
|
|
//-------------------------------------------------------------------------------------------------------------------- |
236
|
|
|
/** |
237
|
|
|
* Returns a login handler for logging in a user agent. |
238
|
|
|
* |
239
|
|
|
* @return LoginHandler |
240
|
|
|
*/ |
241
|
|
|
public function createLoginHandler(): LoginHandler |
242
|
|
|
{ |
243
|
|
|
throw new \LogicException('Not implemented'); |
244
|
|
|
} |
245
|
|
|
|
246
|
|
|
//-------------------------------------------------------------------------------------------------------------------- |
247
|
|
|
/** |
248
|
|
|
* Creates an empty mail message. |
249
|
|
|
* |
250
|
|
|
* @return MailMessage |
251
|
|
|
*/ |
252
|
|
|
public function createMailMessage(): MailMessage |
253
|
|
|
{ |
254
|
|
|
throw new \LogicException('Not implemented'); |
255
|
|
|
} |
256
|
|
|
|
257
|
|
|
//-------------------------------------------------------------------------------------------------------------------- |
258
|
|
|
/** |
259
|
|
|
* Acquires a named lock and returns the object holding the lock. |
260
|
|
|
* |
261
|
|
|
* @param int $id The ID of the named lock. |
262
|
|
|
* |
263
|
|
|
* @return NamedLock |
264
|
|
|
*/ |
265
|
|
|
public function createNamedLock(int $id): NamedLock |
266
|
|
|
{ |
267
|
|
|
unset($id); |
268
|
|
|
|
269
|
|
|
throw new \LogicException('Not implemented'); |
270
|
|
|
} |
271
|
|
|
|
272
|
|
|
//-------------------------------------------------------------------------------------------------------------------- |
273
|
|
|
/** |
274
|
|
|
* Returns the BLOB Store object. |
275
|
|
|
* |
276
|
|
|
* @return BlobStore |
277
|
|
|
*/ |
278
|
|
|
public function getBlobStore(): BlobStore |
279
|
|
|
{ |
280
|
|
|
throw new \LogicException('Not implemented'); |
281
|
|
|
} |
282
|
|
|
|
283
|
|
|
//-------------------------------------------------------------------------------------------------------------------- |
284
|
|
|
/** |
285
|
|
|
* Returns the configuration vault for storing and retrieving sensitive configuration data safely. |
286
|
|
|
* |
287
|
|
|
* @return ConfigVault |
288
|
|
|
*/ |
289
|
|
|
public function getConfigVault(): ConfigVault |
290
|
|
|
{ |
291
|
|
|
throw new \LogicException('Not implemented'); |
292
|
|
|
} |
293
|
|
|
|
294
|
|
|
//-------------------------------------------------------------------------------------------------------------------- |
295
|
|
|
/** |
296
|
|
|
* Returns the error logger. |
297
|
|
|
* |
298
|
|
|
* @return ErrorLogger |
299
|
|
|
*/ |
300
|
|
|
public function getErrorLogger(): ErrorLogger |
301
|
|
|
{ |
302
|
|
|
throw new \LogicException('Not implemented'); |
303
|
|
|
} |
304
|
|
|
|
305
|
|
|
//-------------------------------------------------------------------------------------------------------------------- |
306
|
|
|
/** |
307
|
|
|
* Returns the event dispatcher. |
308
|
|
|
* |
309
|
|
|
* @return EventDispatcher |
310
|
|
|
*/ |
311
|
|
|
public function getEventDispatcher(): EventDispatcher |
312
|
|
|
{ |
313
|
|
|
throw new \LogicException('Not implemented'); |
314
|
|
|
} |
315
|
|
|
|
316
|
|
|
//-------------------------------------------------------------------------------------------------------------------- |
317
|
|
|
/** |
318
|
|
|
* Returns the exception handler. |
319
|
|
|
* |
320
|
|
|
* @return ExceptionHandler |
321
|
|
|
*/ |
322
|
|
|
public function getExceptionHandler(): ExceptionHandler |
323
|
|
|
{ |
324
|
|
|
throw new \LogicException('Not implemented'); |
325
|
|
|
} |
326
|
|
|
|
327
|
|
|
//-------------------------------------------------------------------------------------------------------------------- |
328
|
|
|
/** |
329
|
|
|
* Returns the ID of the index page. |
330
|
|
|
* |
331
|
|
|
* @return int |
332
|
|
|
*/ |
333
|
|
|
public function getIndexPagId(): int |
334
|
|
|
{ |
335
|
|
|
throw new \LogicException('Not implemented'); |
336
|
|
|
} |
337
|
|
|
|
338
|
|
|
//-------------------------------------------------------------------------------------------------------------------- |
339
|
|
|
/** |
340
|
|
|
* Returns the URL of the login page. |
341
|
|
|
* |
342
|
|
|
* @param string|null $redirect After a successful login the user agent must be redirected to this URL. |
343
|
|
|
* |
344
|
|
|
* @return string |
345
|
|
|
*/ |
346
|
|
|
public function getLoginUrl(?string $redirect = null): string |
347
|
|
|
{ |
348
|
|
|
unset($redirect); |
349
|
|
|
|
350
|
|
|
throw new \LogicException('Not implemented'); |
351
|
|
|
} |
352
|
|
|
|
353
|
|
|
//-------------------------------------------------------------------------------------------------------------------- |
354
|
|
|
/** |
355
|
|
|
* Returns ID of the menu item associated with the requested page. |
356
|
|
|
* |
357
|
|
|
* {@deprecated} |
358
|
|
|
* |
359
|
|
|
* @return int|null |
360
|
|
|
*/ |
361
|
|
|
public function getMnuId(): ?int |
362
|
|
|
{ |
363
|
|
|
return $this->pageInfo['mnu_id']; |
|
|
|
|
364
|
|
|
} |
365
|
|
|
|
366
|
|
|
//-------------------------------------------------------------------------------------------------------------------- |
367
|
|
|
/** |
368
|
|
|
* Returns the ID of the "original" page. |
369
|
|
|
* |
370
|
|
|
* {@deprecated} |
371
|
|
|
* |
372
|
|
|
* @return int|null |
373
|
|
|
*/ |
374
|
|
|
public function getPagIdOrg(): ?int |
375
|
|
|
{ |
376
|
|
|
return $this->pageInfo['pag_id_org']; |
|
|
|
|
377
|
|
|
} |
378
|
|
|
|
379
|
|
|
//-------------------------------------------------------------------------------------------------------------------- |
380
|
|
|
/** |
381
|
|
|
* Returns page group title. |
382
|
|
|
* |
383
|
|
|
* {@deprecated} |
384
|
|
|
* |
385
|
|
|
* @return string|null |
386
|
|
|
*/ |
387
|
|
|
public function getPageGroupTitle(): ?string |
388
|
|
|
{ |
389
|
|
|
return $this->pageInfo['ptb_title']; |
|
|
|
|
390
|
|
|
} |
391
|
|
|
|
392
|
|
|
//-------------------------------------------------------------------------------------------------------------------- |
393
|
|
|
/** |
394
|
|
|
* Returns page group title. |
395
|
|
|
* |
396
|
|
|
* {@deprecated} |
397
|
|
|
* |
398
|
|
|
* @return int|null |
399
|
|
|
*/ |
400
|
|
|
public function getPtbId(): ?int |
401
|
|
|
{ |
402
|
|
|
return $this->pageInfo['ptb_id']; |
|
|
|
|
403
|
|
|
} |
404
|
|
|
|
405
|
|
|
//-------------------------------------------------------------------------------------------------------------------- |
406
|
|
|
/** |
407
|
|
|
* Handles the actual page request including authorization and security checking, transaction handling, |
408
|
|
|
* request logging, and exception handling. |
409
|
|
|
*/ |
410
|
|
|
public function handlePageRequest(): void |
411
|
|
|
{ |
412
|
|
|
self::$requestHandler->handleRequest(); |
413
|
|
|
} |
414
|
|
|
|
415
|
|
|
//-------------------------------------------------------------------------------------------------------------------- |
416
|
|
|
} |
417
|
|
|
|
418
|
|
|
//---------------------------------------------------------------------------------------------------------------------- |
419
|
|
|
|