Initial commit
Some checks failed
PHP Composer / build (push) Has been cancelled

This commit is contained in:
Armel van Ravels
2024-08-30 20:29:39 +02:00
commit 804a875aff
38 changed files with 7224 additions and 0 deletions

48
src/Http/Kernel.php Normal file
View File

@@ -0,0 +1,48 @@
<?php
declare(strict_types=1);
namespace App\Http;
use App\Core\EnvironmentLoader;
use App\Enums\Environment;
use Laminas\Diactoros\ServerRequest;
use Laminas\HttpHandlerRunner\Emitter\SapiEmitter;
use League\Route\Router;
use Whoops\Handler\PrettyPageHandler;
use Whoops\Run;
/** @codeCoverageIgnore */
final readonly class Kernel
{
public function __construct(
private EnvironmentLoader $environmentLoader,
private ExceptionHandler $exceptionHandler,
private ServerRequest $serverRequest,
private Router $router,
private SapiEmitter $sapiEmitter,
) {
}
public function run(): void
{
$this->environmentLoader->load();
$this->setExceptionHandler();
$response = $this->router->dispatch($this->serverRequest);
$this->sapiEmitter->emit($response);
}
private function setExceptionHandler(): void
{
if (Environment::Production->isCurrent()) {
set_exception_handler($this->exceptionHandler->handle(...));
return;
}
$whoops = new Run();
$whoops->pushHandler(new PrettyPageHandler());
$whoops->register();
}
}