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

FluidTYPO3 / vhs / 28588802516

02 Jul 2026 12:08PM UTC coverage: 70.321% (+0.4%) from 69.971%
28588802516

push

github

NamelessCoder
[TASK] Remove most of the remaining TSFE usages

21 of 32 new or added lines in 7 files covered. (65.63%)

4836 of 6877 relevant lines covered (70.32%)

4.41 hits per line

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

57.5
/Classes/ViewHelpers/Once/AbstractOnceViewHelper.php
1
<?php
2
namespace FluidTYPO3\Vhs\ViewHelpers\Once;
3

4
/*
5
 * This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
6
 *
7
 * For the full copyright and license information, please read the
8
 * LICENSE.md file that was distributed with this source code.
9
 */
10

11
use FluidTYPO3\Vhs\Utility\ContextUtility;
12
use FluidTYPO3\Vhs\Utility\RequestResolver;
13
use TYPO3\CMS\Fluid\Core\Rendering\RenderingContext;
14
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
15
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractConditionViewHelper;
16

17
/**
18
 * Base class for "Render Once"-style ViewHelpers: session, cookie,
19
 * request, template variable set, ViewHelper variable set etc.
20
 */
21
abstract class AbstractOnceViewHelper extends AbstractConditionViewHelper
22
{
23
    /**
24
     * Standard storage - static variable meaning uniqueness of $identifier
25
     * across each Request, i.e. unique to each individual plugin/content.
26
     *
27
     * @var array
28
     */
29
    protected static $identifiers = [];
30

31
    /**
32
     * Always-current but statically assigned instance of rendering context
33
     * which applied at the exact time that the ViewHelper was asked to
34
     * evaluate whether or not to render content.
35
     *
36
     * @var RenderingContextInterface&RenderingContext
37
     */
38
    protected static $currentRenderingContext;
39

40
    public function initializeArguments(): void
41
    {
42
        parent::initializeArguments();
8✔
43
        $this->registerArgument(
8✔
44
            'identifier',
8✔
45
            'string',
8✔
46
            'Identity of this condition - if used in other places, the condition applies to the same identity in the ' .
8✔
47
            'storage (i.e. cookie name or session key)'
8✔
48
        );
8✔
49
        $this->registerArgument(
8✔
50
            'lockToDomain',
8✔
51
            'boolean',
8✔
52
            'If TRUE, locks this condition to a specific domain, i.e. the storage of $identity is associated with ' .
8✔
53
            'a domain. If same identity is also used without domain lock, it matches any domain locked condition',
8✔
54
            false,
8✔
55
            false
8✔
56
        );
8✔
57
        $this->registerArgument(
8✔
58
            'ttl',
8✔
59
            'integer',
8✔
60
            'Time-to-live for skip registration, number of seconds. After this expires the registration is unset',
8✔
61
            false,
8✔
62
            86400
8✔
63
        );
8✔
64
    }
65

66
    /**
67
     * @return mixed
68
     */
69
    public static function renderStatic(
70
        array $arguments,
71
        \Closure $renderChildrenClosure,
72
        RenderingContextInterface $renderingContext
73
    ) {
74
        /** @var RenderingContext $renderingContext */
75
        static::$currentRenderingContext = $renderingContext;
×
76
        return parent::renderStatic($arguments, $renderChildrenClosure, $renderingContext);
×
77
    }
78

79
    public static function verdict(array $arguments, RenderingContextInterface $renderingContext): bool
80
    {
81
        static::removeIfExpired($arguments);
×
82
        $shouldSkip = static::assertShouldSkip($arguments) === false;
×
83
        static::storeIdentifier($arguments);
×
84
        return $shouldSkip;
×
85
    }
86

87
    protected static function getIdentifier(array $arguments): string
88
    {
89
        return $arguments['identifier'] ?? static::class;
6✔
90
    }
91

92
    protected static function storeIdentifier(array $arguments): void
93
    {
94
        $identifier = static::getIdentifier($arguments);
×
95
        if (!isset(static::$identifiers[$identifier])) {
×
96
            static::$identifiers[$identifier] = time();
×
97
        }
98
    }
99

100
    protected static function removeIfExpired(array $arguments): void
101
    {
102
        $id = static::getIdentifier($arguments);
×
103
        if (isset(static::$identifiers[$id]) && static::$identifiers[$id] <= time() - $arguments['ttl']) {
×
104
            unset(static::$identifiers[$id]);
×
105
        }
106
    }
107

108
    protected static function assertShouldSkip(array $arguments): bool
109
    {
110
        $identifier = static::getIdentifier($arguments);
×
111
        return isset(static::$identifiers[$identifier]);
×
112
    }
113

114
    /**
115
     * Override: forcibly disables page caching - a TRUE condition
116
     * in this ViewHelper means page content would be depending on
117
     * the current visitor's session/cookie/auth etc.
118
     *
119
     * Returns value of "then" attribute.
120
     * If then attribute is not set, iterates through child nodes and renders ThenViewHelper.
121
     * If then attribute is not set and no ThenViewHelper and no ElseViewHelper is found, all child nodes are rendered
122
     *
123
     * @return mixed rendered ThenViewHelper or contents of <f:if> if no ThenViewHelper was found
124
     */
125
    protected function renderThenChild(): mixed
126
    {
127
        if (ContextUtility::isFrontend()) {
×
NEW
128
            RequestResolver::disableFrontendCache('EXT:vhs: Once ViewHelper disables caches.');
×
129
        }
130
        return parent::renderThenChild();
×
131
    }
132
}
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