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

CPS-IT / handlebars-forms / 23529335785

25 Mar 2026 07:11AM UTC coverage: 0.795% (+0.003%) from 0.792%
23529335785

push

github

eliashaeussler
[BUGFIX] Avoid using runtime cache to store collected values

0 of 4 new or added lines in 1 file covered. (0.0%)

4 existing lines in 1 file now uncovered.

7 of 880 relevant lines covered (0.8%)

0.03 hits per line

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

0.0
/Classes/ContentObject/Context/ValueCollector.php
1
<?php
2

3
declare(strict_types=1);
4

5
/*
6
 * This file is part of the TYPO3 CMS extension "handlebars_forms".
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\Typo3HandlebarsForms\ContentObject\Context;
19

20
use CPSIT\Typo3HandlebarsForms\ContentObject;
21
use Symfony\Component\DependencyInjection;
22
use TYPO3\CMS\Core;
23

24
/**
25
 * ValueCollector
26
 *
27
 * @author Elias Häußler <e.haeussler@familie-redlich.de>
28
 * @license GPL-2.0-or-later
29
 *
30
 * @internal
31
 */
32
#[DependencyInjection\Attribute\Autoconfigure(shared: true)]
33
final class ValueCollector
34
{
35
    private const CACHE_IDENTIFIER_PREFIX = 'HandlebarsFormsValue_';
36

37
    /**
38
     * @todo Switch to runtiem cache once https://forge.typo3.org/issues/109220 is resolved
39
     *
40
     * @var array<string, mixed>
41
     */
42
    private static array $collection = [];
43

44
    public function save(ContentObject\AbstractHandlebarsFormsContentObject $contentObject, mixed $value): string
×
45
    {
46
        $identifier = Core\Utility\StringUtility::getUniqueId(
×
47
            self::CACHE_IDENTIFIER_PREFIX . spl_object_hash($contentObject),
×
48
        );
×
49

NEW
50
        self::$collection[$identifier] = $value;
×
51

52
        return $identifier;
×
53
    }
54

55
    public function load(string $identifier): mixed
×
56
    {
NEW
57
        if (!$this->has($identifier)) {
×
58
            return null;
×
59
        }
60

NEW
61
        return self::$collection[$identifier];
×
62
    }
63

64
    public function has(string $identifier): bool
×
65
    {
66
        if (!$this->isValidIdentifier($identifier)) {
×
67
            return false;
×
68
        }
69

70
        // The array_key_exists check is intentional – Null-coalescing operator MUST be avoided,
71
        // otherwise collected NULL values will be treated as if no value has been collected.
72
        // This is also the case why we don't use runtime cache at the moment, because it improperly
73
        // checks for the existence of a cache entry (see https://forge.typo3.org/issues/109220).
NEW
74
        return array_key_exists($identifier, self::$collection);
×
75
    }
76

77
    private function isValidIdentifier(string $identifier): bool
×
78
    {
79
        return str_starts_with($identifier, self::CACHE_IDENTIFIER_PREFIX);
×
80
    }
81
}
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