/** * Convert the view to a rendered string. * * @return string A string of HTML, e.g. to be `echo`'d. */ public function __toString() { static $run, $handler; if (!isset($run, $handler)) { $run = new Run(); $handler = new PrettyPageHandler(); $handler->handleUnconditionally(true); $run->pushHandler($handler); $run->allowQuit(false); $run->writeToOutput(false); $run->register(); } // __toString cannot throw an exception, so we need to handle those // manually to prevent PHP from barfing: try { return $this->render(); } catch (Exception $e) { self::$didWhoops = true; if (!static::$swallowError) { return $run->handleException($e); } else { return static::$swallowError; } } }
/** * @return Whoops\Handler\JsonResponseHandler */ private function getHandler() { $handler = new PrettyPageHandler(); $handler->handleUnconditionally(); return $handler; }
<?php declare (strict_types=1); use function DI\get; use Interop\Container\ContainerInterface; use Psr\Log\LoggerInterface; use Psr\Log\NullLogger; use Stratify\ErrorHandlerModule\ErrorHandlerMiddleware; use Stratify\ErrorHandlerModule\ErrorResponder\ErrorResponder; use Stratify\ErrorHandlerModule\ErrorResponder\SimpleProductionResponder; use Stratify\ErrorHandlerModule\ErrorResponder\WhoopsResponder; use Whoops\Handler\PrettyPageHandler; use Whoops\Run; return [ErrorHandlerMiddleware::class => function (ContainerInterface $c) { $logger = $c->has(LoggerInterface::class) ? $c->get(LoggerInterface::class) : new NullLogger(); return new ErrorHandlerMiddleware($c->get(ErrorResponder::class), $logger); }, ErrorResponder::class => get(SimpleProductionResponder::class), WhoopsResponder::class => DI\object()->constructor(get('error_handler.whoops')), 'error_handler.whoops' => function () { $whoops = new Run(); $whoops->writeToOutput(false); $whoops->allowQuit(false); $handler = new PrettyPageHandler(); $handler->handleUnconditionally(true); $whoops->pushHandler($handler); return $whoops; }];