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

FluidTYPO3 / vhs / 12968595783

25 Jan 2025 09:30PM UTC coverage: 72.268%. Remained the same
12968595783

Pull #1925

github

web-flow
Merge aa1eb976f into 0ca5a1c10
Pull Request #1925: [BUGFIX] Replace all evaluateCondition methods with verdict methods

19 of 27 new or added lines in 9 files covered. (70.37%)

25 existing lines in 4 files now uncovered.

5548 of 7677 relevant lines covered (72.27%)

13.46 hits per line

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

76.19
/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 TYPO3\CMS\Fluid\Core\Rendering\RenderingContext;
13
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
14
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractConditionViewHelper;
15

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

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

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

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

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

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

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

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

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

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