Skip to content

Commit 847cb3e

Browse files
authored
Merge pull request #655 from skipperbent/v5-development
Version 5.3.0.1
2 parents b937b61 + 2b4ae2b commit 847cb3e

File tree

1 file changed

+23
-19
lines changed

1 file changed

+23
-19
lines changed

src/Pecee/SimpleRouter/Router.php

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class Router
3535
* @var bool
3636
*/
3737
protected bool $isProcessingRoute;
38-
38+
3939
/**
4040
* Defines all data from current processing route.
4141
* @var ILoadableRoute
@@ -59,7 +59,7 @@ class Router
5959
* when a route is being processed.
6060
* @var array
6161
*/
62-
protected array$routeStack = [];
62+
protected array $routeStack = [];
6363

6464
/**
6565
* List of added bootmanagers
@@ -166,7 +166,7 @@ public function reset(): void
166166
public function addRoute(IRoute $route): IRoute
167167
{
168168
$this->fireEvents(EventHandler::EVENT_ADD_ROUTE, [
169-
'route' => $route,
169+
'route' => $route,
170170
'isSubRoute' => $this->isProcessingRoute,
171171
]);
172172

@@ -307,7 +307,7 @@ public function loadRoutes(): void
307307
$this->debug('Rendering bootmanager "%s"', $className);
308308
$this->fireEvents(EventHandler::EVENT_RENDER_BOOTMANAGER, [
309309
'bootmanagers' => $this->bootManagers,
310-
'bootmanager' => $manager,
310+
'bootmanager' => $manager,
311311
]);
312312

313313
/* Render bootmanager */
@@ -345,7 +345,7 @@ public function start(): ?string
345345
try {
346346
/* Verify csrf token for request */
347347
$this->csrfVerifier->handle($this->request);
348-
} catch(Exception $e) {
348+
} catch (Exception $e) {
349349
return $this->handleException($e);
350350
}
351351
}
@@ -381,7 +381,7 @@ public function routeRequest(): ?string
381381
foreach ($this->processedRoutes as $key => $route) {
382382

383383
$this->debug('Matching route "%s"', get_class($route));
384-
384+
385385
/* Add current processing route to constants */
386386
$this->currentProcessingRoute = $route;
387387

@@ -405,7 +405,7 @@ public function routeRequest(): ?string
405405
}
406406

407407
$this->fireEvents(EventHandler::EVENT_RENDER_MIDDLEWARES, [
408-
'route' => $route,
408+
'route' => $route,
409409
'middlewares' => $route->getMiddlewares(),
410410
]);
411411

@@ -443,8 +443,12 @@ public function routeRequest(): ?string
443443
}
444444
}
445445

446-
} catch (Exception $e) {
447-
return $this->handleException($e);
446+
} catch (\Throwable $e) {
447+
if ($e instanceof Exception) {
448+
return $this->handleException($e);
449+
}
450+
451+
return $this->handleException(new Exception($e->getMessage(), $e->getCode()));
448452
}
449453

450454
if ($methodNotAllowed === true) {
@@ -500,7 +504,7 @@ protected function handleRouteRewrite(string $key, string $url): ?string
500504
$this->request->setHasPendingRewrite(false);
501505

502506
$this->fireEvents(EventHandler::EVENT_REWRITE, [
503-
'rewriteUrl' => $this->request->getRewriteUrl(),
507+
'rewriteUrl' => $this->request->getRewriteUrl(),
504508
'rewriteRoute' => $this->request->getRewriteRoute(),
505509
]);
506510

@@ -521,7 +525,7 @@ protected function handleException(Exception $e): ?string
521525
$this->debug('Starting exception handling for "%s"', get_class($e));
522526

523527
$this->fireEvents(EventHandler::EVENT_LOAD_EXCEPTIONS, [
524-
'exception' => $e,
528+
'exception' => $e,
525529
'exceptionHandlers' => $this->exceptionHandlers,
526530
]);
527531

@@ -533,8 +537,8 @@ protected function handleException(Exception $e): ?string
533537
}
534538

535539
$this->fireEvents(EventHandler::EVENT_RENDER_EXCEPTION, [
536-
'exception' => $e,
537-
'exceptionHandler' => $handler,
540+
'exception' => $e,
541+
'exceptionHandler' => $handler,
538542
'exceptionHandlers' => $this->exceptionHandlers,
539543
]);
540544

@@ -556,7 +560,7 @@ protected function handleException(Exception $e): ?string
556560
$this->debug('Exception handler contains rewrite, reloading routes');
557561

558562
$this->fireEvents(EventHandler::EVENT_REWRITE, [
559-
'rewriteUrl' => $this->request->getRewriteUrl(),
563+
'rewriteUrl' => $this->request->getRewriteUrl(),
560564
'rewriteRoute' => $this->request->getRewriteRoute(),
561565
]);
562566

@@ -667,9 +671,9 @@ public function getUrl(?string $name = null, $parameters = null, ?array $getPara
667671
$this->debug('Finding url', func_get_args());
668672

669673
$this->fireEvents(EventHandler::EVENT_GET_URL, [
670-
'name' => $name,
674+
'name' => $name,
671675
'parameters' => $parameters,
672-
'getParams' => $getParams,
676+
'getParams' => $getParams,
673677
]);
674678

675679
if ($name === '' && $parameters === '') {
@@ -913,8 +917,8 @@ public function debug(string $message, ...$args): void
913917
$trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2);
914918
$this->debugList[] = [
915919
'message' => vsprintf($message, $args),
916-
'time' => number_format(microtime(true) - $this->debugStartTime, 10),
917-
'trace' => end($trace),
920+
'time' => number_format(microtime(true) - $this->debugStartTime, 10),
921+
'trace' => end($trace),
918922
];
919923
}
920924

@@ -940,7 +944,7 @@ public function getDebugLog(): array
940944
{
941945
return $this->debugList;
942946
}
943-
947+
944948
/**
945949
* Get the current processing route details.
946950
*

0 commit comments

Comments
 (0)