1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace Plaisio\Kernel; |
5
|
|
|
|
6
|
|
|
use Plaisio\Authority\Authority; |
7
|
|
|
use Plaisio\Babel\Babel; |
8
|
|
|
use Plaisio\BlobStore\BlobStore; |
9
|
|
|
use Plaisio\CanonicalHostnameResolver\CanonicalHostnameResolver; |
10
|
|
|
use Plaisio\Cgi\Cgi; |
11
|
|
|
use Plaisio\CompanyResolver\CompanyResolver; |
12
|
|
|
use Plaisio\ConfigVault\ConfigVault; |
13
|
|
|
use Plaisio\Dirs\Dirs; |
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 and parent class for all kernels. |
33
|
|
|
* |
34
|
|
|
* Nub: |
35
|
|
|
* noun. (ˈnʌb) The choicest or most essential or most vital part of some idea or experience. |
36
|
|
|
* |
37
|
|
|
* @property-read WebAssets $assets The helper object for web assets. |
38
|
|
|
* @property-read Authority $authority The helper object for authorization. |
39
|
|
|
* @property-read Babel $babel The helper object for retrieving linguistic |
40
|
|
|
* entities. |
41
|
|
|
* @property-read BlobStore $blobStore The the BLOB Store object. |
42
|
|
|
* @property-read CanonicalHostnameResolver $canonicalHostnameResolver The helper object for deriving the |
43
|
|
|
* canonical hostname. |
44
|
|
|
* @property-read Cgi $cgi The helper object for Cgi variables. |
45
|
|
|
* @property-read CompanyResolver $companyResolver The helper object for deriving the company. |
46
|
|
|
* @property-read ConfigVault $configVault The configuration vault for storing and |
47
|
|
|
* retrieving sensitive configuration data safely. |
48
|
|
|
* @property-read Dirs $dirs Helper object for getting directory names. |
49
|
|
|
* @property-read Object $DL The data layer generated by PhpStratum. |
50
|
|
|
* @property-read ErrorLogger $errorLogger The error logger. |
51
|
|
|
* @property-read EventDispatcher $eventDispatcher The event dispatcher. |
52
|
|
|
* @property-read ExceptionHandler $exceptionHandler The exception handler. |
53
|
|
|
* @property-read LanguageResolver $languageResolver The helper object for resolving the code of |
54
|
|
|
* the language in which the response must be drafted. |
55
|
|
|
* @property-read LoginHandler $loginHandler The login handler for logging in a user agent. |
56
|
|
|
* @property-read ObfuscatorFactory $obfuscatorFactory The factory for creating Obfuscators. |
57
|
|
|
* @property-read Request $request The helper object for providing information |
58
|
|
|
* about the HTTP request. |
59
|
|
|
* @property-read RequestHandler $requestHandler The helper object for handling the HTTP page |
60
|
|
|
* request. |
61
|
|
|
* @property-read RequestLogger $requestLogger The helper object for logging HTTP page requests. |
62
|
|
|
* @property-read RequestParameterResolver $requestParameterResolver The helper object for resolving the CGI |
63
|
|
|
* parameters from a clean URL. |
64
|
|
|
* @property-read Session $session The helper object for session management. |
65
|
|
|
*/ |
66
|
|
|
abstract class Nub |
67
|
|
|
{ |
68
|
|
|
//-------------------------------------------------------------------------------------------------------------------- |
69
|
|
|
/** |
70
|
|
|
* A reference to the singleton instance of this class. |
71
|
|
|
* |
72
|
|
|
* @var Nub |
73
|
|
|
*/ |
74
|
|
|
public static $nub; |
75
|
|
|
|
76
|
|
|
//-------------------------------------------------------------------------------------------------------------------- |
77
|
|
|
/** |
78
|
|
|
* Object constructor. |
79
|
|
|
*/ |
80
|
|
|
protected function __construct() |
81
|
|
|
{ |
82
|
|
|
self::$nub = $this; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
//-------------------------------------------------------------------------------------------------------------------- |
86
|
|
|
/** |
87
|
|
|
* Returns the value of an object property. |
88
|
|
|
* |
89
|
|
|
* Do not call this method directly as it is a PHP magic method that |
90
|
|
|
* will be implicitly called when executing `$value = $object->property;`. |
91
|
|
|
* |
92
|
|
|
* @param string $property The name of the property. |
93
|
|
|
* |
94
|
|
|
* @return mixed The value of the property. |
95
|
|
|
* |
96
|
|
|
* @throws \LogicException If the property is not defined. |
97
|
|
|
*/ |
98
|
|
|
public function __get(string $property) |
99
|
|
|
{ |
100
|
|
|
$getter = 'get'.ucfirst($property); |
101
|
|
|
if (method_exists($this, $getter)) |
102
|
|
|
{ |
103
|
|
|
return $this->$property = $this->$getter(); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
throw new \LogicException(sprintf('Unknown property %s::%s', __CLASS__, $property)); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
//-------------------------------------------------------------------------------------------------------------------- |
110
|
|
|
/** |
111
|
|
|
* Acquires a lock on a database entity and returns the object holding the lock. |
112
|
|
|
* |
113
|
|
|
* @param int $nameId The ID of the name of the entity lock. |
114
|
|
|
* @param int $entityId The ID of the entity. |
115
|
|
|
* |
116
|
|
|
* @return EntityLock |
117
|
|
|
*/ |
118
|
|
|
public function createEntityLock(int $nameId, int $entityId): EntityLock |
119
|
|
|
{ |
120
|
|
|
unset($nameId); |
121
|
|
|
unset($entityId); |
122
|
|
|
|
123
|
|
|
throw new \LogicException('Not implemented'); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
//-------------------------------------------------------------------------------------------------------------------- |
127
|
|
|
/** |
128
|
|
|
* Creates an empty mail message. |
129
|
|
|
* |
130
|
|
|
* @return MailMessage |
131
|
|
|
*/ |
132
|
|
|
public function createMailMessage(): MailMessage |
133
|
|
|
{ |
134
|
|
|
throw new \LogicException('Not implemented'); |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
//-------------------------------------------------------------------------------------------------------------------- |
138
|
|
|
/** |
139
|
|
|
* Acquires a named lock and returns the object holding the lock. |
140
|
|
|
* |
141
|
|
|
* @param int $id The ID of the named lock. |
142
|
|
|
* |
143
|
|
|
* @return NamedLock |
144
|
|
|
*/ |
145
|
|
|
public function createNamedLock(int $id): NamedLock |
146
|
|
|
{ |
147
|
|
|
unset($id); |
148
|
|
|
|
149
|
|
|
throw new \LogicException('Not implemented'); |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
//-------------------------------------------------------------------------------------------------------------------- |
153
|
|
|
/** |
154
|
|
|
* De-obfuscates an obfuscated database ID. |
155
|
|
|
* |
156
|
|
|
* @param string|null $code The obfuscated database ID. |
157
|
|
|
* @param string $alias An alias for the column holding the IDs. |
158
|
|
|
* |
159
|
|
|
* @return int|null |
160
|
|
|
*/ |
161
|
|
|
public function deObfuscate(?string $code, string $alias): ?int |
162
|
|
|
{ |
163
|
|
|
return $this->obfuscatorFactory::decode($code, $alias); |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
//-------------------------------------------------------------------------------------------------------------------- |
167
|
|
|
/** |
168
|
|
|
* Returns the URL of the login page. |
169
|
|
|
* |
170
|
|
|
* @param string|null $redirect After a successful login the user agent must be redirected to this URL. |
171
|
|
|
* |
172
|
|
|
* @return string |
173
|
|
|
*/ |
174
|
|
|
public function getLoginUrl(?string $redirect = null): string |
175
|
|
|
{ |
176
|
|
|
unset($redirect); |
177
|
|
|
|
178
|
|
|
throw new \LogicException('Not implemented'); |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
//-------------------------------------------------------------------------------------------------------------------- |
182
|
|
|
/** |
183
|
|
|
* Returns an Obfuscator for obfuscating and de-obfuscating database IDs. |
184
|
|
|
* |
185
|
|
|
* @param string $alias An alias for the column holding the IDs. |
186
|
|
|
* |
187
|
|
|
* @return Obfuscator |
188
|
|
|
*/ |
189
|
|
|
public function getObfuscator(string $alias): Obfuscator |
190
|
|
|
{ |
191
|
|
|
return $this->obfuscatorFactory::getObfuscator($alias); |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
//-------------------------------------------------------------------------------------------------------------------- |
195
|
|
|
/** |
196
|
|
|
* Handles the actual page request including authorization and security checking, transaction handling, |
197
|
|
|
* request logging, and exception handling. |
198
|
|
|
*/ |
199
|
|
|
final public function handlePageRequest(): void |
200
|
|
|
{ |
201
|
|
|
$this->requestHandler->handleRequest(); |
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 function obfuscate(?int $id, string $alias): ?string |
214
|
|
|
{ |
215
|
|
|
return $this->obfuscatorFactory::encode($id, $alias); |
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
//-------------------------------------------------------------------------------------------------------------------- |
219
|
|
|
} |
220
|
|
|
|
221
|
|
|
//---------------------------------------------------------------------------------------------------------------------- |
222
|
|
|
|