diff --git a/meta/definitions/authorize.php b/meta/definitions/authorize.php index 0545d02..b5fbecd 100644 --- a/meta/definitions/authorize.php +++ b/meta/definitions/authorize.php @@ -1,17 +1,46 @@ create(AuthorizeMiddleware::class)->constructor(get('authorize.error')), + Authenticate::class => create(Authenticate::class)->constructor(get(Session::class), get(Cookie::class), get('authentication.method')), + + HeaderAuthenticationMiddleware::class => create(HeaderAuthenticationMiddleware::class)->constructor(get(Entity\UserInterface::class), get('authorize.error')), + + PostRequestAuthentication::class => create(PostRequestAuthentication::class)->constructor(get(\Ulmus\User\Lib\Authenticate::class), "email", "email", "password"), + + PostRequestAuthenticationMiddleware::class => create(PostRequestAuthenticationMiddleware::class)->constructor(get(Entity\UserInterface::class), get('authentication.error'), get(PostRequestAuthentication::class)), + + 'authentication.method' => null, 'authorize.error' => function($c) { - return HttpFactory::createJsonResponse([ - 'api.error' => "Authorization failed", - 'api.datetime' => ( new \DateTime )->format(\DateTime::ATOM), - ]); + return function(array $errorData) { + return HttpFactory::createJsonResponse($errorData + [ + 'api.error' => "Authorization failed", + 'api.datetime' => (new \DateTime)->format(\DateTime::ATOM), + ]); + }; + }, + + 'authentication.error' => function($c, Picea $picea) { + return function($message) use ($picea) { + return HttpFactory::createHtmlResponse($picea->renderHtml('lean/error/500', [ + 'title' => "Authentication failed", + 'subtitle' => "", + 'message' => $message, + ])); + }; }, ]; \ No newline at end of file diff --git a/meta/definitions/cli.php b/meta/definitions/cli.php index c6237cd..903aedf 100644 --- a/meta/definitions/cli.php +++ b/meta/definitions/cli.php @@ -8,7 +8,7 @@ use Mcnd\CLI\CliMiddleware; use Notes\CLI\CommandFetcher; -use Lean\Lean; +use Lean\{ Factory, Lean }; return [ CommandFetcher::class => function($c) { @@ -27,7 +27,7 @@ return [ 'cli.response:default' => function($c) { return function() { - return new \Laminas\Diactoros\Response\TextResponse("This is the default response from CLI middleware which indicates that no command were registered for this application.\n"); + return Factory\HttpFactory::createTextResponse("This is the default response from CLI middleware which indicates that no command were registered for this application.\n"); }; }, ]; diff --git a/meta/definitions/cronard.php b/meta/definitions/cronard.php index 33fc66e..ee1fc5c 100644 --- a/meta/definitions/cronard.php +++ b/meta/definitions/cronard.php @@ -2,19 +2,17 @@ use function DI\autowire, DI\create, DI\get; -use Laminas\Diactoros\Response\HtmlResponse; - use Cronard\CronardMiddleware, Notes\Cronard\TaskFetcher; use Psr\Http\Message\ResponseInterface; -use Lean\Lean; +use Lean\{ Factory, Lean }; return [ CronardMiddleware::class => function($c) { $cronardMiddleware = new CronardMiddleware($c, getenv('CRON_KEY'), function() : ResponseInterface { - return new HtmlResponse(sprintf("%s - cron task begin...", date('Y-m-d H:i:s'))); + return Factory\HttpFactory::createHtmlResponse(sprintf("%s - cron task begin...", date('Y-m-d H:i:s'))); }, []); return $cronardMiddleware->fromFile(getenv("META_PATH")."/crontab.php")->fromAnnotations($c->get(TaskFetcher::class)); diff --git a/meta/definitions/event.php b/meta/definitions/event.php index 2e5fdd6..36bd99d 100644 --- a/meta/definitions/event.php +++ b/meta/definitions/event.php @@ -26,7 +26,7 @@ return [ Event\EventDefinition::class => function($c) { return new Event\EventDefinition([ new class() implements RoutingCompileRoutes { - public function execute(Routing $routing, Route|\Notes\Route\Annotation\Method\Route $attribute) : void + public function execute(Routing $routing, Route $attribute) : void { if (null !== ($name = $attribute->name ?? null)) { $routing->extension->registerRoute($name, $attribute->getRoute(), $attribute->class, $attribute->classMethod, $attribute->methods ?? (array)$attribute->method); @@ -35,7 +35,7 @@ return [ }, new class() implements RoutingMapRoutes { - public function execute(Routing $routing, ContainerInterface $container, ServerRequestInterface & $request, Route|\Notes\Route\Annotation\Method\Route $attribute) : void + public function execute(Routing $routing, ContainerInterface $container, ServerRequestInterface & $request, Route $attribute) : void { $class = $attribute->class; $method = $attribute->classMethod; diff --git a/meta/definitions/routes.php b/meta/definitions/routes.php index 7bcaa38..ee3e7a0 100644 --- a/meta/definitions/routes.php +++ b/meta/definitions/routes.php @@ -3,29 +3,16 @@ use function DI\autowire, DI\create, DI\get; use League\Route\Strategy\ApplicationStrategy, - League\Route\Http\Exception\NotFoundException, League\Route\Router; -use Psr\Http\Message\ResponseFactoryInterface, - Psr\Container\ContainerInterface, - Psr\Http\Message\ResponseInterface, - Psr\Http\Message\ServerRequestInterface, - Psr\Http\Server\MiddlewareInterface, - Psr\Http\Server\RequestHandlerInterface, - Psr\SimpleCache\CacheInterface; - -use TheBugs\JavascriptMiddleware; +use Psr\Container\ContainerInterface; use Cronard\CronardMiddleware; -use Tuupola\Middleware\HttpBasicAuthentication; - use Notes\Route\RouteFetcher; use Notes\Breadcrumb\Breadcrumb; -use Ulmus\User\Lib\Authenticate; - use Storage\SessionMiddleware; return [ diff --git a/meta/definitions/software.php b/meta/definitions/software.php index ddda44b..56bbc16 100644 --- a/meta/definitions/software.php +++ b/meta/definitions/software.php @@ -2,18 +2,10 @@ use function DI\autowire, DI\create, DI\get; -use Laminas\Diactoros\Response\HtmlResponse; - use TheBugs\JavascriptMiddleware; - -use Cronard\CronardMiddleware, - Notes\Cronard\TaskFetcher; - use Lean\Lean; -use Psr\Http\Message\ResponseInterface; - use Storage\Cookie, Storage\Session, Storage\SessionMiddleware; diff --git a/skeleton/meta/definitions/auth.php b/skeleton/meta/definitions/auth.php index 56e9f64..0b05eab 100644 --- a/skeleton/meta/definitions/auth.php +++ b/skeleton/meta/definitions/auth.php @@ -22,29 +22,15 @@ use TheBugs\Email\{ EmailConfiguration, MailerInterface, SwiftMailer }; use Taxus\{ Taxus, PermissionGrantInterface }; return [ - Entity\User::class => autowire(Entity\User::class), - - Authenticate::class => create(Authenticate::class)->constructor(get(Session::class), get(Cookie::class), get('authentication.method')), + \Ulmus\User\Entity\UserInterface::class => autowire(Entity\User::class), SecurityHandler::class => create(SecurityHandler::class)->constructor(function() { - return new RedirectResponse(getenv("URL_BASE")."/login"); + return Lean\Factory\HttpFactory::createRedirectResponse(getenv("URL_BASE")."/login"); }, get('authentication.unauthorize'), get(Taxus::class)), - 'authentication.method' => null, - - 'authentication.error' => function($c, Picea $picea) { - return function($message) use ($picea) { - return new HtmlResponse($picea->renderHtml('lean/error/500', [ - 'title' => "", - 'subtitle' => "", - 'message' => $message, - ])); - }; - }, - 'authentication.unauthorize' => function($c, Picea $picea) { return function($message) use ($picea) { - return new HtmlResponse($picea->renderHtml('lean/error/401', [ + return Lean\Factory\HttpFactory::createHtmlResponse($picea->renderHtml('lean/error/401', [ 'title' => "", 'subtitle' => "", 'message' => $message, diff --git a/src/Event/RoutingCompileRoutes.php b/src/Event/RoutingCompileRoutes.php index 5eda957..1a8f0a1 100644 --- a/src/Event/RoutingCompileRoutes.php +++ b/src/Event/RoutingCompileRoutes.php @@ -6,5 +6,5 @@ use Lean\Routing; use Notes\Route\Attribute\Method\Route; interface RoutingCompileRoutes { - public function execute(Routing $routing, Route|\Notes\Route\Annotation\Method\Route $attribute) : void; + public function execute(Routing $routing, Route $attribute) : void; } diff --git a/src/Event/RoutingMapRoutes.php b/src/Event/RoutingMapRoutes.php index 292ff0e..e448574 100644 --- a/src/Event/RoutingMapRoutes.php +++ b/src/Event/RoutingMapRoutes.php @@ -8,5 +8,5 @@ use Psr\Container\ContainerInterface; use Psr\Http\Message\{ ResponseInterface, ServerRequestInterface }; interface RoutingMapRoutes { - public function execute(Routing $routing, ContainerInterface $container, ServerRequestInterface & $request, Route|\Notes\Route\Annotation\Method\Route $attribute) : void; + public function execute(Routing $routing, ContainerInterface $container, ServerRequestInterface & $request, Route $attribute) : void; }