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

FluidTYPO3 / vhs / 30001290505

23 Jul 2026 10:57AM UTC coverage: 70.309% (-1.7%) from 72.022%
30001290505

push

github

NamelessCoder
[TER] 8.0.0

4819 of 6854 relevant lines covered (70.31%)

6.54 hits per line

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

10.09
/Classes/ViewHelpers/Render/RequestViewHelper.php
1
<?php
2
namespace FluidTYPO3\Vhs\ViewHelpers\Render;
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\Proxy\DispatcherProxy;
12
use FluidTYPO3\Vhs\Utility\ContentObjectFetcher;
13
use FluidTYPO3\Vhs\Utility\RequestResolver;
14
use Psr\Http\Message\ServerRequestInterface;
15
use TYPO3\CMS\Core\Utility\GeneralUtility;
16
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
17
use TYPO3\CMS\Extbase\Mvc\ExtbaseRequestParameters;
18
use TYPO3\CMS\Extbase\Mvc\RequestInterface;
19
use TYPO3\CMS\Extbase\Mvc\ResponseInterface;
20
use TYPO3\CMS\Extbase\Mvc\Web\Request;
21
use TYPO3\CMS\Extbase\Mvc\Web\Response;
22
use TYPO3\CMS\Fluid\Core\Rendering\RenderingContext;
23
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
24
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
25

26
/**
27
 * ### Render: Request
28
 *
29
 * Renders a sub-request to the desired Extension, Plugin,
30
 * Controller and action with the desired arguments.
31
 *
32
 * Note: arguments must not be wrapped with the prefix used
33
 * in GET/POST parameters but must be provided as if the
34
 * arguments were sent directly to the Controller action.
35
 */
