From 4dcc7f407e99ae2928f63593292e85315e89fae3 Mon Sep 17 00:00:00 2001 From: Dave Mc Nicoll Date: Mon, 16 Oct 2023 13:58:51 -0400 Subject: [PATCH] - WIP on picea-asset AND fixing ApplicationStrategy allowing PHP-DI caching --- meta/definitions/routes.php | 30 +------------------- meta/definitions/template.php | 17 ++++++++++-- src/ApplicationStrategy.php | 52 +++++++++++++++++++++++++++++++++++ src/Kernel.php | 4 +-- 4 files changed, 70 insertions(+), 33 deletions(-) create mode 100644 src/ApplicationStrategy.php diff --git a/meta/definitions/routes.php b/meta/definitions/routes.php index d564003..12540f2 100644 --- a/meta/definitions/routes.php +++ b/meta/definitions/routes.php @@ -51,35 +51,7 @@ return [ return $breadcrumb; }, - ApplicationStrategy::class => function($c) { - return new class($c->get(Picea\Picea::class)) extends ApplicationStrategy { - - public Picea\Picea $picea; - - public function __construct(Picea\Picea $picea) { - $this->picea = $picea; - } - - public function getNotFoundDecorator(NotFoundException $exception): MiddlewareInterface - { - return new class($this->picea) implements MiddlewareInterface { - - protected Picea\Picea $picea; - - public function __construct(Picea\Picea $picea) { - $this->picea = $picea; - } - - public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface - { - return new Laminas\Diactoros\Response\HtmlResponse($this->picea->renderHtml("lean/error/404", [], $this), 404); - } - - }; - } - - }; - }, + ApplicationStrategy::class => autowire(\Lean\ApplicationStrategy::class), 'routes.middlewares' => [ "dump", "errorHandler", SessionMiddleware::class, CronardMiddleware::class, Mcnd\Event\EventMiddleware::class, Mcnd\CLI\CliMiddleware::class, ], diff --git a/meta/definitions/template.php b/meta/definitions/template.php index ba0961f..c4be788 100644 --- a/meta/definitions/template.php +++ b/meta/definitions/template.php @@ -4,10 +4,19 @@ use function DI\autowire, DI\create, DI\get; use Laminas\Diactoros\Response\HtmlResponse; -use Picea\{ Picea, Caching\Cache, Caching\Opcache, Compiler, Compiler\Context, Compiler\BaseContext, FileFetcher, Language\DefaultRegistrations, Method\Request }; +use Picea\{Asset\Action\InstallActionInterface, + Picea, + Caching\Cache, + Caching\Opcache, + Compiler, + Compiler\Context, + Compiler\BaseContext, + FileFetcher, + Language\DefaultRegistrations, + Method\Request}; use Picea\Extension\{ LanguageHandler, LanguageExtension, TitleExtension, NumberExtension, UrlExtension }; use Picea\Ui\{ Method, Ui }; -use Picea\Asset\Asset; +use Picea\Asset\{ Asset, Action }; return [ Picea::class => function($c) { @@ -79,4 +88,8 @@ return [ FileFetcher::class => function($c) { return new FileFetcher($c->get(Lean\Lean::class)->getViewPaths()); }, + + Action\Install::class => autowire(Action\Install::class), + Action\Symlink::class => autowire(Action\Symlink::class), + Action\InstallActionInterface::class => create(Action\Symlink::class), ]; \ No newline at end of file diff --git a/src/ApplicationStrategy.php b/src/ApplicationStrategy.php new file mode 100644 index 0000000..f92ef64 --- /dev/null +++ b/src/ApplicationStrategy.php @@ -0,0 +1,52 @@ +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); + } + }; + } +} \ No newline at end of file diff --git a/src/Kernel.php b/src/Kernel.php index d99ebe0..492e6e2 100644 --- a/src/Kernel.php +++ b/src/Kernel.php @@ -110,8 +110,8 @@ class Kernel { if (getenv("APP_ENV") === "prod") { if (getenv("CACHE_PATH")) { - # $containerBuilder->enableCompilation(getenv("CACHE_PATH") . "/di/"); - # $containerBuilder->writeProxiesToFile(true); + $containerBuilder->enableCompilation(getenv("CACHE_PATH") . "/di/"); + $containerBuilder->writeProxiesToFile(true, getenv("CACHE_PATH") . "/di/proxies/"); } }