create-prisma-php-app 1.11.13 → 1.11.14

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.
Files changed (2) hide show
  1. package/dist/bootstrap.php +20 -5
  2. package/package.json +1 -1
@@ -146,17 +146,20 @@ function findGroupFolder($uri): string
146
146
  function dynamicRoute($uri)
147
147
  {
148
148
  global $filesListRoutes;
149
+ global $dynamicRouteParams;
149
150
  $uriMatch = null;
150
151
  $normalizedUri = ltrim(str_replace('\\', '/', $uri), './');
151
152
  $normalizedUriEdited = "src/app/$normalizedUri/route.php";
152
153
  $uriSegments = explode('/', $normalizedUriEdited);
153
-
154
154
  foreach ($filesListRoutes as $route) {
155
155
  $normalizedRoute = trim(str_replace('\\', '/', $route), '.');
156
156
  $routeSegments = explode('/', ltrim($normalizedRoute, '/'));
157
157
  $singleDynamic = preg_match_all('/\[[^\]]+\]/', $normalizedRoute, $matches) === 1 && !strpos($normalizedRoute, '[...');
158
158
  if ($singleDynamic) {
159
- if (singleDynamicRoute($uriSegments, $routeSegments)) {
159
+ $segmentMatch = singleDynamicRoute($uriSegments, $routeSegments);
160
+ if (!empty($segmentMatch)) {
161
+ $trimSegmentMatch = trim($segmentMatch, '[]');
162
+ $dynamicRouteParams = [$trimSegmentMatch => $uriSegments[array_search($segmentMatch, $routeSegments)]];
160
163
  $uriMatch = $normalizedRoute;
161
164
  break;
162
165
  }
@@ -164,6 +167,15 @@ function dynamicRoute($uri)
164
167
  $cleanedRoute = preg_replace('/\[\.\.\..*?\].*/', '', $normalizedRoute);
165
168
  if (strpos('/src/app/' . $normalizedUri, $cleanedRoute) === 0) {
166
169
  if (strpos($normalizedRoute, 'route.php') !== false) {
170
+ $normalizedUriEdited = "src/app/$normalizedUri";
171
+ $trimNormalizedUriEdited = trim($normalizedUriEdited, $cleanedRoute);
172
+ $explodedNormalizedUri = explode('/', $trimNormalizedUriEdited);
173
+ $pattern = '/\[\.\.\.(.*?)\]/';
174
+ if (preg_match($pattern, $normalizedRoute, $matches)) {
175
+ $contentWithinBrackets = $matches[1];
176
+ $dynamicRouteParams = [$contentWithinBrackets => $explodedNormalizedUri];
177
+ }
178
+
167
179
  $uriMatch = $normalizedRoute;
168
180
  break;
169
181
  }
@@ -217,19 +229,21 @@ function getGroupFolder($uri): string
217
229
 
218
230
  function singleDynamicRoute($uriSegments, $routeSegments)
219
231
  {
232
+ $segmentMatch = "";
220
233
  if (count($routeSegments) != count($uriSegments)) {
221
- return false;
234
+ return $segmentMatch;
222
235
  }
223
236
 
224
237
  foreach ($routeSegments as $index => $segment) {
225
238
  if (preg_match('/^\[[^\]]+\]$/', $segment)) {
239
+ return "{$segment}";
226
240
  } else {
227
241
  if ($segment !== $uriSegments[$index]) {
228
- return false;
242
+ return $segmentMatch;
229
243
  }
230
244
  }
231
245
  }
232
- return true;
246
+ return $segmentMatch;
233
247
  }
234
248
 
235
249
  function checkForDuplicateRoutes()
@@ -297,6 +311,7 @@ $filesListRoutes = [];
297
311
  $metadata = "";
298
312
  $uri = "";
299
313
  $pathname = "";
314
+ $dynamicRouteParams = [];
300
315
  $content = "";
301
316
  $childContent = "";
302
317
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-prisma-php-app",
3
- "version": "1.11.13",
3
+ "version": "1.11.14",
4
4
  "description": "Prisma-PHP: A Revolutionary Library Bridging PHP with Prisma ORM",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",