36
class RequestViewHelper extends AbstractRenderViewHelper
37
{
38
    /**
39
     * @var class-string
40
     */
41
    protected static string $requestType = Request::class;
42

43
    /**
44
     * @var class-string
45
     */
46
    protected static string $responseType = Response::class;
47

48
    public function initializeArguments(): void
49
    {
50
        parent::initializeArguments();
3✔
51
        $this->registerArgument('action', 'string', 'Controller action to call in request');
3✔
52
        $this->registerArgument('controller', 'string', 'Controller name to call in request');
3✔
53
        $this->registerArgument('extensionName', 'string', 'Extension name scope to use in request');
3✔
54
        $this->registerArgument(
3✔
55
            'vendorName',
3✔
56
            'string',
3✔
57
            'Vendor name scope to use in request. WARNING: only applies to TYPO3 versions below 10.4'
3✔
58
        );
3✔
59
        $this->registerArgument('pluginName', 'string', 'Plugin name scope to use in request');
3✔
60
        $this->registerArgument('arguments', 'array', 'Arguments to use in request');
3✔
61
    }
62

63
    /**
64
     * @return string|ResponseInterface
65
     */
66
    public static function renderStatic(
67
        array $arguments,
68
        \Closure $renderChildrenClosure,
69
        RenderingContextInterface $renderingContext
70
    ) {
71
        /** @var RenderingContext $renderingContext */
72
        /** @var string|null $action */
73
        $action = $arguments['action'];
×
74
        /** @var string|null $controller */
75
        $controller = $arguments['controller'];
×
76
        /** @var string|null $extensionName */
77
        $extensionName = $arguments['extensionName'];
×
78
        /** @var string|null $pluginName */
79
        $pluginName = $arguments['pluginName'];
×
80
        $requestArguments = is_array($arguments['arguments']) ? $arguments['arguments'] : [];
×
81
        $configurationManager = static::getConfigurationManager();
×
82
        $contentObjectBackup = ContentObjectFetcher::resolve($configurationManager);
×
83
        $configurationBackup = $configurationManager->getConfiguration(
×
84
            ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK
×
85
        );
×
86

87
        /** @var ContentObjectRenderer $temporaryContentObject */
88
        $temporaryContentObject = GeneralUtility::makeInstance(ContentObjectRenderer::class);
×
89
        try {
90
            $targetConfiguration = $configurationManager->getConfiguration(
×
91
                ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK,
×
92
                $extensionName,
×
93
                $pluginName
×
94
            );
×
95

96
            /** @var ResponseInterface|\TYPO3\CMS\Core\Http\Response $response */
97
            $response = GeneralUtility::makeInstance(
×
98
                class_exists(static::$responseType)
×
99
                    ? static::$responseType
×
100
                    : \TYPO3\CMS\Core\Http\Response::class
×
101
            );
×
102
            if (method_exists($configurationManager, 'setContentObject')) {
×
103
                $configurationManager->setContentObject($temporaryContentObject);
×
104
            }
105
            $configurationManager->setConfiguration($targetConfiguration);
×
106

107
            $request = self::loadDefaultValues(
×
108
                $renderingContext,
×
109
                $extensionName,
×
110
                $pluginName,
×
111
                $controller,
×
112
                $action,
×
113
                $requestArguments
×
114
            );
×
115

116
            /** @var ResponseInterface|null $possibleResponse */
117
            $possibleResponse = static::getDispatcher()->dispatch(
×
118
                $request instanceof RequestInterface ? $request : new \TYPO3\CMS\Extbase\Mvc\Request($request),
×
119
                $response instanceof Response ? $response : null
×
120
            );
×
121
            if ($possibleResponse) {
×
122
                $response = $possibleResponse;
×
123
            }
124
            if ($contentObjectBackup !== null && method_exists($configurationManager, 'setContentObject')) {
×
125
                $configurationManager->setContentObject($contentObjectBackup);
×
126
            }
127
            $configurationManager->setConfiguration($configurationBackup);
×
128
            if (method_exists($response, 'getBody')) {
×
129
                $response->getBody()->rewind();
×
130
                return $response->getBody()->getContents();
×
131
            }
132
            if (method_exists($response, 'getContent')) {
×
133
                return $response->getContent();
×
134
            }
135
            return '';
×
136
        } catch (\Exception $error) {
×
137
            if (!$arguments['graceful']) {
×
138
                throw $error;
×
139
            }
140
            /** @var string|null $onError */
141
            $onError = $arguments['onError'];
×
142
            if ($onError !== null) {
×
143
                return sprintf($onError, $error->getMessage(), $error->getCode());
×
144
            }
145
            return $error->getMessage() . ' (' . $error->getCode() . ')';
×
146
        }
147
    }
148

149
    protected static function getDispatcher(): DispatcherProxy
150
    {
151
        /** @var DispatcherProxy $dispatcher */
152
        $dispatcher = GeneralUtility::makeInstance(DispatcherProxy::class);
×
153
        return $dispatcher;
×
154
    }
155

156
    protected static function getConfigurationManager(): ConfigurationManagerInterface
157
    {
158
        /** @var ConfigurationManagerInterface $configurationManager */
159
        $configurationManager = GeneralUtility::makeInstance(ConfigurationManagerInterface::class);
×
160
        return $configurationManager;
×
161
    }
162

163
    /**
164
     * @return RequestInterface|ServerRequestInterface
165
     * @see \TYPO3\CMS\Extbase\Core\Bootstrap::initializeConfiguration
166
     */
167
    protected static function loadDefaultValues(
168
        RenderingContextInterface $renderingContext,
169
        ?string $extensionName,
170
        ?string $pluginName,
171
        ?string $controllerName,
172
        ?string $actionName,
173
        array $arguments
174
    ) {
175
        $configurationManager = static::getConfigurationManager();
×
176
        $configuration = $configurationManager->getConfiguration(
×
177
            ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK,
×
178
            $extensionName,
×
179
            $pluginName
×
180
        );
×
181
        /** @var string $defaultActionName */
182
        $defaultActionName = reset(reset($configuration['controllerConfiguration'])['actions']);
×
183

184
        $firstControllerName = null;
×
185
        $controllerAliasToClassMapping = [];
×
186
        $controllerClassToAliasMapping = [];
×
187
        foreach ($configuration['controllerConfiguration'] as $controllerClassName => $controllerConfiguration) {
×
188
            $firstControllerName = $firstControllerName ?? $controllerClassName;
×
189
            $controllerAliasToClassMapping[$controllerConfiguration['alias']] = $controllerConfiguration['className'];
×
190
            $controllerClassToAliasMapping[$controllerConfiguration['className']] = $controllerConfiguration['alias'];
×
191
        }
192

193
        if (class_exists(ExtbaseRequestParameters::class)) {
×
194
            /** @var ExtbaseRequestParameters $parameters */
195
            $parameters = GeneralUtility::makeInstance(ExtbaseRequestParameters::class);
×
196

197
            $parameters->setControllerAliasToClassNameMapping($controllerAliasToClassMapping);
×
198
            if ($pluginName !== null) {
×
199
                $parameters->setPluginName($pluginName);
×
200
            }
201
            if ($extensionName !== null) {
×
202
                $parameters->setControllerExtensionName($extensionName);
×
203
            }
204
            $parameters->setControllerName($controllerName ?? $controllerClassToAliasMapping[$firstControllerName]);
×
205
            $parameters->setControllerActionName($actionName ?? $defaultActionName);
×
206

207
            if (!empty($configuration['format'])) {
×
208
                $parameters->setFormat($configuration['format']);
×
209
            }
210

211
            foreach ($arguments as $argumentName => $argumentValue) {
×
212
                $parameters->setArgument($argumentName, $argumentValue);
×
213
            }
214

215
            return $GLOBALS['TYPO3_REQUEST']->withAttribute('extbase', $parameters);
×
216
        }
217

218
        $request = RequestResolver::resolveRequestFromRenderingContext($renderingContext);
×
219

220
        if (method_exists($request, 'setControllerAliasToClassNameMapping')) {
×
221
            $request->setControllerAliasToClassNameMapping($controllerAliasToClassMapping);
×
222
        }
223

224
        if ($pluginName !== null && method_exists($request, 'setPluginName')) {
×
225
            $request->setPluginName($pluginName);
×
226
        }
227

228
        if ($extensionName !== null && method_exists($request, 'setControllerExtensionName')) {
×
229
            $request->setControllerExtensionName($extensionName);
×
230
        }
231

232
        if (method_exists($request, 'setControllerName')) {
×
233
            $request->setControllerName($controllerName ?? $controllerClassToAliasMapping[$firstControllerName]);
×
234
        }
235

236
        if (method_exists($request, 'setControllerActionName')) {
×
237
            $request->setControllerActionName($actionName ?? $defaultActionName);
×
238
        }
239

240
        return $request;
×
241
    }
242
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc