diff --git a/SubModules/Templates/Middlewares/TemplateLoaderMiddleware.php b/SubModules/Templates/Middlewares/TemplateLoaderMiddleware.php deleted file mode 100644 index 3f9153f..0000000 --- a/SubModules/Templates/Middlewares/TemplateLoaderMiddleware.php +++ /dev/null @@ -1,53 +0,0 @@ -getContainer()) - ?->getTemplateRule() - ->getActive(); - $file = null; - if ($active) { - $file = $active->getTemplateDirectory() . DIRECTORY_SEPARATOR . 'templates.php'; - if (is_file($file)) { - try { - (fn($file) => include_once $file)->call($active, $file); - } catch (Throwable $e) { - $logger = ContainerHelper::use( - LoggerInterface::class, - $this->getContainer() - ); - $logger->notice($e, context: ['mode' => 'templates_include']); - throw $e; - } - } - } - $this->getManager()->dispatch( - 'templates.templateFileLoaded', - $active, - $file - ); - return $request; - } -} diff --git a/SubModules/Templates/Templates.php b/SubModules/Templates/Templates.php index cb4a2b9..fd9f3f3 100644 --- a/SubModules/Templates/Templates.php +++ b/SubModules/Templates/Templates.php @@ -5,8 +5,8 @@ use ArrayAccess\TrayDigita\App\Modules\Core\Abstracts\CoreSubmoduleAbstract; use ArrayAccess\TrayDigita\App\Modules\Core\SubModules\Option\Option; -use ArrayAccess\TrayDigita\App\Modules\Core\SubModules\Templates\Middlewares\TemplateLoaderMiddleware; use ArrayAccess\TrayDigita\Kernel\Interfaces\KernelInterface; +use ArrayAccess\TrayDigita\Templates\Middlewares\TemplateLoaderMiddleware; use ArrayAccess\TrayDigita\Templates\Wrapper; use ArrayAccess\TrayDigita\Util\Filter\ContainerHelper; use ArrayAccess\TrayDigita\View\Interfaces\ViewInterface; @@ -66,7 +66,7 @@ private function initSetTemplate(KernelInterface $kernel): void } $this->templateRule = new TemplateRule($wrapper); $this->templateRule->initialize(); - $view?->setTemplateRule($this->templateRule); + $view->setTemplateRule($this->templateRule); $option = $this->getModules()->get(Option::class); $active = $option?->get(self::ACTIVE_TEMPLATE_KEY)?->getValue(); @@ -81,15 +81,14 @@ private function initSetTemplate(KernelInterface $kernel): void $view->setViewsDirectory([]); } - // add middleware to load templates.php - try { - $kernel->getHttpKernel()->addMiddleware( - ContainerHelper::resolveCallable( - TemplateLoaderMiddleware::class, - $this->getContainer() - ) - ); - } catch (Throwable $e) { - } + /** + * add middleware to load templates.php + * @see TemplateLoaderMiddleware::doProcess() + */ + $kernel->getHttpKernel()->addMiddleware( + new TemplateLoaderMiddleware( + $view->getContainer()??$this->getContainer() + ) + ); } }