-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use ErrorRenderer to be compatible with new Twig-less error rendering
- Loading branch information
1 parent
74d6c70
commit b121a7a
Showing
21 changed files
with
480 additions
and
263 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
|
||
declare(strict_types = 1); | ||
|
||
namespace VasekPurchart\TracyBlueScreenBundle\BlueScreen; | ||
|
||
use Symfony\Component\ErrorHandler\ErrorRenderer\ErrorRendererInterface; | ||
use Tracy\BlueScreen; | ||
|
||
class BlueScreenErrorRenderer implements \Symfony\Component\ErrorHandler\ErrorRenderer\ErrorRendererInterface | ||
{ | ||
|
||
/** @var \Tracy\BlueScreen */ | ||
private $blueScreen; | ||
|
||
/** @var bool|\Closure */ | ||
private $debug; | ||
|
||
/** @var \Symfony\Component\ErrorHandler\ErrorRenderer\ErrorRendererInterface */ | ||
private $fallbackErrorRenderer; | ||
|
||
/** | ||
* @param \Tracy\BlueScreen $blueScreen | ||
* @param bool|\Closure $debug | ||
* @param \Symfony\Component\ErrorHandler\ErrorRenderer\ErrorRendererInterface $fallbackErrorRenderer | ||
*/ | ||
public function __construct( | ||
BlueScreen $blueScreen, | ||
$debug, | ||
ErrorRendererInterface $fallbackErrorRenderer | ||
) | ||
{ | ||
$this->blueScreen = $blueScreen; | ||
$this->debug = $debug; | ||
$this->fallbackErrorRenderer = $fallbackErrorRenderer; | ||
} | ||
|
||
public function render(\Throwable $exception): \Symfony\Component\ErrorHandler\Exception\FlattenException | ||
{ | ||
if (!$this->isDebug()) { | ||
return $this->fallbackErrorRenderer->render($exception); | ||
} | ||
|
||
return \Symfony\Component\ErrorHandler\Exception\FlattenException::createFromThrowable($exception) | ||
->setAsString($this->getBlueScreenAsString($exception)); | ||
} | ||
|
||
private function getBlueScreenAsString(\Throwable $exception): string | ||
{ | ||
ob_start(); | ||
ob_start(); // double buffer prevents sending HTTP headers in some PHP | ||
|
||
$this->blueScreen->render($exception); | ||
|
||
$result = ob_get_clean(); | ||
ob_end_clean(); | ||
|
||
return $result; | ||
} | ||
|
||
private function isDebug(): bool | ||
{ | ||
return is_bool($this->debug) ? $this->debug : ($this->debug)(); | ||
} | ||
|
||
} |
This file was deleted.
Oops, something went wrong.
This file contains 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
34 changes: 34 additions & 0 deletions
34
src/DependencyInjection/ReplaceErrorControllerErrorRendererCompilerPass.php
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
declare(strict_types = 1); | ||
|
||
namespace VasekPurchart\TracyBlueScreenBundle\DependencyInjection; | ||
|
||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Reference; | ||
use Symfony\Component\HttpKernel\Controller\ErrorController; | ||
|
||
class ReplaceErrorControllerErrorRendererCompilerPass implements \Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface | ||
{ | ||
|
||
public function process(ContainerBuilder $container): void | ||
{ | ||
if ( | ||
!$container->hasParameter('vasek_purchart.tracy_blue_screen.controller.enabled') | ||
|| !$container->getParameter('vasek_purchart.tracy_blue_screen.controller.enabled') | ||
) { | ||
return; | ||
} | ||
|
||
$errorControllerDefinition = $container->findDefinition('error_controller'); | ||
if ($errorControllerDefinition->getClass() !== ErrorController::class) { | ||
throw new \VasekPurchart\TracyBlueScreenBundle\DependencyInjection\CannotReplaceErrorRendererForNonDefaultErrorControllerException($errorControllerDefinition->getClass()); | ||
} | ||
|
||
$errorControllerDefinition->setArgument( | ||
'$errorRenderer', | ||
new Reference('vasek_purchart.tracy_blue_screen.blue_screen.error_renderer') | ||
); | ||
} | ||
|
||
} |
This file contains 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
This file was deleted.
Oops, something went wrong.
This file contains 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
40 changes: 40 additions & 0 deletions
40
...yInjection/exceptions/CannotReplaceErrorRendererForNonDefaultErrorControllerException.php
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
declare(strict_types = 1); | ||
|
||
namespace VasekPurchart\TracyBlueScreenBundle\DependencyInjection; | ||
|
||
use Symfony\Component\HttpKernel\Controller\ErrorController; | ||
|
||
class CannotReplaceErrorRendererForNonDefaultErrorControllerException extends \Exception | ||
{ | ||
|
||
/** @var string */ | ||
private $customErrorControllerClass; | ||
|
||
public function __construct( | ||
string $errorControllerClass, | ||
?\Throwable $previous = null | ||
) | ||
{ | ||
parent::__construct(sprintf( | ||
'Automatic error renderer replacement is available only for default error controller (%s), currently %s is used.' . PHP_EOL | ||
. 'You can:' . PHP_EOL | ||
. '1) Use the default error controller (%s)' . PHP_EOL | ||
. '2) Use the provided BlueScreen error renderer in your current error controller (%s). Just pass the prepared `vasek_purchart.tracy_blue_screen.blue_screen.error_renderer` DI service.' . PHP_EOL | ||
. '3) If you do not want to use BlueScreen for requests, disable `controller` in this bundles configuration (you can still use the `console` part independently)', | ||
ErrorController::class, | ||
$errorControllerClass, | ||
ErrorController::class, | ||
$errorControllerClass | ||
), 0, $previous); | ||
|
||
$this->customErrorControllerClass = $errorControllerClass; | ||
} | ||
|
||
public function getCustomErrorControllerClass(): string | ||
{ | ||
return $this->customErrorControllerClass; | ||
} | ||
|
||
} |
Oops, something went wrong.