create-prisma-php-app 1.25.2 → 1.25.501
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bootstrap.php +153 -216
- package/dist/index.js +2 -2
- package/dist/settings/paths.php +0 -4
- package/dist/src/Lib/AI/ChatGPTClient.php +4 -4
- package/dist/src/Lib/Auth/Auth.php +26 -27
- package/dist/src/Lib/FileManager/UploadFile.php +2 -2
- package/dist/src/Lib/Headers/Boom.php +3 -3
- package/dist/src/Lib/MainLayout.php +38 -18
- package/dist/src/Lib/Middleware/AuthMiddleware.php +19 -18
- package/dist/src/Lib/PrismaPHPSettings.php +43 -0
- package/dist/src/Lib/Request.php +346 -0
- package/dist/src/Lib/StateManager.php +34 -52
- package/dist/src/app/index.php +4 -2
- package/dist/src/app/js/index.js +1 -1
- package/dist/src/app/js/json5.min.js +1 -0
- package/dist/src/app/layout.php +5 -4
- package/dist/src/app/swagger-docs-layout.php +26 -0
- package/package.json +1 -1
- package/dist/settings/public-functions.php +0 -159
- package/dist/settings/request-methods.php +0 -129
- package/dist/swagger-docs-layout.php +0 -17
package/dist/bootstrap.php
CHANGED
|
@@ -7,13 +7,21 @@ if (session_status() == PHP_SESSION_NONE) {
|
|
|
7
7
|
require_once __DIR__ . '/vendor/autoload.php';
|
|
8
8
|
require_once __DIR__ . '/settings/paths.php';
|
|
9
9
|
|
|
10
|
+
use Dotenv\Dotenv;
|
|
11
|
+
use Lib\Request;
|
|
12
|
+
use Lib\PrismaPHPSettings;
|
|
13
|
+
use Lib\StateManager;
|
|
10
14
|
use Lib\Middleware\AuthMiddleware;
|
|
11
15
|
use Lib\Auth\Auth;
|
|
12
|
-
use
|
|
16
|
+
use Lib\MainLayout;
|
|
13
17
|
|
|
14
18
|
$dotenv = Dotenv::createImmutable(\DOCUMENT_PATH);
|
|
15
19
|
$dotenv->load();
|
|
16
20
|
|
|
21
|
+
PrismaPHPSettings::init();
|
|
22
|
+
Request::init();
|
|
23
|
+
StateManager::init();
|
|
24
|
+
|
|
17
25
|
date_default_timezone_set($_ENV['APP_TIMEZONE'] ?? 'UTC');
|
|
18
26
|
|
|
19
27
|
function determineContentToInclude()
|
|
@@ -37,24 +45,24 @@ function determineContentToInclude()
|
|
|
37
45
|
* ============================================
|
|
38
46
|
*/
|
|
39
47
|
$scriptUrl = explode('?', $requestUri, 2)[0];
|
|
40
|
-
$
|
|
41
|
-
$
|
|
48
|
+
$pathname = $_SERVER['SCRIPT_URL'] ?? $scriptUrl;
|
|
49
|
+
$pathname = ltrim($pathname, '/');
|
|
42
50
|
$baseDir = APP_PATH;
|
|
43
51
|
$includePath = '';
|
|
44
52
|
$layoutsToInclude = [];
|
|
45
53
|
|
|
46
54
|
/**
|
|
47
55
|
* ============ Middleware Management ============
|
|
48
|
-
* AuthMiddleware is invoked to handle authentication logic for the current route ($
|
|
56
|
+
* AuthMiddleware is invoked to handle authentication logic for the current route ($pathname).
|
|
49
57
|
* ================================================
|
|
50
58
|
*/
|
|
51
|
-
AuthMiddleware::handle($
|
|
59
|
+
AuthMiddleware::handle($pathname);
|
|
52
60
|
/**
|
|
53
61
|
* ============ End of Middleware Management ======
|
|
54
62
|
* ================================================
|
|
55
63
|
*/
|
|
56
64
|
|
|
57
|
-
$isDirectAccessToPrivateRoute = preg_match('/_/', $
|
|
65
|
+
$isDirectAccessToPrivateRoute = preg_match('/_/', $pathname);
|
|
58
66
|
if ($isDirectAccessToPrivateRoute) {
|
|
59
67
|
$sameSiteFetch = false;
|
|
60
68
|
$serverFetchSite = $_SERVER['HTTP_SEC_FETCH_SITE'] ?? '';
|
|
@@ -63,12 +71,12 @@ function determineContentToInclude()
|
|
|
63
71
|
}
|
|
64
72
|
|
|
65
73
|
if (!$sameSiteFetch) {
|
|
66
|
-
return ['path' => $includePath, 'layouts' => $layoutsToInclude, '
|
|
74
|
+
return ['path' => $includePath, 'layouts' => $layoutsToInclude, 'pathname' => $pathname, 'uri' => $requestUri];
|
|
67
75
|
}
|
|
68
76
|
}
|
|
69
77
|
|
|
70
|
-
if ($
|
|
71
|
-
$groupFolder = findGroupFolder($
|
|
78
|
+
if ($pathname) {
|
|
79
|
+
$groupFolder = findGroupFolder($pathname);
|
|
72
80
|
if ($groupFolder) {
|
|
73
81
|
$path = __DIR__ . $groupFolder;
|
|
74
82
|
if (file_exists($path)) {
|
|
@@ -77,7 +85,7 @@ function determineContentToInclude()
|
|
|
77
85
|
}
|
|
78
86
|
|
|
79
87
|
if (empty($includePath)) {
|
|
80
|
-
$dynamicRoute = dynamicRoute($
|
|
88
|
+
$dynamicRoute = dynamicRoute($pathname);
|
|
81
89
|
if ($dynamicRoute) {
|
|
82
90
|
$path = __DIR__ . $dynamicRoute;
|
|
83
91
|
if (file_exists($path)) {
|
|
@@ -88,12 +96,12 @@ function determineContentToInclude()
|
|
|
88
96
|
|
|
89
97
|
$currentPath = $baseDir;
|
|
90
98
|
$getGroupFolder = getGroupFolder($groupFolder);
|
|
91
|
-
$
|
|
99
|
+
$modifiedPathname = $pathname;
|
|
92
100
|
if (!empty($getGroupFolder)) {
|
|
93
|
-
$
|
|
101
|
+
$modifiedPathname = trim($getGroupFolder, "/src/app/");
|
|
94
102
|
}
|
|
95
103
|
|
|
96
|
-
foreach (explode('/', $
|
|
104
|
+
foreach (explode('/', $modifiedPathname) as $segment) {
|
|
97
105
|
if (empty($segment)) continue;
|
|
98
106
|
|
|
99
107
|
$currentPath .= '/' . $segment;
|
|
@@ -125,14 +133,12 @@ function determineContentToInclude()
|
|
|
125
133
|
$includePath = $baseDir . getFilePrecedence();
|
|
126
134
|
}
|
|
127
135
|
|
|
128
|
-
return ['path' => $includePath, 'layouts' => $layoutsToInclude, '
|
|
136
|
+
return ['path' => $includePath, 'layouts' => $layoutsToInclude, 'pathname' => $pathname, 'uri' => $requestUri];
|
|
129
137
|
}
|
|
130
138
|
|
|
131
139
|
function getFilePrecedence()
|
|
132
140
|
{
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
foreach ($_filesListRoutes as $route) {
|
|
141
|
+
foreach (PrismaPHPSettings::$routeFiles as $route) {
|
|
136
142
|
// Check if the file has a .php extension
|
|
137
143
|
if (pathinfo($route, PATHINFO_EXTENSION) !== 'php') {
|
|
138
144
|
continue; // Skip files that are not PHP files
|
|
@@ -155,9 +161,7 @@ function getFilePrecedence()
|
|
|
155
161
|
|
|
156
162
|
function uriExtractor(string $scriptUrl): string
|
|
157
163
|
{
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
$projectName = $_prismaPHPSettings['projectName'] ?? '';
|
|
164
|
+
$projectName = PrismaPHPSettings::$option['projectName'] ?? '';
|
|
161
165
|
if (empty($projectName)) {
|
|
162
166
|
return "/";
|
|
163
167
|
}
|
|
@@ -170,18 +174,10 @@ function uriExtractor(string $scriptUrl): string
|
|
|
170
174
|
return "/";
|
|
171
175
|
}
|
|
172
176
|
|
|
173
|
-
function
|
|
177
|
+
function findGroupFolder($pathname): string
|
|
174
178
|
{
|
|
175
|
-
$
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
return $routeFiles;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
function findGroupFolder($uri): string
|
|
182
|
-
{
|
|
183
|
-
$uriSegments = explode('/', $uri);
|
|
184
|
-
foreach ($uriSegments as $segment) {
|
|
179
|
+
$pathnameSegments = explode('/', $pathname);
|
|
180
|
+
foreach ($pathnameSegments as $segment) {
|
|
185
181
|
if (!empty($segment)) {
|
|
186
182
|
if (isGroupIdentifier($segment)) {
|
|
187
183
|
return $segment;
|
|
@@ -189,7 +185,7 @@ function findGroupFolder($uri): string
|
|
|
189
185
|
}
|
|
190
186
|
}
|
|
191
187
|
|
|
192
|
-
$matchedGroupFolder = matchGroupFolder($
|
|
188
|
+
$matchedGroupFolder = matchGroupFolder($pathname);
|
|
193
189
|
if ($matchedGroupFolder) {
|
|
194
190
|
return $matchedGroupFolder;
|
|
195
191
|
} else {
|
|
@@ -197,16 +193,14 @@ function findGroupFolder($uri): string
|
|
|
197
193
|
}
|
|
198
194
|
}
|
|
199
195
|
|
|
200
|
-
function dynamicRoute($
|
|
196
|
+
function dynamicRoute($pathname)
|
|
201
197
|
{
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
$
|
|
205
|
-
$
|
|
206
|
-
$normalizedUriEdited = "src/app/$normalizedUri";
|
|
207
|
-
$uriSegments = explode('/', $normalizedUriEdited);
|
|
198
|
+
$pathnameMatch = null;
|
|
199
|
+
$normalizedPathname = ltrim(str_replace('\\', '/', $pathname), './');
|
|
200
|
+
$normalizedPathnameEdited = "src/app/$normalizedPathname";
|
|
201
|
+
$pathnameSegments = explode('/', $normalizedPathnameEdited);
|
|
208
202
|
|
|
209
|
-
foreach (
|
|
203
|
+
foreach (PrismaPHPSettings::$routeFiles as $route) {
|
|
210
204
|
$normalizedRoute = trim(str_replace('\\', '/', $route), '.');
|
|
211
205
|
|
|
212
206
|
// Skip non-.php files to improve performance
|
|
@@ -223,23 +217,23 @@ function dynamicRoute($uri)
|
|
|
223
217
|
$singleDynamic = preg_match_all('/\[[^\]]+\]/', $normalizedRoute, $matches) === 1 && strpos($normalizedRoute, '[...') === false;
|
|
224
218
|
|
|
225
219
|
if ($singleDynamic) {
|
|
226
|
-
$segmentMatch = singleDynamicRoute($
|
|
220
|
+
$segmentMatch = singleDynamicRoute($pathnameSegments, $filteredRouteSegments);
|
|
227
221
|
$index = array_search($segmentMatch, $filteredRouteSegments);
|
|
228
222
|
|
|
229
|
-
if ($index !== false && isset($
|
|
223
|
+
if ($index !== false && isset($pathnameSegments[$index])) {
|
|
230
224
|
$trimSegmentMatch = trim($segmentMatch, '[]');
|
|
231
|
-
|
|
225
|
+
Request::$dynamicParams = new \ArrayObject([$trimSegmentMatch => $pathnameSegments[$index]], \ArrayObject::ARRAY_AS_PROPS);
|
|
232
226
|
|
|
233
|
-
$
|
|
234
|
-
$
|
|
235
|
-
$
|
|
236
|
-
$
|
|
227
|
+
$dynamicRoutePathname = str_replace($segmentMatch, $pathnameSegments[$index], $normalizedRoute);
|
|
228
|
+
$dynamicRoutePathname = preg_replace('/\(.+\)/', '', $dynamicRoutePathname);
|
|
229
|
+
$dynamicRoutePathname = preg_replace('/\/+/', '/', $dynamicRoutePathname);
|
|
230
|
+
$dynamicRoutePathnameDirname = rtrim(dirname($dynamicRoutePathname), '/');
|
|
237
231
|
|
|
238
|
-
$
|
|
232
|
+
$expectedPathname = rtrim('/src/app/' . $normalizedPathname, '/');
|
|
239
233
|
|
|
240
234
|
if (strpos($normalizedRoute, 'route.php') !== false || strpos($normalizedRoute, 'index.php') !== false) {
|
|
241
|
-
if ($
|
|
242
|
-
$
|
|
235
|
+
if ($expectedPathname === $dynamicRoutePathnameDirname) {
|
|
236
|
+
$pathnameMatch = $normalizedRoute;
|
|
243
237
|
break;
|
|
244
238
|
}
|
|
245
239
|
}
|
|
@@ -250,20 +244,20 @@ function dynamicRoute($uri)
|
|
|
250
244
|
$cleanedNormalizedRoute = preg_replace('/\/+/', '/', $cleanedNormalizedRoute);
|
|
251
245
|
$dynamicSegmentRoute = preg_replace('/\[\.\.\..*?\].*/', '', $cleanedNormalizedRoute);
|
|
252
246
|
|
|
253
|
-
// Check if the normalized
|
|
254
|
-
if (strpos("/src/app/$
|
|
255
|
-
$
|
|
256
|
-
$
|
|
247
|
+
// Check if the normalized pathname starts with the cleaned route
|
|
248
|
+
if (strpos("/src/app/$normalizedPathname", $dynamicSegmentRoute) === 0) {
|
|
249
|
+
$trimmedPathname = str_replace($dynamicSegmentRoute, '', "/src/app/$normalizedPathname");
|
|
250
|
+
$pathnameParts = explode('/', trim($trimmedPathname, '/'));
|
|
257
251
|
|
|
258
252
|
// Extract the dynamic segment content
|
|
259
253
|
if (preg_match('/\[\.\.\.(.*?)\]/', $normalizedRoute, $matches)) {
|
|
260
254
|
$dynamicParam = $matches[1];
|
|
261
|
-
|
|
255
|
+
Request::$dynamicParams = new \ArrayObject([$dynamicParam => $pathnameParts], \ArrayObject::ARRAY_AS_PROPS);
|
|
262
256
|
}
|
|
263
257
|
|
|
264
258
|
// Check for 'route.php'
|
|
265
259
|
if (strpos($normalizedRoute, 'route.php') !== false) {
|
|
266
|
-
$
|
|
260
|
+
$pathnameMatch = $normalizedRoute;
|
|
267
261
|
break;
|
|
268
262
|
}
|
|
269
263
|
|
|
@@ -272,16 +266,16 @@ function dynamicRoute($uri)
|
|
|
272
266
|
$segmentMatch = "[...$dynamicParam]";
|
|
273
267
|
$index = array_search($segmentMatch, $filteredRouteSegments);
|
|
274
268
|
|
|
275
|
-
if ($index !== false && isset($
|
|
276
|
-
// Generate the dynamic
|
|
277
|
-
$
|
|
278
|
-
$
|
|
269
|
+
if ($index !== false && isset($pathnameSegments[$index])) {
|
|
270
|
+
// Generate the dynamic pathname
|
|
271
|
+
$dynamicRoutePathname = str_replace($segmentMatch, implode('/', $pathnameParts), $cleanedNormalizedRoute);
|
|
272
|
+
$dynamicRoutePathnameDirname = rtrim(dirname($dynamicRoutePathname), '/');
|
|
279
273
|
|
|
280
|
-
$
|
|
274
|
+
$expectedPathname = rtrim("/src/app/$normalizedPathname", '/');
|
|
281
275
|
|
|
282
|
-
// Compare the expected and dynamic
|
|
283
|
-
if ($
|
|
284
|
-
$
|
|
276
|
+
// Compare the expected and dynamic pathname
|
|
277
|
+
if ($expectedPathname === $dynamicRoutePathnameDirname) {
|
|
278
|
+
$pathnameMatch = $normalizedRoute;
|
|
285
279
|
break;
|
|
286
280
|
}
|
|
287
281
|
}
|
|
@@ -290,7 +284,7 @@ function dynamicRoute($uri)
|
|
|
290
284
|
}
|
|
291
285
|
}
|
|
292
286
|
|
|
293
|
-
return $
|
|
287
|
+
return $pathnameMatch;
|
|
294
288
|
}
|
|
295
289
|
|
|
296
290
|
function isGroupIdentifier($segment): bool
|
|
@@ -300,15 +294,13 @@ function isGroupIdentifier($segment): bool
|
|
|
300
294
|
|
|
301
295
|
function matchGroupFolder($constructedPath): ?string
|
|
302
296
|
{
|
|
303
|
-
global $_filesListRoutes;
|
|
304
|
-
|
|
305
297
|
$bestMatch = null;
|
|
306
298
|
$normalizedConstructedPath = ltrim(str_replace('\\', '/', $constructedPath), './');
|
|
307
299
|
|
|
308
300
|
$routeFile = "/src/app/$normalizedConstructedPath/route.php";
|
|
309
301
|
$indexFile = "/src/app/$normalizedConstructedPath/index.php";
|
|
310
302
|
|
|
311
|
-
foreach (
|
|
303
|
+
foreach (PrismaPHPSettings::$routeFiles as $route) {
|
|
312
304
|
if (pathinfo($route, PATHINFO_EXTENSION) !== 'php') {
|
|
313
305
|
continue;
|
|
314
306
|
}
|
|
@@ -327,10 +319,10 @@ function matchGroupFolder($constructedPath): ?string
|
|
|
327
319
|
return $bestMatch;
|
|
328
320
|
}
|
|
329
321
|
|
|
330
|
-
function getGroupFolder($
|
|
322
|
+
function getGroupFolder($pathname): string
|
|
331
323
|
{
|
|
332
|
-
$lastSlashPos = strrpos($
|
|
333
|
-
$pathWithoutFile = substr($
|
|
324
|
+
$lastSlashPos = strrpos($pathname, '/');
|
|
325
|
+
$pathWithoutFile = substr($pathname, 0, $lastSlashPos);
|
|
334
326
|
|
|
335
327
|
if (preg_match('/\(([^)]+)\)[^()]*$/', $pathWithoutFile, $matches)) {
|
|
336
328
|
return $pathWithoutFile;
|
|
@@ -339,14 +331,14 @@ function getGroupFolder($uri): string
|
|
|
339
331
|
return "";
|
|
340
332
|
}
|
|
341
333
|
|
|
342
|
-
function singleDynamicRoute($
|
|
334
|
+
function singleDynamicRoute($pathnameSegments, $routeSegments)
|
|
343
335
|
{
|
|
344
336
|
$segmentMatch = "";
|
|
345
337
|
foreach ($routeSegments as $index => $segment) {
|
|
346
338
|
if (preg_match('/^\[[^\]]+\]$/', $segment)) {
|
|
347
339
|
return "{$segment}";
|
|
348
340
|
} else {
|
|
349
|
-
if ($segment !== $
|
|
341
|
+
if ($segment !== $pathnameSegments[$index]) {
|
|
350
342
|
return $segmentMatch;
|
|
351
343
|
}
|
|
352
344
|
}
|
|
@@ -358,9 +350,8 @@ function checkForDuplicateRoutes()
|
|
|
358
350
|
{
|
|
359
351
|
if (isset($_ENV['APP_ENV']) && $_ENV['APP_ENV'] === 'production') return;
|
|
360
352
|
|
|
361
|
-
global $_filesListRoutes;
|
|
362
353
|
$normalizedRoutesMap = [];
|
|
363
|
-
foreach (
|
|
354
|
+
foreach (PrismaPHPSettings::$routeFiles as $route) {
|
|
364
355
|
if (pathinfo($route, PATHINFO_EXTENSION) !== 'php') {
|
|
365
356
|
continue;
|
|
366
357
|
}
|
|
@@ -395,25 +386,24 @@ function checkForDuplicateRoutes()
|
|
|
395
386
|
}
|
|
396
387
|
}
|
|
397
388
|
|
|
398
|
-
function
|
|
389
|
+
function containsChildLayoutChildren($filePath)
|
|
399
390
|
{
|
|
400
391
|
$fileContent = file_get_contents($filePath);
|
|
401
392
|
|
|
402
|
-
//
|
|
403
|
-
$pattern = '/\<\?=\s
|
|
393
|
+
// Updated regular expression to match MainLayout::$childLayoutChildren
|
|
394
|
+
$pattern = '/\<\?=\s*MainLayout::\$childLayoutChildren\s*;?\s*\?>|echo\s*MainLayout::\$childLayoutChildren\s*;?/';
|
|
404
395
|
|
|
405
|
-
// Return true if
|
|
396
|
+
// Return true if MainLayout::$childLayoutChildren variables are found, false otherwise
|
|
406
397
|
return preg_match($pattern, $fileContent) === 1;
|
|
407
398
|
}
|
|
408
399
|
|
|
409
|
-
function
|
|
400
|
+
function containsChildren($filePath)
|
|
410
401
|
{
|
|
411
402
|
$fileContent = file_get_contents($filePath);
|
|
412
403
|
|
|
413
|
-
//
|
|
414
|
-
$pattern = '/\<\?=\s
|
|
415
|
-
|
|
416
|
-
// Return true if content variables are found, false otherwise
|
|
404
|
+
// Updated regular expression to match MainLayout::$children
|
|
405
|
+
$pattern = '/\<\?=\s*MainLayout::\$children\s*;?\s*\?>|echo\s*MainLayout::\$children\s*;?/';
|
|
406
|
+
// Return true if the new content variables are found, false otherwise
|
|
417
407
|
return preg_match($pattern, $fileContent) === 1;
|
|
418
408
|
}
|
|
419
409
|
|
|
@@ -535,25 +525,23 @@ function wireCallback()
|
|
|
535
525
|
|
|
536
526
|
function getLoadingsFiles()
|
|
537
527
|
{
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
$loadingFiles = array_filter($_filesListRoutes, function ($route) {
|
|
528
|
+
$loadingFiles = array_filter(PrismaPHPSettings::$routeFiles, function ($route) {
|
|
541
529
|
$normalizedRoute = str_replace('\\', '/', $route);
|
|
542
530
|
return preg_match('/\/loading\.php$/', $normalizedRoute);
|
|
543
531
|
});
|
|
544
532
|
|
|
545
|
-
$haveLoadingFileContent = array_reduce($loadingFiles, function ($carry, $route)
|
|
533
|
+
$haveLoadingFileContent = array_reduce($loadingFiles, function ($carry, $route) {
|
|
546
534
|
$normalizeUri = str_replace('\\', '/', $route);
|
|
547
535
|
$fileUrl = str_replace('./src/app', '', $normalizeUri);
|
|
548
536
|
$route = str_replace(['\\', './'], ['/', ''], $route);
|
|
549
537
|
|
|
550
538
|
ob_start();
|
|
551
|
-
include($route);
|
|
552
|
-
$
|
|
539
|
+
include($route);
|
|
540
|
+
$loadingContent = ob_get_clean();
|
|
553
541
|
|
|
554
|
-
if ($
|
|
542
|
+
if ($loadingContent !== false) {
|
|
555
543
|
$url = $fileUrl === '/loading.php' ? '/' : str_replace('/loading.php', '', $fileUrl);
|
|
556
|
-
$carry .= '<div pp-loading-url="' . $url . '">' . $
|
|
544
|
+
$carry .= '<div pp-loading-url="' . $url . '">' . $loadingContent . '</div>';
|
|
557
545
|
}
|
|
558
546
|
|
|
559
547
|
return $carry;
|
|
@@ -566,36 +554,8 @@ function getLoadingsFiles()
|
|
|
566
554
|
return '';
|
|
567
555
|
}
|
|
568
556
|
|
|
569
|
-
function getPrismaSettings(): \ArrayObject
|
|
570
|
-
{
|
|
571
|
-
$_prismaPHPSettingsFile = DOCUMENT_PATH . '/prisma-php.json';
|
|
572
|
-
|
|
573
|
-
if (file_exists($_prismaPHPSettingsFile)) {
|
|
574
|
-
$jsonContent = file_get_contents($_prismaPHPSettingsFile);
|
|
575
|
-
$decodedJson = json_decode($jsonContent, true);
|
|
576
|
-
|
|
577
|
-
if (json_last_error() === JSON_ERROR_NONE) {
|
|
578
|
-
return new \ArrayObject($decodedJson, \ArrayObject::ARRAY_AS_PROPS);
|
|
579
|
-
} else {
|
|
580
|
-
return new \ArrayObject([]);
|
|
581
|
-
}
|
|
582
|
-
}
|
|
583
|
-
}
|
|
584
|
-
|
|
585
557
|
function modifyOutputLayoutForError($contentToAdd)
|
|
586
558
|
{
|
|
587
|
-
global
|
|
588
|
-
$baseUrl,
|
|
589
|
-
$content,
|
|
590
|
-
$childContent,
|
|
591
|
-
$uri,
|
|
592
|
-
$pathname,
|
|
593
|
-
$dynamicRouteParams,
|
|
594
|
-
$params,
|
|
595
|
-
$referer,
|
|
596
|
-
$mainLayoutHead,
|
|
597
|
-
$mainLayoutFooter;
|
|
598
|
-
|
|
599
559
|
$errorFile = APP_PATH . '/error.php';
|
|
600
560
|
$errorFileExists = file_exists($errorFile);
|
|
601
561
|
|
|
@@ -616,7 +576,7 @@ function modifyOutputLayoutForError($contentToAdd)
|
|
|
616
576
|
|
|
617
577
|
ob_start();
|
|
618
578
|
include_once $errorFile;
|
|
619
|
-
|
|
579
|
+
MainLayout::$children = ob_get_clean();
|
|
620
580
|
include $layoutFile;
|
|
621
581
|
} else {
|
|
622
582
|
echo $errorContent;
|
|
@@ -629,8 +589,6 @@ function modifyOutputLayoutForError($contentToAdd)
|
|
|
629
589
|
|
|
630
590
|
function createUpdateRequestData()
|
|
631
591
|
{
|
|
632
|
-
global $_requestUriForFilesIncludes;
|
|
633
|
-
|
|
634
592
|
$requestJsonData = SETTINGS_PATH . '/request-data.json';
|
|
635
593
|
|
|
636
594
|
// Check if the JSON file exists
|
|
@@ -654,7 +612,7 @@ function createUpdateRequestData()
|
|
|
654
612
|
}
|
|
655
613
|
|
|
656
614
|
// Extract the current request URL
|
|
657
|
-
$currentUrl =
|
|
615
|
+
$currentUrl = Request::$uri;
|
|
658
616
|
|
|
659
617
|
// If the URL already exists in the data, merge new included files with the existing ones
|
|
660
618
|
if (isset($currentData[$currentUrl])) {
|
|
@@ -675,20 +633,17 @@ function createUpdateRequestData()
|
|
|
675
633
|
file_put_contents($requestJsonData, $jsonData);
|
|
676
634
|
}
|
|
677
635
|
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
// If needed, log it or output immediately based on severity
|
|
688
|
-
if ($severity === E_WARNING || $severity === E_NOTICE) {
|
|
689
|
-
modifyOutputLayoutForError($errorContent);
|
|
636
|
+
function authenticateUserToken()
|
|
637
|
+
{
|
|
638
|
+
$token = Request::getBearerToken();
|
|
639
|
+
if ($token) {
|
|
640
|
+
$auth = Auth::getInstance();
|
|
641
|
+
$verifyToken = $auth->verifyToken($token);
|
|
642
|
+
if ($verifyToken) {
|
|
643
|
+
$auth->signIn($verifyToken);
|
|
644
|
+
}
|
|
690
645
|
}
|
|
691
|
-
}
|
|
646
|
+
}
|
|
692
647
|
|
|
693
648
|
set_exception_handler(function ($exception) {
|
|
694
649
|
$errorContent = "<div class='error'>Exception: " . htmlspecialchars($exception->getMessage(), ENT_QUOTES, 'UTF-8') . "</div>";
|
|
@@ -706,63 +661,21 @@ register_shutdown_function(function () {
|
|
|
706
661
|
}
|
|
707
662
|
});
|
|
708
663
|
|
|
709
|
-
$_prismaPHPSettings = getPrismaSettings();
|
|
710
|
-
$_filesListRoutes = getFilesListRoutes();
|
|
711
|
-
|
|
712
|
-
require_once SETTINGS_PATH . '/public-functions.php';
|
|
713
|
-
require_once SETTINGS_PATH . '/request-methods.php';
|
|
714
|
-
$_fileToInclude = '';
|
|
715
|
-
|
|
716
|
-
function authenticateUserToken()
|
|
717
|
-
{
|
|
718
|
-
$token = getBearerToken();
|
|
719
|
-
if ($token) {
|
|
720
|
-
$auth = Auth::getInstance();
|
|
721
|
-
$verifyToken = $auth->verifyToken($token);
|
|
722
|
-
if ($verifyToken) {
|
|
723
|
-
$auth->authenticate($verifyToken);
|
|
724
|
-
}
|
|
725
|
-
}
|
|
726
|
-
}
|
|
727
|
-
|
|
728
|
-
/**
|
|
729
|
-
* @var string $pathname The pathname of the current request
|
|
730
|
-
*/
|
|
731
|
-
$pathname = '';
|
|
732
|
-
/**
|
|
733
|
-
* @var array $dynamicRouteParams The dynamic route parameters
|
|
734
|
-
*/
|
|
735
|
-
$dynamicRouteParams = [];
|
|
736
|
-
/**
|
|
737
|
-
* @var string $content The content to be included in the main layout file
|
|
738
|
-
*/
|
|
739
|
-
$content = '';
|
|
740
|
-
/**
|
|
741
|
-
* @var string $childContent The child content to be included in the layout file
|
|
742
|
-
*/
|
|
743
|
-
$childContent = '';
|
|
744
|
-
/**
|
|
745
|
-
* @var string $requestUrl - The request URL.
|
|
746
|
-
*/
|
|
747
|
-
$requestUri = '';
|
|
748
|
-
|
|
749
664
|
try {
|
|
750
665
|
$_determineContentToInclude = determineContentToInclude();
|
|
751
666
|
$_contentToInclude = $_determineContentToInclude['path'] ?? '';
|
|
752
667
|
$_layoutsToInclude = $_determineContentToInclude['layouts'] ?? [];
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
$_requestUriForFilesIncludes = $requestUri;
|
|
756
|
-
$_fileToInclude = null;
|
|
668
|
+
Request::$pathname = $_determineContentToInclude['pathname'] ? '/' . $_determineContentToInclude['pathname'] : '/';
|
|
669
|
+
Request::$uri = $_determineContentToInclude['uri'] ? $_determineContentToInclude['uri'] : '/';
|
|
757
670
|
if (is_file($_contentToInclude)) {
|
|
758
|
-
|
|
671
|
+
Request::$fileToInclude = basename($_contentToInclude); // returns the file name
|
|
759
672
|
}
|
|
760
673
|
|
|
761
674
|
checkForDuplicateRoutes();
|
|
762
675
|
authenticateUserToken();
|
|
763
676
|
|
|
764
677
|
if (empty($_contentToInclude)) {
|
|
765
|
-
if (
|
|
678
|
+
if (!Request::$isXFileRequest && PrismaPHPSettings::$option['backendOnly']) {
|
|
766
679
|
// Set the header and output a JSON response for permission denied
|
|
767
680
|
header('Content-Type: application/json');
|
|
768
681
|
echo json_encode([
|
|
@@ -773,22 +686,22 @@ try {
|
|
|
773
686
|
exit;
|
|
774
687
|
}
|
|
775
688
|
|
|
776
|
-
$
|
|
777
|
-
if (is_file($
|
|
778
|
-
if (file_exists($
|
|
689
|
+
$_requestFilePath = APP_PATH . Request::$pathname;
|
|
690
|
+
if (is_file($_requestFilePath)) {
|
|
691
|
+
if (file_exists($_requestFilePath) && $isXFileRequest) {
|
|
779
692
|
// Check if the file is a PHP file
|
|
780
|
-
if (pathinfo($
|
|
693
|
+
if (pathinfo($_requestFilePath, PATHINFO_EXTENSION) === 'php') {
|
|
781
694
|
// Include the PHP file without setting the JSON header
|
|
782
|
-
include $
|
|
695
|
+
include $_requestFilePath;
|
|
783
696
|
} else {
|
|
784
697
|
// Set the appropriate content-type for non-PHP files if needed
|
|
785
698
|
// and read the content
|
|
786
|
-
header('Content-Type: ' . mime_content_type($
|
|
787
|
-
readfile($
|
|
699
|
+
header('Content-Type: ' . mime_content_type($_requestFilePath)); // Dynamic content type
|
|
700
|
+
readfile($_requestFilePath);
|
|
788
701
|
}
|
|
789
702
|
exit;
|
|
790
703
|
}
|
|
791
|
-
} else if (
|
|
704
|
+
} else if (PrismaPHPSettings::$option['backendOnly']) {
|
|
792
705
|
// Set the header and output a JSON response for file not found
|
|
793
706
|
header('Content-Type: application/json');
|
|
794
707
|
echo json_encode([
|
|
@@ -800,7 +713,7 @@ try {
|
|
|
800
713
|
}
|
|
801
714
|
}
|
|
802
715
|
|
|
803
|
-
if (!empty($_contentToInclude) &&
|
|
716
|
+
if (!empty($_contentToInclude) && Request::$fileToInclude === 'route.php') {
|
|
804
717
|
header('Content-Type: application/json');
|
|
805
718
|
require_once $_contentToInclude;
|
|
806
719
|
exit;
|
|
@@ -811,74 +724,75 @@ try {
|
|
|
811
724
|
|
|
812
725
|
$_isContentIncluded = false;
|
|
813
726
|
$_isChildContentIncluded = false;
|
|
814
|
-
$_isContentVariableIncluded =
|
|
727
|
+
$_isContentVariableIncluded = containsChildren($_parentLayoutPath);
|
|
815
728
|
if (!$_isContentVariableIncluded) {
|
|
816
729
|
$_isContentIncluded = true;
|
|
817
730
|
}
|
|
818
731
|
|
|
819
|
-
if (!empty($_contentToInclude) && !empty(
|
|
732
|
+
if (!empty($_contentToInclude) && !empty(Request::$fileToInclude)) {
|
|
820
733
|
if (!$_isParentLayout) {
|
|
821
734
|
ob_start();
|
|
822
735
|
require_once $_contentToInclude;
|
|
823
|
-
|
|
736
|
+
MainLayout::$childLayoutChildren = ob_get_clean();
|
|
824
737
|
}
|
|
825
738
|
foreach (array_reverse($_layoutsToInclude) as $layoutPath) {
|
|
826
739
|
if ($_parentLayoutPath === $layoutPath) {
|
|
827
740
|
continue;
|
|
828
741
|
}
|
|
829
742
|
|
|
830
|
-
$_isChildContentVariableIncluded =
|
|
743
|
+
$_isChildContentVariableIncluded = containsChildLayoutChildren($layoutPath);
|
|
831
744
|
if (!$_isChildContentVariableIncluded) {
|
|
832
745
|
$_isChildContentIncluded = true;
|
|
833
746
|
}
|
|
834
747
|
|
|
835
748
|
ob_start();
|
|
836
749
|
require_once $layoutPath;
|
|
837
|
-
|
|
750
|
+
MainLayout::$childLayoutChildren = ob_get_clean();
|
|
838
751
|
}
|
|
839
752
|
} else {
|
|
840
753
|
ob_start();
|
|
841
754
|
require_once APP_PATH . '/not-found.php';
|
|
842
|
-
|
|
755
|
+
MainLayout::$childLayoutChildren = ob_get_clean();
|
|
843
756
|
}
|
|
844
757
|
|
|
845
758
|
if ($_isParentLayout && !empty($_contentToInclude)) {
|
|
846
759
|
ob_start();
|
|
847
760
|
require_once $_contentToInclude;
|
|
848
|
-
|
|
761
|
+
MainLayout::$childLayoutChildren = ob_get_clean();
|
|
849
762
|
}
|
|
850
763
|
|
|
851
764
|
if (!$_isContentIncluded && !$_isChildContentIncluded) {
|
|
852
|
-
$
|
|
765
|
+
$_secondRequestC69CD = Request::$data['secondRequestC69CD'] ?? false;
|
|
853
766
|
|
|
854
|
-
if (!$
|
|
767
|
+
if (!$_secondRequestC69CD) {
|
|
855
768
|
createUpdateRequestData();
|
|
856
769
|
}
|
|
857
770
|
|
|
858
|
-
if (
|
|
771
|
+
if (Request::$isWire && !$_secondRequestC69CD) {
|
|
859
772
|
$_requestFilesJson = SETTINGS_PATH . '/request-data.json';
|
|
860
773
|
$_requestFilesData = file_exists($_requestFilesJson) ? json_decode(file_get_contents($_requestFilesJson), true) : [];
|
|
861
774
|
|
|
862
|
-
if ($_requestFilesData[
|
|
863
|
-
$_requestDataToLoop = $_requestFilesData[
|
|
775
|
+
if ($_requestFilesData[Request::$uri]) {
|
|
776
|
+
$_requestDataToLoop = $_requestFilesData[Request::$uri];
|
|
864
777
|
|
|
865
778
|
foreach ($_requestDataToLoop['includedFiles'] as $file) {
|
|
866
779
|
if (file_exists($file)) {
|
|
867
780
|
ob_start();
|
|
868
781
|
require_once $file;
|
|
869
|
-
|
|
782
|
+
MainLayout::$childLayoutChildren .= ob_get_clean();
|
|
870
783
|
}
|
|
871
784
|
}
|
|
872
785
|
}
|
|
873
786
|
}
|
|
874
787
|
|
|
875
|
-
|
|
876
|
-
|
|
788
|
+
MainLayout::$children = MainLayout::$childLayoutChildren;
|
|
789
|
+
MainLayout::$children .= getLoadingsFiles();
|
|
790
|
+
MainLayout::$children = '<div id="pphp-7CA7BB68A3656A88">' . MainLayout::$children . '</div>';
|
|
877
791
|
|
|
878
792
|
ob_start();
|
|
879
793
|
require_once APP_PATH . '/layout.php';
|
|
880
794
|
|
|
881
|
-
if (
|
|
795
|
+
if (Request::$isWire && !$_secondRequestC69CD) {
|
|
882
796
|
ob_end_clean();
|
|
883
797
|
wireCallback();
|
|
884
798
|
} else {
|
|
@@ -886,16 +800,39 @@ try {
|
|
|
886
800
|
}
|
|
887
801
|
} else {
|
|
888
802
|
if ($_isContentIncluded) {
|
|
889
|
-
echo "<div class='error'>The parent layout file does not contain <?php echo
|
|
803
|
+
echo "<div class='error'>The parent layout file does not contain <?php echo MainLayout::\$children; ?> Or <?= MainLayout::\$children ?><br>" . "<strong>$_parentLayoutPath</strong></div>";
|
|
890
804
|
} else {
|
|
891
|
-
$
|
|
892
|
-
modifyOutputLayoutForError($
|
|
805
|
+
$_errorDetails = "<div class='error'>The layout file does not contain <?php echo MainLayout::\$childLayoutChildren; ?> or <?= MainLayout::\$childLayoutChildren ?><br><strong>$layoutPath</strong></div>";
|
|
806
|
+
modifyOutputLayoutForError($_errorDetails);
|
|
893
807
|
}
|
|
894
808
|
}
|
|
895
809
|
} catch (Throwable $e) {
|
|
896
|
-
$
|
|
897
|
-
$
|
|
898
|
-
$
|
|
899
|
-
$
|
|
900
|
-
modifyOutputLayoutForError($
|
|
810
|
+
$_errorDetails = "Unhandled Exception: " . htmlspecialchars($e->getMessage(), ENT_QUOTES, 'UTF-8');
|
|
811
|
+
$_errorDetails .= "<br>File: " . htmlspecialchars($e->getFile(), ENT_QUOTES, 'UTF-8');
|
|
812
|
+
$_errorDetails .= "<br>Line: " . htmlspecialchars($e->getLine(), ENT_QUOTES, 'UTF-8');
|
|
813
|
+
$_errorDetails = "<div class='error'>$_errorDetails</div>";
|
|
814
|
+
modifyOutputLayoutForError($_errorDetails);
|
|
901
815
|
}
|
|
816
|
+
|
|
817
|
+
(function () {
|
|
818
|
+
$lastErrorCapture = error_get_last();
|
|
819
|
+
if ($lastErrorCapture !== null) {
|
|
820
|
+
$errorContent = "<div class='error'>Error: " . $lastErrorCapture['message'] . " in " . $lastErrorCapture['file'] . " on line " . $lastErrorCapture['line'] . "</div>";
|
|
821
|
+
modifyOutputLayoutForError($errorContent);
|
|
822
|
+
}
|
|
823
|
+
})();
|
|
824
|
+
|
|
825
|
+
set_error_handler(function ($severity, $message, $file, $line) {
|
|
826
|
+
if (!(error_reporting() & $severity)) {
|
|
827
|
+
// This error code is not included in error_reporting
|
|
828
|
+
return;
|
|
829
|
+
}
|
|
830
|
+
|
|
831
|
+
// Capture the specific severity types, including warnings (E_WARNING)
|
|
832
|
+
$errorContent = "<div class='error'>Error: {$severity} - {$message} in {$file} on line {$line}</div>";
|
|
833
|
+
|
|
834
|
+
// If needed, log it or output immediately based on severity
|
|
835
|
+
if ($severity === E_WARNING || $severity === E_NOTICE) {
|
|
836
|
+
modifyOutputLayoutForError($errorContent);
|
|
837
|
+
}
|
|
838
|
+
});
|