create-prisma-php-app 1.25.2 → 1.25.500
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 +132 -203
- 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/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
|
|
174
|
-
{
|
|
175
|
-
$jsonFileName = SETTINGS_PATH . '/files-list.json';
|
|
176
|
-
$routeFiles = file_exists($jsonFileName) ? json_decode(file_get_contents($jsonFileName), true) : [];
|
|
177
|
-
|
|
178
|
-
return $routeFiles;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
function findGroupFolder($uri): string
|
|
177
|
+
function findGroupFolder($pathname): string
|
|
182
178
|
{
|
|
183
|
-
$
|
|
184
|
-
foreach ($
|
|
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
|
-
|
|
198
|
+
$pathnameMatch = null;
|
|
199
|
+
$normalizedPathname = ltrim(str_replace('\\', '/', $pathname), './');
|
|
200
|
+
$normalizedPathnameEdited = "src/app/$normalizedPathname";
|
|
201
|
+
$pathnameSegments = explode('/', $normalizedPathnameEdited);
|
|
203
202
|
|
|
204
|
-
$
|
|
205
|
-
$normalizedUri = ltrim(str_replace('\\', '/', $uri), './');
|
|
206
|
-
$normalizedUriEdited = "src/app/$normalizedUri";
|
|
207
|
-
$uriSegments = explode('/', $normalizedUriEdited);
|
|
208
|
-
|
|
209
|
-
foreach ($_filesListRoutes as $route) {
|
|
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,6 +633,18 @@ function createUpdateRequestData()
|
|
|
675
633
|
file_put_contents($requestJsonData, $jsonData);
|
|
676
634
|
}
|
|
677
635
|
|
|
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
|
+
}
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
|
|
678
648
|
set_error_handler(function ($severity, $message, $file, $line) {
|
|
679
649
|
if (!(error_reporting() & $severity)) {
|
|
680
650
|
// This error code is not included in error_reporting
|
|
@@ -706,63 +676,21 @@ register_shutdown_function(function () {
|
|
|
706
676
|
}
|
|
707
677
|
});
|
|
708
678
|
|
|
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
679
|
try {
|
|
750
680
|
$_determineContentToInclude = determineContentToInclude();
|
|
751
681
|
$_contentToInclude = $_determineContentToInclude['path'] ?? '';
|
|
752
682
|
$_layoutsToInclude = $_determineContentToInclude['layouts'] ?? [];
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
$_requestUriForFilesIncludes = $requestUri;
|
|
756
|
-
$_fileToInclude = null;
|
|
683
|
+
Request::$pathname = $_determineContentToInclude['pathname'] ? '/' . $_determineContentToInclude['pathname'] : '/';
|
|
684
|
+
Request::$uri = $_determineContentToInclude['uri'] ? $_determineContentToInclude['uri'] : '/';
|
|
757
685
|
if (is_file($_contentToInclude)) {
|
|
758
|
-
|
|
686
|
+
Request::$fileToInclude = basename($_contentToInclude); // returns the file name
|
|
759
687
|
}
|
|
760
688
|
|
|
761
689
|
checkForDuplicateRoutes();
|
|
762
690
|
authenticateUserToken();
|
|
763
691
|
|
|
764
692
|
if (empty($_contentToInclude)) {
|
|
765
|
-
if (
|
|
693
|
+
if (!Request::$isXFileRequest && PrismaPHPSettings::$option['backendOnly']) {
|
|
766
694
|
// Set the header and output a JSON response for permission denied
|
|
767
695
|
header('Content-Type: application/json');
|
|
768
696
|
echo json_encode([
|
|
@@ -773,22 +701,22 @@ try {
|
|
|
773
701
|
exit;
|
|
774
702
|
}
|
|
775
703
|
|
|
776
|
-
$
|
|
777
|
-
if (is_file($
|
|
778
|
-
if (file_exists($
|
|
704
|
+
$_requestFilePath = APP_PATH . Request::$pathname;
|
|
705
|
+
if (is_file($_requestFilePath)) {
|
|
706
|
+
if (file_exists($_requestFilePath) && $isXFileRequest) {
|
|
779
707
|
// Check if the file is a PHP file
|
|
780
|
-
if (pathinfo($
|
|
708
|
+
if (pathinfo($_requestFilePath, PATHINFO_EXTENSION) === 'php') {
|
|
781
709
|
// Include the PHP file without setting the JSON header
|
|
782
|
-
include $
|
|
710
|
+
include $_requestFilePath;
|
|
783
711
|
} else {
|
|
784
712
|
// Set the appropriate content-type for non-PHP files if needed
|
|
785
713
|
// and read the content
|
|
786
|
-
header('Content-Type: ' . mime_content_type($
|
|
787
|
-
readfile($
|
|
714
|
+
header('Content-Type: ' . mime_content_type($_requestFilePath)); // Dynamic content type
|
|
715
|
+
readfile($_requestFilePath);
|
|
788
716
|
}
|
|
789
717
|
exit;
|
|
790
718
|
}
|
|
791
|
-
} else if (
|
|
719
|
+
} else if (PrismaPHPSettings::$option['backendOnly']) {
|
|
792
720
|
// Set the header and output a JSON response for file not found
|
|
793
721
|
header('Content-Type: application/json');
|
|
794
722
|
echo json_encode([
|
|
@@ -800,7 +728,7 @@ try {
|
|
|
800
728
|
}
|
|
801
729
|
}
|
|
802
730
|
|
|
803
|
-
if (!empty($_contentToInclude) &&
|
|
731
|
+
if (!empty($_contentToInclude) && Request::$fileToInclude === 'route.php') {
|
|
804
732
|
header('Content-Type: application/json');
|
|
805
733
|
require_once $_contentToInclude;
|
|
806
734
|
exit;
|
|
@@ -811,74 +739,75 @@ try {
|
|
|
811
739
|
|
|
812
740
|
$_isContentIncluded = false;
|
|
813
741
|
$_isChildContentIncluded = false;
|
|
814
|
-
$_isContentVariableIncluded =
|
|
742
|
+
$_isContentVariableIncluded = containsChildren($_parentLayoutPath);
|
|
815
743
|
if (!$_isContentVariableIncluded) {
|
|
816
744
|
$_isContentIncluded = true;
|
|
817
745
|
}
|
|
818
746
|
|
|
819
|
-
if (!empty($_contentToInclude) && !empty(
|
|
747
|
+
if (!empty($_contentToInclude) && !empty(Request::$fileToInclude)) {
|
|
820
748
|
if (!$_isParentLayout) {
|
|
821
749
|
ob_start();
|
|
822
750
|
require_once $_contentToInclude;
|
|
823
|
-
|
|
751
|
+
MainLayout::$childLayoutChildren = ob_get_clean();
|
|
824
752
|
}
|
|
825
753
|
foreach (array_reverse($_layoutsToInclude) as $layoutPath) {
|
|
826
754
|
if ($_parentLayoutPath === $layoutPath) {
|
|
827
755
|
continue;
|
|
828
756
|
}
|
|
829
757
|
|
|
830
|
-
$_isChildContentVariableIncluded =
|
|
758
|
+
$_isChildContentVariableIncluded = containsChildLayoutChildren($layoutPath);
|
|
831
759
|
if (!$_isChildContentVariableIncluded) {
|
|
832
760
|
$_isChildContentIncluded = true;
|
|
833
761
|
}
|
|
834
762
|
|
|
835
763
|
ob_start();
|
|
836
764
|
require_once $layoutPath;
|
|
837
|
-
|
|
765
|
+
MainLayout::$childLayoutChildren = ob_get_clean();
|
|
838
766
|
}
|
|
839
767
|
} else {
|
|
840
768
|
ob_start();
|
|
841
769
|
require_once APP_PATH . '/not-found.php';
|
|
842
|
-
|
|
770
|
+
MainLayout::$childLayoutChildren = ob_get_clean();
|
|
843
771
|
}
|
|
844
772
|
|
|
845
773
|
if ($_isParentLayout && !empty($_contentToInclude)) {
|
|
846
774
|
ob_start();
|
|
847
775
|
require_once $_contentToInclude;
|
|
848
|
-
|
|
776
|
+
MainLayout::$childLayoutChildren = ob_get_clean();
|
|
849
777
|
}
|
|
850
778
|
|
|
851
779
|
if (!$_isContentIncluded && !$_isChildContentIncluded) {
|
|
852
|
-
$
|
|
780
|
+
$_secondRequestC69CD = Request::$data['secondRequestC69CD'] ?? false;
|
|
853
781
|
|
|
854
|
-
if (!$
|
|
782
|
+
if (!$_secondRequestC69CD) {
|
|
855
783
|
createUpdateRequestData();
|
|
856
784
|
}
|
|
857
785
|
|
|
858
|
-
if (
|
|
786
|
+
if (Request::$isWire && !$_secondRequestC69CD) {
|
|
859
787
|
$_requestFilesJson = SETTINGS_PATH . '/request-data.json';
|
|
860
788
|
$_requestFilesData = file_exists($_requestFilesJson) ? json_decode(file_get_contents($_requestFilesJson), true) : [];
|
|
861
789
|
|
|
862
|
-
if ($_requestFilesData[
|
|
863
|
-
$_requestDataToLoop = $_requestFilesData[
|
|
790
|
+
if ($_requestFilesData[Request::$uri]) {
|
|
791
|
+
$_requestDataToLoop = $_requestFilesData[Request::$uri];
|
|
864
792
|
|
|
865
793
|
foreach ($_requestDataToLoop['includedFiles'] as $file) {
|
|
866
794
|
if (file_exists($file)) {
|
|
867
795
|
ob_start();
|
|
868
796
|
require_once $file;
|
|
869
|
-
|
|
797
|
+
MainLayout::$childLayoutChildren .= ob_get_clean();
|
|
870
798
|
}
|
|
871
799
|
}
|
|
872
800
|
}
|
|
873
801
|
}
|
|
874
802
|
|
|
875
|
-
|
|
876
|
-
|
|
803
|
+
MainLayout::$children = MainLayout::$childLayoutChildren;
|
|
804
|
+
MainLayout::$children .= getLoadingsFiles();
|
|
805
|
+
MainLayout::$children = '<div id="pphp-7CA7BB68A3656A88">' . MainLayout::$children . '</div>';
|
|
877
806
|
|
|
878
807
|
ob_start();
|
|
879
808
|
require_once APP_PATH . '/layout.php';
|
|
880
809
|
|
|
881
|
-
if (
|
|
810
|
+
if (Request::$isWire && !$_secondRequestC69CD) {
|
|
882
811
|
ob_end_clean();
|
|
883
812
|
wireCallback();
|
|
884
813
|
} else {
|
|
@@ -886,16 +815,16 @@ try {
|
|
|
886
815
|
}
|
|
887
816
|
} else {
|
|
888
817
|
if ($_isContentIncluded) {
|
|
889
|
-
echo "<div class='error'>The parent layout file does not contain <?php echo
|
|
818
|
+
echo "<div class='error'>The parent layout file does not contain <?php echo MainLayout::\$children; ?> Or <?= MainLayout::\$children ?><br>" . "<strong>$_parentLayoutPath</strong></div>";
|
|
890
819
|
} else {
|
|
891
|
-
$
|
|
892
|
-
modifyOutputLayoutForError($
|
|
820
|
+
$_errorDetails = "<div class='error'>The layout file does not contain <?php echo MainLayout::\$childLayoutChildren; ?> or <?= MainLayout::\$childLayoutChildren ?><br><strong>$layoutPath</strong></div>";
|
|
821
|
+
modifyOutputLayoutForError($_errorDetails);
|
|
893
822
|
}
|
|
894
823
|
}
|
|
895
824
|
} catch (Throwable $e) {
|
|
896
|
-
$
|
|
897
|
-
$
|
|
898
|
-
$
|
|
899
|
-
$
|
|
900
|
-
modifyOutputLayoutForError($
|
|
825
|
+
$_errorDetails = "Unhandled Exception: " . htmlspecialchars($e->getMessage(), ENT_QUOTES, 'UTF-8');
|
|
826
|
+
$_errorDetails .= "<br>File: " . htmlspecialchars($e->getFile(), ENT_QUOTES, 'UTF-8');
|
|
827
|
+
$_errorDetails .= "<br>Line: " . htmlspecialchars($e->getLine(), ENT_QUOTES, 'UTF-8');
|
|
828
|
+
$_errorDetails = "<div class='error'>$_errorDetails</div>";
|
|
829
|
+
modifyOutputLayoutForError($_errorDetails);
|
|
901
830
|
}
|