Skip to content

Commit

Permalink
Pass ErrorHandler to the RouteHandler.
Browse files Browse the repository at this point in the history
  • Loading branch information
map-g committed Sep 27, 2023
1 parent 7f64e51 commit 63328e5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,10 @@ public function __construct(...$middleware)
if ($needsAccessLog instanceof Container) {
\array_unshift($handlers, $needsAccessLog->getAccessLogHandler());
}

$this->router = new RouteHandler($container);
$errorHandler = \array_reduce($handlers, function ($carry, $handler) {
return $carry ?? ($handler instanceof ErrorHandler ? $handler : null);
});
$this->router = new RouteHandler($container, $errorHandler);
$handlers[] = $this->router;
$this->handler = new MiddlewareHandler($handlers);
$this->sapi = \PHP_SAPI === 'cli' ? new ReactiveHandler($container->getEnv('X_LISTEN')) : new SapiHandler();
Expand Down
4 changes: 2 additions & 2 deletions src/Io/RouteHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ class RouteHandler
/** @var Container */
private $container;

public function __construct(Container $container = null)
public function __construct(Container $container = null, ErrorHandler $errorHandler = null)
{
$this->routeCollector = new RouteCollector(new RouteParser(), new RouteGenerator());
$this->errorHandler = new ErrorHandler();
$this->errorHandler = $errorHandler ?? new ErrorHandler();
$this->container = $container ?? new Container();
}

Expand Down

0 comments on commit 63328e5

Please sign in to comment.