create-prisma-php-app 1.11.12 → 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.
package/dist/bootstrap.php
CHANGED
|
@@ -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
|
-
|
|
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
|
|
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
|
|
242
|
+
return $segmentMatch;
|
|
229
243
|
}
|
|
230
244
|
}
|
|
231
245
|
}
|
|
232
|
-
return
|
|
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
|
|
|
@@ -72,7 +72,7 @@ class AuthMiddleware
|
|
|
72
72
|
$roleBasedRoutes = AuthConfig::$roleBasedRoutes ?? [];
|
|
73
73
|
foreach ($roleBasedRoutes as $pattern => $data) {
|
|
74
74
|
if (self::getUriRegex($pattern, $requestUri)) {
|
|
75
|
-
$userRole = $auth->getPayload()
|
|
75
|
+
$userRole = Auth::ROLE_NAME ? $auth->getPayload()[Auth::ROLE_NAME] : $auth->getPayload();
|
|
76
76
|
if ($userRole !== null && AuthConfig::checkAuthRole($userRole, $data[AuthConfig::ROLE_IDENTIFIER])) {
|
|
77
77
|
return true;
|
|
78
78
|
}
|