From bbccebb86d998ad48a442ba7bf82f9e2a53855dd Mon Sep 17 00:00:00 2001 From: ahmed abdelaal Date: Sun, 5 May 2024 03:11:43 +0300 Subject: [PATCH] add ability to override the default error view paths --- .../Foundation/Configuration/Exceptions.php | 11 +++++++++ .../Foundation/Exceptions/Handler.php | 23 +++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/src/Illuminate/Foundation/Configuration/Exceptions.php b/src/Illuminate/Foundation/Configuration/Exceptions.php index 532cb06d7e4f..b41921566ab4 100644 --- a/src/Illuminate/Foundation/Configuration/Exceptions.php +++ b/src/Illuminate/Foundation/Configuration/Exceptions.php @@ -29,6 +29,17 @@ public function report(callable $using) return $this->handler->reportable($using); } + /** + * Register error view paths callback. + * + * @param callable $using + * @return void + */ + public function registerErrorViewPathsUsing(callable $using) + { + $this->handler->registerErrorViewPathsUsing($using); + } + /** * Register a reportable callback. * diff --git a/src/Illuminate/Foundation/Exceptions/Handler.php b/src/Illuminate/Foundation/Exceptions/Handler.php index 7d049553737e..fddb8bfb792a 100644 --- a/src/Illuminate/Foundation/Exceptions/Handler.php +++ b/src/Illuminate/Foundation/Exceptions/Handler.php @@ -116,6 +116,13 @@ class Handler implements ExceptionHandlerContract */ protected $finalizeResponseCallback; + /** + * The callback that should be used to register the application's error view paths. + * + * @var callable|null + */ + protected $registerErrorViewPathsUsing; + /** * The registered exception mappings. * @@ -233,6 +240,17 @@ public function renderable(callable $renderUsing) return $this; } + /** + * Register error view paths callback. + * + * @param callable $using + * @return void + */ + public function registerErrorViewPathsUsing(callable $using) + { + $this->registerErrorViewPathsUsing = $using; + } + /** * Register a new exception mapping. * @@ -897,6 +915,11 @@ protected function renderHttpException(HttpExceptionInterface $e) */ protected function registerErrorViewPaths() { + if (! is_null($this->registerErrorViewPathsUsing)) { + call_user_func($this->registerErrorViewPathsUsing); + + return; + } (new RegisterErrorViewPaths)(); }