From 3f5d9bce892f446fd5ac4029c9b2690c34a59773 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20K=C3=B6rner?= Date: Mon, 4 Dec 2023 13:59:25 +0100 Subject: [PATCH] load contao framework on cache warmup --- CHANGELOG.md | 3 +++ src/Cache/TemplateCache.php | 17 ++++++++--------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d0380d5..e124e0b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,9 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [1.6.2] - 20223-12-04 +- Fixed: possible exception on cache warmup + ## [1.6.1] - 20223-11-23 - Fixed: templates in project /contao/templates folder not found diff --git a/src/Cache/TemplateCache.php b/src/Cache/TemplateCache.php index 7d22655..202401e 100644 --- a/src/Cache/TemplateCache.php +++ b/src/Cache/TemplateCache.php @@ -8,6 +8,7 @@ namespace HeimrichHannot\TwigSupportBundle\Cache; +use Contao\CoreBundle\Framework\ContaoFramework; use HeimrichHannot\TwigSupportBundle\Filesystem\TwigTemplateLocator; use Symfony\Component\Cache\Adapter\FilesystemAdapter; use Symfony\Component\HttpKernel\CacheClearer\CacheClearerInterface; @@ -19,22 +20,18 @@ class TemplateCache implements CacheWarmerInterface, CacheClearerInterface public const TEMPLATES_WITH_EXTENSION_CACHE_KEY = 'templates_with_extension'; public const TEMPLATES_WITHOUT_EXTENSION_CACHE_KEY = 'templates_without_extension'; - /** - * @var TwigTemplateLocator - */ - protected $templateLocator; - /** - * @var FilesystemAdapter - */ - protected $templateCache; + protected TwigTemplateLocator $templateLocator; + protected FilesystemAdapter $templateCache; + private ContaoFramework $contaoFramework; /** * TemplateCacheWarmer constructor. */ - public function __construct(TwigTemplateLocator $templateLocator, FilesystemAdapter $templateCache) + public function __construct(TwigTemplateLocator $templateLocator, FilesystemAdapter $templateCache, ContaoFramework $contaoFramework) { $this->templateLocator = $templateLocator; $this->templateCache = $templateCache; + $this->contaoFramework = $contaoFramework; } public function isOptional() @@ -44,6 +41,8 @@ public function isOptional() public function warmUp($cacheDir) { + $this->contaoFramework->initialize(); + $this->templateCache->save( $this->templateCache ->getItem(static::TEMPLATES_WITH_EXTENSION_CACHE_KEY)