create-prisma-php-app 1.22.2 → 1.22.4

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';
@@ -1,4 +1,3 @@
1
- version: "3.8"
2
1
  services:
3
2
  web:
4
3
  build:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-prisma-php-app",
3
- "version": "1.22.2",
3
+ "version": "1.22.4",
4
4
  "description": "Prisma-PHP: A Revolutionary Library Bridging PHP with Prisma ORM",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",