lean/src/ApplicationStrategy.php

52 lines
1.5 KiB
PHP
Raw Normal View History

<?php
namespace Lean;
use League\Route\Strategy;
use League\Route\Http\Exception\NotFoundException;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Picea\Picea;
use Psr\Http\Server\RequestHandlerInterface;
class ApplicationStrategy extends Strategy\ApplicationStrategy {
static array $asset_ext = [
"js", "mjs", "manifest", "webmanifest", "css", "png", "ico",
"jpg", "jpeg", "gif", "webp", "woff", "woff2", "eot", "svg",
"ttf"
];
public function __construct(
public Picea $picea
) {}
public function getNotFoundDecorator(NotFoundException $exception): MiddlewareInterface
{
return new class($this->picea) implements MiddlewareInterface {
protected Picea $picea;
public function __construct(Picea $picea)
{
$this->picea = $picea;
}
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
return $this->throw404($request);
}
public function throw404(ServerRequestInterface $request) : ResponseInterface
{
if ( class_exists(\Picea\Asset\Asset::class) ) {
}
return new \Laminas\Diactoros\Response\HtmlResponse($this->picea->renderHtml("lean/error/404", [], $this), 404);
}
};
}
}