• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

CPS-IT / handlebars / 25793409878

13 May 2026 10:28AM UTC coverage: 89.851% (+0.03%) from 89.818%
25793409878

push

github

web-flow
Merge pull request #574 from CPS-IT/fix/cache-identifier

[!!!][BUGFIX] Include more context in template cache identifier

37 of 40 new or added lines in 4 files covered. (92.5%)

1452 of 1616 relevant lines covered (89.85%)

7.21 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

93.1
/Classes/Cache/CacheContext.php
1
<?php
2

3
declare(strict_types=1);
4

5
/*
6
 * This file is part of the TYPO3 CMS extension "handlebars".
7
 *
8
 * It is free software; you can redistribute it and/or modify it under
9
 * the terms of the GNU General Public License, either version 2
10
 * of the License, or any later version.
11
 *
12
 * For the full copyright and license information, please read the
13
 * LICENSE.txt file that was distributed with this source code.
14
 *
15
 * The TYPO3 project - inspiring people to share!
16
 */
17

18
namespace CPSIT\Typo3Handlebars\Cache;
19

20
use Composer\InstalledVersions;
21
use DevTheorem\Handlebars;
22

23
/**
24
 * CacheContext
25
 *
26
 * @author Elias Häußler <e.haeussler@familie-redlich.de>
27
 * @license GPL-2.0-or-later
28
 */
29
final class CacheContext
30
{
31
    private ?string $cacheIdentifier = null;
32

33
    public function __construct(
4✔
34
        public readonly string $template,
35
        public readonly Handlebars\Options $options = new Handlebars\Options(),
36
    ) {}
4✔
37

38
    public function calculateCacheIdentifier(): string
3✔
39
    {
40
        if ($this->cacheIdentifier === null) {
3✔
41
            $this->cacheIdentifier = sha1(serialize($this->composeCacheIdentifierComponents()));
3✔
42
        }
43

44
        return $this->cacheIdentifier;
3✔
45
    }
46

47
    /**
48
     * @return list<mixed>
49
     */
50
    private function composeCacheIdentifierComponents(): array
3✔
51
    {
52
        $components = [
3✔
53
            $this->template,
3✔
54
            $this->options,
3✔
55
        ];
3✔
56

57
        $packageVersion = $this->lookupHandlebarsPackageVersion();
3✔
58

59
        if ($packageVersion !== null) {
3✔
60
            $components[] = $packageVersion;
3✔
61
        }
62

63
        return $components;
3✔
64
    }
65

66
    private function lookupHandlebarsPackageVersion(): ?string
3✔
67
    {
68
        $version = null;
3✔
69
        $installedPackagesPath = dirname(__DIR__, 2) . '/Resources/Private/Libs/vendor/composer/installed.php';
3✔
70

71
        if (is_file($installedPackagesPath)) {
3✔
72
            // Classic mode
73
            /** @var array{versions: array<string, array{version: string}>} $installedPackages */
74
            $installedPackages = include $installedPackagesPath;
2✔
75
            $version = $installedPackages['versions']['devtheorem/php-handlebars']['version'] ?? null;
2✔
76
        } elseif (class_exists(InstalledVersions::class)) {
2✔
77
            // Composer mode
78
            try {
79
                $version = InstalledVersions::getVersion('devtheorem/php-handlebars');
2✔
NEW
80
            } catch (\OutOfBoundsException) {
×
81
                // Something is wrong if the library is not installed, but this will already
82
                // be problematic on higher levels. We shouldn't fail in this low level area.
83
            }
84
        }
85

86
        if (is_string($version)) {
3✔
87
            return $version;
3✔
88
        }
89

NEW
90
        return null;
×
91
    }
92

93
    public function __clone(): void
1✔
94
    {
95
        // Enforce recalculation of the cache identifier on clone
96
        $this->cacheIdentifier = null;
1✔
97
    }
98
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc