Skip to content

Commit

Permalink
load contao framework on cache warmup
Browse files Browse the repository at this point in the history
  • Loading branch information
koertho committed Dec 4, 2023
1 parent 9a56e6e commit 3f5d9bc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
17 changes: 8 additions & 9 deletions src/Cache/TemplateCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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()
Expand All @@ -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)
Expand Down

0 comments on commit 3f5d9bc

Please sign in to comment.