Files
lean/meta/definitions/http.php
T

59 lines
2.3 KiB
PHP

<?php
use Lean\ApplicationStrategy\{ ThrowableHandler, ThrowableHandlerInterface, NotFoundDecoratorInterface, NotFoundDecorator, MethodNotAllowedInterface, };
use Psr\Container\ContainerInterface;
use Psr\Http\Message\ServerRequestInterface;
use Laminas\{ Diactoros\ServerRequestFactory, HttpHandlerRunner\Emitter\EmitterInterface, HttpHandlerRunner\Emitter\SapiEmitter };
use Lean\Factory\{ HttpFactory, HttpFactoryInterface };
use Picea\Picea;
use Storage\Cookie,
Storage\Session,
Storage\SessionMiddleware;
use function DI\{ autowire, create, get };
return [
ServerRequestInterface::class => function ($c) {
return ServerRequestFactory::fromGlobals(
$_SERVER, $_GET, $_POST, $_COOKIE, $_FILES
);
},
EmitterInterface::class => create(SapiEmitter::class),
ThrowableHandlerInterface::class => autowire(ThrowableHandler::class),
NotFoundDecoratorInterface::class => autowire(NotFoundDecorator::class),
# MethodNotAllowedInterface::class => autowire(MethodNotAllowedDecorator::class),
HttpFactoryInterface::class => create(HttpFactory::class),
Cookie::class => create(Cookie::class)->constructor([
'secure' => true,
'path' => getenv('URL_BASE') ?: '/',
'httponly' => true,
'samesite'=> "Lax",
], getenv("LEAN_RANDOM")),
Session::class => create(Session::class)->constructor(get(Cookie::class), [ 'path' => getenv('URL_BASE') ?: '/', ]),
SessionMiddleware::class => create(SessionMiddleware::class)->constructor(get(Cookie::class), [
'name' => "lean_sess_" . substr(md5(getenv("LEAN_RANDOM")), 0, 12),
'path' => getenv('URL_BASE') ?: '/',
'samesite' => getenv("LEAN_COOKIE_SAMESITE") ?? "Lax",
'secure' => (bool) getenv('LEAN_COOKIE_SECURE') ?? false
]),
'error.401' => function(ContainerInterface $c, Picea $picea) {
return $c->get(HttpFactoryInterface::class)::createHtmlResponse($picea->renderHtml("lean/error/401", []), 401);
},
'error.404' => function(ContainerInterface $c, Picea $picea) {
return $c->get(HttpFactoryInterface::class)::createHtmlResponse($picea->renderHtml("lean/error/404", []), 404);
},
'error.500' => function(ContainerInterface $c, Picea $picea) {
return $c->get(HttpFactoryInterface::class)::createHtmlResponse($picea->renderHtml("lean/error/500", []), 500);
},
];