Created
April 7, 2021 13:55
-
-
Save 4n70w4/39cc0441eea9c6b94512ff2443009bf8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Exceptions\Displayer\Classic; | |
use App\Exceptions\Displayer\Traits\ContentTypeTextHtml; | |
use App\Exceptions\Displayer\Traits\VerboseFalse; | |
use Exception; | |
use GrahamCampbell\Exceptions\Displayer\DisplayerInterface; | |
use Illuminate\Auth\AuthenticationException; | |
use Illuminate\Http\Request; | |
use Illuminate\Routing\Router; | |
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface; | |
class SelfRenderedDisplayer implements DisplayerInterface { | |
use ContentTypeTextHtml; | |
use VerboseFalse; | |
/** | |
* The request instance. | |
* | |
* @var \Illuminate\Http\Request | |
*/ | |
protected $request; | |
protected Router $router; | |
protected $response; | |
/** | |
* Create a new redirect displayer instance. | |
* | |
* @param \Illuminate\Http\Request $request | |
* | |
* @return void | |
*/ | |
public function __construct(Request $request, Router $router) { | |
$this->request = $request; | |
$this->router = $router; | |
} | |
/** | |
* Get the error response associated with the given exception. | |
* | |
* @param \Throwable $exception | |
* @param string $id | |
* @param int $code | |
* @param string[] $headers | |
* | |
* @return \Symfony\Component\HttpFoundation\Response | |
*/ | |
public function display(\Throwable $exception, string $id, int $code, array $headers) { | |
return $this->router->toResponse($this->request, $this->response); | |
} | |
/** | |
* Can we display the exception? | |
* | |
* @param \Throwable $original | |
* @param \Throwable $transformed | |
* @param int $code | |
* | |
* @return bool | |
*/ | |
public function canDisplay(\Throwable $original, \Throwable $transformed, int $code) { | |
return method_exists($transformed, 'render') && $this->response = $transformed->render($this->request); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment