create-prisma-php-app 1.22.506 → 1.22.507

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.
@@ -188,29 +188,37 @@ function dynamicRoute($uri)
188
188
  $normalizedUri = ltrim(str_replace('\\', '/', $uri), './');
189
189
  $normalizedUriEdited = "src/app/$normalizedUri";
190
190
  $uriSegments = explode('/', $normalizedUriEdited);
191
+
191
192
  foreach ($_filesListRoutes as $route) {
192
193
  $normalizedRoute = trim(str_replace('\\', '/', $route), '.');
194
+
195
+ // Skip non-.php files to improve performance
196
+ if (pathinfo($normalizedRoute, PATHINFO_EXTENSION) !== 'php') {
197
+ continue;
198
+ }
199
+
193
200
  $routeSegments = explode('/', ltrim($normalizedRoute, '/'));
194
201
 
195
202
  $filteredRouteSegments = array_values(array_filter($routeSegments, function ($segment) {
196
203
  return !preg_match('/\(.+\)/', $segment); // Skip segments with parentheses (groups)
197
204
  }));
198
205
 
199
- $singleDynamic = preg_match_all('/\[[^\]]+\]/', $normalizedRoute, $matches) === 1 && !strpos($normalizedRoute, '[...');
206
+ $singleDynamic = preg_match_all('/\[[^\]]+\]/', $normalizedRoute, $matches) === 1 && strpos($normalizedRoute, '[...') === false;
207
+
200
208
  if ($singleDynamic) {
201
209
  $segmentMatch = singleDynamicRoute($uriSegments, $filteredRouteSegments);
202
210
  $index = array_search($segmentMatch, $filteredRouteSegments);
211
+
203
212
  if ($index !== false && isset($uriSegments[$index])) {
204
213
  $trimSegmentMatch = trim($segmentMatch, '[]');
205
214
  $dynamicRouteParams = new \ArrayObject([$trimSegmentMatch => $uriSegments[$index]], \ArrayObject::ARRAY_AS_PROPS);
215
+
206
216
  $dynamicRouteUri = str_replace($segmentMatch, $uriSegments[$index], $normalizedRoute);
207
217
  $dynamicRouteUri = preg_replace('/\(.+\)/', '', $dynamicRouteUri);
208
218
  $dynamicRouteUri = preg_replace('/\/+/', '/', $dynamicRouteUri);
209
- $dynamicRouteUriDirname = dirname($dynamicRouteUri);
210
- $dynamicRouteUriDirname = rtrim($dynamicRouteUriDirname, '/');
219
+ $dynamicRouteUriDirname = rtrim(dirname($dynamicRouteUri), '/');
211
220
 
212
- $expectedUri = '/src/app/' . $normalizedUri;
213
- $expectedUri = rtrim($expectedUri, '/');
221
+ $expectedUri = rtrim('/src/app/' . $normalizedUri, '/');
214
222
 
215
223
  if (strpos($normalizedRoute, 'route.php') !== false || strpos($normalizedRoute, 'index.php') !== false) {
216
224
  if ($expectedUri === $dynamicRouteUriDirname) {
@@ -221,9 +229,9 @@ function dynamicRoute($uri)
221
229
  }
222
230
  } elseif (strpos($normalizedRoute, '[...') !== false) {
223
231
  // Clean and normalize the route
224
- $cleanedNormalizedRoute = preg_replace('/\(.+\)/', '', $normalizedRoute); // Remove any public/private segment
225
- $cleanedNormalizedRoute = preg_replace('/\/+/', '/', $cleanedNormalizedRoute); // Replace multiple slashes
226
- $dynamicSegmentRoute = preg_replace('/\[\.\.\..*?\].*/', '', $cleanedNormalizedRoute); // Remove the dynamic segment
232
+ $cleanedNormalizedRoute = preg_replace('/\(.+\)/', '', $normalizedRoute);
233
+ $cleanedNormalizedRoute = preg_replace('/\/+/', '/', $cleanedNormalizedRoute);
234
+ $dynamicSegmentRoute = preg_replace('/\[\.\.\..*?\].*/', '', $cleanedNormalizedRoute);
227
235
 
228
236
  // Check if the normalized URI starts with the cleaned route
229
237
  if (strpos("/src/app/$normalizedUri", $dynamicSegmentRoute) === 0) {
@@ -364,7 +372,6 @@ function checkForDuplicateRoutes()
364
372
  }
365
373
  }
366
374
 
367
-
368
375
  function containsChildContent($filePath)
369
376
  {
370
377
  $fileContent = file_get_contents($filePath);
@@ -515,6 +522,7 @@ function getLoadingsFiles()
515
522
  $haveLoadingFileContent = array_reduce($loadingFiles, function ($carry, $route) use ($uri, $pathname, $dynamicRouteParams, $params, $referer) {
516
523
  $normalizeUri = str_replace('\\', '/', $route);
517
524
  $fileUrl = str_replace('./src/app', '', $normalizeUri);
525
+ $route = str_replace(['\\', './'], ['/', ''], $route);
518
526
 
519
527
  ob_start();
520
528
  include($route); // This will execute the PHP code in loading.php
@@ -535,8 +543,6 @@ function getLoadingsFiles()
535
543
  return '';
536
544
  }
537
545
 
538
-
539
-
540
546
  function getPrismaSettings(): \ArrayObject
541
547
  {
542
548
  $_prismaPHPSettingsFile = DOCUMENT_PATH . '/prisma-php.json';
@@ -593,6 +599,8 @@ function modifyOutputLayoutForError($contentToAdd)
593
599
  } else {
594
600
  echo $errorContent;
595
601
  }
602
+ } else {
603
+ echo $contentToAdd;
596
604
  }
597
605
  exit;
598
606
  }
@@ -628,12 +636,13 @@ register_shutdown_function(function () {
628
636
  }
629
637
  });
630
638
 
639
+ $_prismaPHPSettings = getPrismaSettings();
640
+ $_filesListRoutes = getFilesListRoutes();
641
+
631
642
  require_once SETTINGS_PATH . '/public-functions.php';
632
643
  require_once SETTINGS_PATH . '/request-methods.php';
633
644
  $_metadataFile = APP_PATH . '/metadata.php';
634
645
  $_metadataArray = file_exists($_metadataFile) ? require_once $_metadataFile : [];
635
- $_filesListRoutes = getFilesListRoutes();
636
- $_prismaPHPSettings = getPrismaSettings();
637
646
  $_fileToInclude = '';
638
647
 
639
648
  function authenticateUserToken()
@@ -683,7 +692,6 @@ $mainLayoutFooter = [];
683
692
 
684
693
  try {
685
694
  $_determineContentToInclude = determineContentToInclude();
686
- checkForDuplicateRoutes();
687
695
  $_contentToInclude = $_determineContentToInclude['path'] ?? '';
688
696
  $_layoutsToInclude = $_determineContentToInclude['layouts'] ?? [];
689
697
  $uri = $_determineContentToInclude['uri'] ?? '';
@@ -692,6 +700,9 @@ try {
692
700
  if (is_file($_contentToInclude)) {
693
701
  $_fileToInclude = basename($_contentToInclude); // returns the file name
694
702
  }
703
+ $metadata = $_metadataArray[$uri] ?? ($_metadataArray['default'] ?? []);
704
+
705
+ checkForDuplicateRoutes();
695
706
  authenticateUserToken();
696
707
 
697
708
  if (empty($_contentToInclude)) {
@@ -739,7 +750,6 @@ try {
739
750
  exit;
740
751
  }
741
752
 
742
- $metadata = $_metadataArray[$uri] ?? ($_metadataArray['default'] ?? []);
743
753
  $_parentLayoutPath = APP_PATH . '/layout.php';
744
754
  $_isParentLayout = !empty($_layoutsToInclude) && strpos($_layoutsToInclude[0], 'src/app/layout.php') !== false;
745
755
 
@@ -797,7 +807,8 @@ try {
797
807
  if ($_isContentIncluded) {
798
808
  echo "<div class='error'>The parent layout file does not contain &lt;?php echo \$content; ?&gt; Or &lt;?= \$content ?&gt;<br>" . "<strong>$_parentLayoutPath</strong></div>";
799
809
  } else {
800
- echo "<div class='error'>The layout file does not contain &lt;?php echo \$childContent; ?&gt; or &lt;?= \$childContent ?&gt;<br><strong>$layoutPath</strong></div>";
810
+ $errorDetails = "<div class='error'>The layout file does not contain &lt;?php echo \$childContent; ?&gt; or &lt;?= \$childContent ?&gt;<br><strong>$layoutPath</strong></div>";
811
+ modifyOutputLayoutForError($errorDetails);
801
812
  }
802
813
  }
803
814
  } catch (Throwable $e) {
@@ -1,4 +1,3 @@
1
- version: "3.8"
2
1
  services:
3
2
  web:
4
3
  build: