create-prisma-php-app 1.12.8 → 1.13.0
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
CHANGED
|
@@ -65,16 +65,30 @@ function determineContentToInclude()
|
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
foreach (explode('/', $modifiedUri) as $segment) {
|
|
68
|
-
if (empty($segment))
|
|
69
|
-
|
|
70
|
-
}
|
|
68
|
+
if (empty($segment)) continue;
|
|
69
|
+
|
|
71
70
|
$currentPath .= '/' . $segment;
|
|
72
71
|
$potentialLayoutPath = $currentPath . '/layout.php';
|
|
73
|
-
if (file_exists($potentialLayoutPath)) {
|
|
72
|
+
if (file_exists($potentialLayoutPath) && !in_array($potentialLayoutPath, $layoutsToInclude)) {
|
|
74
73
|
$layoutsToInclude[] = $potentialLayoutPath;
|
|
75
74
|
}
|
|
76
75
|
}
|
|
77
76
|
|
|
77
|
+
if (isset($dynamicRoute)) {
|
|
78
|
+
$currentDynamicPath = $baseDir;
|
|
79
|
+
foreach (explode('/', $dynamicRoute) as $segment) {
|
|
80
|
+
if (empty($segment)) continue;
|
|
81
|
+
|
|
82
|
+
if ($segment === 'src' || $segment === 'app') continue;
|
|
83
|
+
|
|
84
|
+
$currentDynamicPath .= '/' . $segment;
|
|
85
|
+
$potentialDynamicRoute = $currentDynamicPath . '/layout.php';
|
|
86
|
+
if (file_exists($potentialDynamicRoute) && !in_array($potentialDynamicRoute, $layoutsToInclude)) {
|
|
87
|
+
$layoutsToInclude[] = $potentialDynamicRoute;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
78
92
|
if (empty($layoutsToInclude)) {
|
|
79
93
|
$layoutsToInclude[] = $baseDir . '/layout.php';
|
|
80
94
|
}
|
|
@@ -108,7 +122,7 @@ function uriExtractor(string $scriptUrl): string
|
|
|
108
122
|
|
|
109
123
|
function writeRoutes()
|
|
110
124
|
{
|
|
111
|
-
global $
|
|
125
|
+
global $_filesListRoutes;
|
|
112
126
|
$directory = './src/app';
|
|
113
127
|
|
|
114
128
|
if (is_dir($directory)) {
|
|
@@ -127,7 +141,7 @@ function writeRoutes()
|
|
|
127
141
|
@file_put_contents($jsonFileName, $jsonData);
|
|
128
142
|
|
|
129
143
|
if (file_exists($jsonFileName)) {
|
|
130
|
-
$
|
|
144
|
+
$_filesListRoutes = json_decode(file_get_contents($jsonFileName), true);
|
|
131
145
|
}
|
|
132
146
|
}
|
|
133
147
|
}
|
|
@@ -153,13 +167,13 @@ function findGroupFolder($uri): string
|
|
|
153
167
|
|
|
154
168
|
function dynamicRoute($uri)
|
|
155
169
|
{
|
|
156
|
-
global $
|
|
170
|
+
global $_filesListRoutes;
|
|
157
171
|
global $dynamicRouteParams;
|
|
158
172
|
$uriMatch = null;
|
|
159
173
|
$normalizedUri = ltrim(str_replace('\\', '/', $uri), './');
|
|
160
|
-
$normalizedUriEdited = "src/app/$normalizedUri
|
|
174
|
+
$normalizedUriEdited = "src/app/$normalizedUri";
|
|
161
175
|
$uriSegments = explode('/', $normalizedUriEdited);
|
|
162
|
-
foreach ($
|
|
176
|
+
foreach ($_filesListRoutes as $route) {
|
|
163
177
|
$normalizedRoute = trim(str_replace('\\', '/', $route), '.');
|
|
164
178
|
$routeSegments = explode('/', ltrim($normalizedRoute, '/'));
|
|
165
179
|
$singleDynamic = preg_match_all('/\[[^\]]+\]/', $normalizedRoute, $matches) === 1 && !strpos($normalizedRoute, '[...');
|
|
@@ -168,24 +182,51 @@ function dynamicRoute($uri)
|
|
|
168
182
|
if (!empty($segmentMatch)) {
|
|
169
183
|
$trimSegmentMatch = trim($segmentMatch, '[]');
|
|
170
184
|
$dynamicRouteParams = [$trimSegmentMatch => $uriSegments[array_search($segmentMatch, $routeSegments)]];
|
|
171
|
-
|
|
172
|
-
|
|
185
|
+
|
|
186
|
+
$dynamicRouteUri = str_replace($segmentMatch, $dynamicRouteParams[array_search($segmentMatch, $routeSegments)], $normalizedRoute);
|
|
187
|
+
$dynamicRouteUriDirname = dirname($dynamicRouteUri);
|
|
188
|
+
$dynamicRouteUriDirname = rtrim($dynamicRouteUriDirname, '/');
|
|
189
|
+
|
|
190
|
+
$expectedUri = '/src/app/' . $normalizedUri;
|
|
191
|
+
$expectedUri = rtrim($expectedUri, '/');
|
|
192
|
+
|
|
193
|
+
if (strpos($normalizedRoute, 'route.php') !== false || strpos($normalizedRoute, 'index.php') !== false) {
|
|
194
|
+
if ($expectedUri === $dynamicRouteUriDirname) {
|
|
195
|
+
$uriMatch = $normalizedRoute;
|
|
196
|
+
break;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
173
199
|
}
|
|
174
200
|
} elseif (strpos($normalizedRoute, '[...') !== false) {
|
|
175
201
|
$cleanedRoute = preg_replace('/\[\.\.\..*?\].*/', '', $normalizedRoute);
|
|
176
202
|
if (strpos('/src/app/' . $normalizedUri, $cleanedRoute) === 0) {
|
|
177
|
-
if (strpos($normalizedRoute, 'route.php') !== false) {
|
|
178
|
-
$normalizedUriEdited = "/src/app/$normalizedUri";
|
|
179
|
-
$trimNormalizedUriEdited = str_replace($cleanedRoute, '', $normalizedUriEdited);
|
|
180
|
-
$explodedNormalizedUri = explode('/', $trimNormalizedUriEdited);
|
|
181
|
-
$pattern = '/\[\.\.\.(.*?)\]/';
|
|
182
|
-
if (preg_match($pattern, $normalizedRoute, $matches)) {
|
|
183
|
-
$contentWithinBrackets = $matches[1];
|
|
184
|
-
$dynamicRouteParams = [$contentWithinBrackets => $explodedNormalizedUri];
|
|
185
|
-
}
|
|
186
203
|
|
|
204
|
+
$normalizedUriEdited = "/src/app/$normalizedUri";
|
|
205
|
+
$trimNormalizedUriEdited = str_replace($cleanedRoute, '', $normalizedUriEdited);
|
|
206
|
+
$explodedNormalizedUri = explode('/', $trimNormalizedUriEdited);
|
|
207
|
+
$pattern = '/\[\.\.\.(.*?)\]/';
|
|
208
|
+
if (preg_match($pattern, $normalizedRoute, $matches)) {
|
|
209
|
+
$contentWithinBrackets = $matches[1];
|
|
210
|
+
$dynamicRouteParams = [$contentWithinBrackets => $explodedNormalizedUri];
|
|
211
|
+
}
|
|
212
|
+
if (strpos($normalizedRoute, 'route.php') !== false) {
|
|
187
213
|
$uriMatch = $normalizedRoute;
|
|
188
214
|
break;
|
|
215
|
+
} else {
|
|
216
|
+
if (strpos($normalizedRoute, 'index.php') !== false) {
|
|
217
|
+
$segmentMatch = "[...$contentWithinBrackets]";
|
|
218
|
+
$dynamicRouteUri = str_replace($segmentMatch, $uriSegments[array_search($segmentMatch, $routeSegments)], $normalizedRoute);
|
|
219
|
+
$dynamicRouteUriDirname = dirname($dynamicRouteUri);
|
|
220
|
+
$dynamicRouteUriDirname = rtrim($dynamicRouteUriDirname, '/');
|
|
221
|
+
|
|
222
|
+
$expectedUri = '/src/app/' . $normalizedUri;
|
|
223
|
+
$expectedUri = rtrim($expectedUri, '/');
|
|
224
|
+
|
|
225
|
+
if ($expectedUri === $dynamicRouteUriDirname) {
|
|
226
|
+
$uriMatch = $normalizedRoute;
|
|
227
|
+
break;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
189
230
|
}
|
|
190
231
|
}
|
|
191
232
|
}
|
|
@@ -201,14 +242,14 @@ function isGroupIdentifier($segment): bool
|
|
|
201
242
|
|
|
202
243
|
function matchGroupFolder($constructedPath): ?string
|
|
203
244
|
{
|
|
204
|
-
global $
|
|
245
|
+
global $_filesListRoutes;
|
|
205
246
|
$bestMatch = null;
|
|
206
247
|
$normalizedConstructedPath = ltrim(str_replace('\\', '/', $constructedPath), './');
|
|
207
248
|
|
|
208
249
|
$routeFile = "/src/app/$normalizedConstructedPath/route.php";
|
|
209
250
|
$indexFile = "/src/app/$normalizedConstructedPath/index.php";
|
|
210
251
|
|
|
211
|
-
foreach ($
|
|
252
|
+
foreach ($_filesListRoutes as $route) {
|
|
212
253
|
$normalizedRoute = trim(str_replace('\\', '/', $route), '.');
|
|
213
254
|
|
|
214
255
|
$cleanedRoute = preg_replace('/\/\([^)]+\)/', '', $normalizedRoute);
|
|
@@ -256,9 +297,9 @@ function singleDynamicRoute($uriSegments, $routeSegments)
|
|
|
256
297
|
|
|
257
298
|
function checkForDuplicateRoutes()
|
|
258
299
|
{
|
|
259
|
-
global $
|
|
300
|
+
global $_filesListRoutes;
|
|
260
301
|
$normalizedRoutesMap = [];
|
|
261
|
-
foreach ($
|
|
302
|
+
foreach ($_filesListRoutes as $route) {
|
|
262
303
|
$routeWithoutGroups = preg_replace('/\(.*?\)/', '', $route);
|
|
263
304
|
$routeTrimmed = ltrim($routeWithoutGroups, '.\\/');
|
|
264
305
|
$routeTrimmed = preg_replace('#/{2,}#', '/', $routeTrimmed);
|
|
@@ -314,8 +355,8 @@ function setupErrorHandling(&$content)
|
|
|
314
355
|
ob_start();
|
|
315
356
|
require_once SETTINGS_PATH . '/public-functions.php';
|
|
316
357
|
require_once SETTINGS_PATH . '/request-methods.php';
|
|
317
|
-
$
|
|
318
|
-
$
|
|
358
|
+
$_metadataArray = require_once APP_PATH . '/metadata.php';
|
|
359
|
+
$_filesListRoutes = [];
|
|
319
360
|
$metadata = "";
|
|
320
361
|
$uri = "";
|
|
321
362
|
$pathname = "";
|
|
@@ -367,42 +408,42 @@ function modifyOutputLayoutForError($contentToAdd)
|
|
|
367
408
|
}
|
|
368
409
|
|
|
369
410
|
try {
|
|
370
|
-
$
|
|
411
|
+
$_determineContentToInclude = determineContentToInclude();
|
|
371
412
|
checkForDuplicateRoutes();
|
|
372
|
-
$
|
|
373
|
-
$
|
|
374
|
-
$uri = $
|
|
413
|
+
$_contentToInclude = $_determineContentToInclude['path'] ?? '';
|
|
414
|
+
$_layoutsToInclude = $_determineContentToInclude['layouts'] ?? [];
|
|
415
|
+
$uri = $_determineContentToInclude['uri'] ?? '';
|
|
375
416
|
$pathname = $uri ? "/" . $uri : "/";
|
|
376
|
-
$metadata = $
|
|
377
|
-
if (!empty($
|
|
417
|
+
$metadata = $_metadataArray[$uri] ?? $_metadataArray['default'];
|
|
418
|
+
if (!empty($_contentToInclude) && basename($_contentToInclude) === 'route.php') {
|
|
378
419
|
header('Content-Type: application/json');
|
|
379
|
-
require_once $
|
|
420
|
+
require_once $_contentToInclude;
|
|
380
421
|
exit;
|
|
381
422
|
}
|
|
382
423
|
|
|
383
|
-
$
|
|
384
|
-
$
|
|
424
|
+
$_parentLayoutPath = APP_PATH . '/layout.php';
|
|
425
|
+
$_isParentLayout = !empty($_layoutsToInclude) && strpos($_layoutsToInclude[0], 'src/app/layout.php') !== false;
|
|
385
426
|
|
|
386
|
-
$
|
|
387
|
-
$
|
|
388
|
-
if (containsContent($
|
|
389
|
-
$
|
|
427
|
+
$_isContentIncluded = false;
|
|
428
|
+
$_isChildContentIncluded = false;
|
|
429
|
+
if (containsContent($_parentLayoutPath)) {
|
|
430
|
+
$_isContentIncluded = true;
|
|
390
431
|
}
|
|
391
432
|
|
|
392
433
|
ob_start();
|
|
393
|
-
if (!empty($
|
|
394
|
-
if (!$
|
|
434
|
+
if (!empty($_contentToInclude)) {
|
|
435
|
+
if (!$_isParentLayout) {
|
|
395
436
|
ob_start();
|
|
396
|
-
require_once $
|
|
437
|
+
require_once $_contentToInclude;
|
|
397
438
|
$childContent = ob_get_clean();
|
|
398
439
|
}
|
|
399
|
-
foreach (array_reverse($
|
|
400
|
-
if ($
|
|
440
|
+
foreach (array_reverse($_layoutsToInclude) as $layoutPath) {
|
|
441
|
+
if ($_parentLayoutPath === $layoutPath) {
|
|
401
442
|
continue;
|
|
402
443
|
}
|
|
403
444
|
|
|
404
445
|
if (containsChildContent($layoutPath)) {
|
|
405
|
-
$
|
|
446
|
+
$_isChildContentIncluded = true;
|
|
406
447
|
}
|
|
407
448
|
|
|
408
449
|
ob_start();
|
|
@@ -415,19 +456,19 @@ try {
|
|
|
415
456
|
$childContent = ob_get_clean();
|
|
416
457
|
}
|
|
417
458
|
|
|
418
|
-
if ($
|
|
459
|
+
if ($_isParentLayout && !empty($_contentToInclude)) {
|
|
419
460
|
ob_start();
|
|
420
|
-
require_once $
|
|
461
|
+
require_once $_contentToInclude;
|
|
421
462
|
$childContent = ob_get_clean();
|
|
422
463
|
}
|
|
423
464
|
|
|
424
|
-
if (!$
|
|
465
|
+
if (!$_isContentIncluded && !$_isChildContentIncluded) {
|
|
425
466
|
$content .= $childContent;
|
|
426
467
|
ob_start();
|
|
427
468
|
require_once APP_PATH . '/layout.php';
|
|
428
469
|
} else {
|
|
429
|
-
if ($
|
|
430
|
-
$content .= "<div class='error'>The parent layout file does not contain <?php echo \$content; ?> Or <?= \$content ?><br>" . "<strong>$
|
|
470
|
+
if ($_isContentIncluded) {
|
|
471
|
+
$content .= "<div class='error'>The parent layout file does not contain <?php echo \$content; ?> Or <?= \$content ?><br>" . "<strong>$_parentLayoutPath</strong></div>";
|
|
431
472
|
modifyOutputLayoutForError($content);
|
|
432
473
|
} else {
|
|
433
474
|
$content .= "<div class='error'>The layout file does not contain <?php echo \$childContent; ?> or <?= \$childContent ?><br><strong>$layoutPath</strong></div>";
|
package/dist/prisma-php.js
CHANGED
|
@@ -35,7 +35,7 @@ const main = async () => {
|
|
|
35
35
|
if (localSettings.tailwindcss) commandArgs.push("--tailwindcss");
|
|
36
36
|
if (localSettings.websocket) commandArgs.push("--websocket");
|
|
37
37
|
if (localSettings.prisma) commandArgs.push("--prisma");
|
|
38
|
-
if (localSettings.
|
|
38
|
+
if (localSettings.htmx) commandArgs.push("--htmx");
|
|
39
39
|
if (localSettings.docker) commandArgs.push("--docker");
|
|
40
40
|
console.log("Executing command...\n");
|
|
41
41
|
await executeCommand("npx", [
|
|
@@ -85,7 +85,7 @@ class AuthMiddleware
|
|
|
85
85
|
{
|
|
86
86
|
$pattern = strtolower($pattern);
|
|
87
87
|
$requestUri = strtolower(trim($requestUri));
|
|
88
|
-
$regex = "#^/?" . preg_quote($pattern, '#') . "
|
|
88
|
+
$regex = "#^/?" . preg_quote($pattern, '#') . "(/.*)?$#";
|
|
89
89
|
return preg_match($regex, $requestUri);
|
|
90
90
|
}
|
|
91
91
|
}
|