Adds proper safety for prod and added option for SSL
This commit is contained in:
parent
0962b609c4
commit
d67c4063e4
6 changed files with 50 additions and 33 deletions
42
src/php/CrashHandler.php
Normal file
42
src/php/CrashHandler.php
Normal file
|
@ -0,0 +1,42 @@
|
|||
<?php declare(strict_types=1);
|
||||
namespace GamesShop;
|
||||
|
||||
use GamesShop\Environment\EnvironmentHandler;
|
||||
use GamesShop\Templates\TemplateEngine;
|
||||
use League\Container\Container;
|
||||
use Whoops\Handler\CallbackHandler;
|
||||
use Whoops\Handler\HandlerInterface;
|
||||
use Whoops\Handler\PrettyPageHandler;
|
||||
use Whoops\Run;
|
||||
|
||||
final class CrashHandler
|
||||
{
|
||||
public function __construct(
|
||||
private readonly Container $container,
|
||||
private readonly EnvironmentHandler $env
|
||||
) { }
|
||||
|
||||
public function register() : void {
|
||||
$handler = $this->getHandler();
|
||||
$this->container->addShared(HandlerInterface::class, $handler);
|
||||
|
||||
$whoops = new Run();
|
||||
$whoops->pushHandler($handler);
|
||||
$whoops->register();
|
||||
}
|
||||
|
||||
private function getHandler(): HandlerInterface
|
||||
{
|
||||
if (!$this->env->isProduction()) {
|
||||
return new PrettyPageHandler();
|
||||
}
|
||||
|
||||
return new CallbackHandler(
|
||||
function ($exception, $inspector, $run) {
|
||||
http_response_code(500);
|
||||
echo ContainerHandler::get(TemplateEngine::class)
|
||||
->renderErrorPage(500);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue