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

FluidTYPO3 / vhs / 13566190336

27 Feb 2025 12:18PM UTC coverage: 72.127% (-0.6%) from 72.746%
13566190336

push

github

NamelessCoder
[TER] 7.1.0

5649 of 7832 relevant lines covered (72.13%)

20.01 hits per line

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

91.07
/Classes/View/UncacheTemplateView.php
1
<?php
2
namespace FluidTYPO3\Vhs\View;
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 TYPO3\CMS\Core\Utility\GeneralUtility;
12
use TYPO3\CMS\Core\Utility\VersionNumberUtility;
13
use TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext;
14
use TYPO3\CMS\Extbase\Mvc\ExtbaseRequestParameters;
15
use TYPO3\CMS\Extbase\Mvc\Request;
16
use TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder;
17
use TYPO3\CMS\Fluid\Compatibility\TemplateParserBuilder;
18
use TYPO3\CMS\Fluid\Core\Rendering\RenderingContext;
19
use TYPO3\CMS\Fluid\Core\Rendering\RenderingContextFactory;
20
use TYPO3\CMS\Fluid\View\TemplateView;
21
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
22

23
class UncacheTemplateView extends TemplateView
24
{
25
    public function callUserFunction(string $postUserFunc, array $conf): string
26
    {
27
        $partial = $conf['partial'] ?? null;
14✔
28
        $section = $conf['section'] ?? null;
14✔
29
        $arguments = $conf['arguments'] ?? [];
14✔
30
        $parameters = $conf['controllerContext'] ?? null;
14✔
31
        $extensionName = $parameters instanceof ExtbaseRequestParameters
14✔
32
            ? $parameters->getControllerExtensionName()
×
33
            : $parameters['extensionName'] ?? null;
14✔
34

35
        if (empty($partial)) {
14✔
36
            return '';
7✔
37
        }
38

39
        if (class_exists(RenderingContextFactory::class)) {
7✔
40
            $renderingContext = $this->createRenderingContextWithRenderingContextFactory();
6✔
41
            if (method_exists($renderingContext, 'setRequest')) {
6✔
42
                $request = $parameters instanceof ExtbaseRequestParameters
6✔
43
                    ? $GLOBALS['TYPO3_REQUEST']->withAttribute('extbase', $parameters)
×
44
                    : $GLOBALS['TYPO3_REQUEST'];
6✔
45
                $renderingContext->setRequest(
6✔
46
                    // TYPO3 v11.x needs the ServerRequest wrapped in an Extbase Request.
47
                    version_compare(VersionNumberUtility::getCurrentTypo3Version(), '12.0', '<')
6✔
48
                        ? new Request($request)
2✔
49
                        : $request
6✔
50
                );
6✔
51
            }
52
        } else {
53
            /** @var ControllerContext $controllerContext */
54
            $controllerContext = GeneralUtility::makeInstance(ControllerContext::class);
1✔
55
            /** @var Request $request */
56
            $request = GeneralUtility::makeInstance(Request::class);
1✔
57
            $controllerContext->setRequest($request);
1✔
58

59
            /** @var UriBuilder $uriBuilder */
60
            $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
1✔
61
            $uriBuilder->setRequest($request);
1✔
62
            $controllerContext->setUriBuilder($uriBuilder);
1✔
63

64
            if ($parameters) {
1✔
65
                if (method_exists($request, 'setControllerActionName')) {
1✔
66
                    $request->setControllerActionName($parameters['actionName']);
1✔
67
                }
68

69
                if (method_exists($request, 'setControllerExtensionName')) {
1✔
70
                    $request->setControllerExtensionName($parameters['extensionName']);
1✔
71
                }
72

73
                if (method_exists($request, 'setControllerName')) {
1✔
74
                    $request->setControllerName($parameters['controllerName']);
1✔
75
                }
76

77
                if (method_exists($request, 'setControllerObjectName')) {
1✔
78
                    $request->setControllerObjectName($parameters['controllerObjectName']);
1✔
79
                }
80

81
                if (method_exists($request, 'setPluginName')) {
1✔
82
                    $request->setPluginName($parameters['pluginName']);
1✔
83
                }
84

85
                if (method_exists($request, 'setFormat')) {
1✔
86
                    $request->setFormat($parameters['format']);
1✔
87
                }
88
            }
89

90
            /** @var RenderingContext $renderingContext */
91
            $renderingContext = GeneralUtility::makeInstance(RenderingContext::class);
1✔
92
        }
93

94
        $this->prepareContextsForUncachedRendering($renderingContext);
7✔
95
        if (!empty($conf['partialRootPaths'])) {
7✔
96
            $renderingContext->getTemplatePaths()->setPartialRootPaths($conf['partialRootPaths']);
7✔
97
        } elseif ($extensionName) {
×
98
            $extensionKey = GeneralUtility::camelCaseToLowerCaseUnderscored($extensionName);
×
99
            $renderingContext->getTemplatePaths()->fillDefaultsByPackageName($extensionKey);
×
100
        }
101
        return $this->renderPartialUncached($renderingContext, $partial, $section, $arguments);
7✔
102
    }
103

104
    protected function prepareContextsForUncachedRendering(RenderingContextInterface $renderingContext): void
105
    {
106
        $this->setRenderingContext($renderingContext);
14✔
107
    }
108

109
    protected function renderPartialUncached(
110
        RenderingContextInterface $renderingContext,
111
        string $partial,
112
        ?string $section = null,
113
        array $arguments = []
114
    ): string {
115
        $this->renderingStack[] = [
7✔
116
            'type' => static::RENDERING_TEMPLATE,
7✔
117
            'parsedTemplate' => null,
7✔
118
            'renderingContext' => $renderingContext,
7✔
119
        ];
7✔
120
        /** @var string $rendered */
121
        $rendered = $this->renderPartial($partial, $section, $arguments);
7✔
122
        array_pop($this->renderingStack);
7✔
123
        return $rendered;
7✔
124
    }
125

126
    /**
127
     * @codeCoverageIgnore
128
     */
129
    protected function createRenderingContextWithRenderingContextFactory(): RenderingContextInterface
130
    {
131
        /** @var RenderingContextFactory $renderingContextFactory */
132
        $renderingContextFactory = GeneralUtility::makeInstance(RenderingContextFactory::class);
133
        return $renderingContextFactory->create();
134
    }
135
}
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