• 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

47.62
/Classes/ViewHelpers/Render/AbstractRenderViewHelper.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 TYPO3\CMS\Core\Utility\GeneralUtility;
12
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
13
use TYPO3\CMS\Fluid\View\StandaloneView;
14
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
15
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
16
use TYPO3Fluid\Fluid\View\ViewInterface;
17

18
/**
19
 * ### Base class for all rendering ViewHelpers.
20
 *
21
 * If errors occur they can be graciously ignored and
22
 * replaced by a small error message or the error itself.
23
 */
24
abstract class AbstractRenderViewHelper extends AbstractViewHelper
25
{
26
    /**
27
     * @var ConfigurationManagerInterface
28
     */
29
    protected $configurationManager;
30

31
    /**
32
     * @var boolean
33
     */
34
    protected $escapeOutput = false;
35

36
    public function injectConfigurationManager(ConfigurationManagerInterface $configurationManager): void
37
    {
38
        $this->configurationManager = $configurationManager;
63✔
39
    }
40

41
    public function initializeArguments(): void
42
    {
43
        $this->registerArgument(
28✔
44
            'onError',
28✔
45
            'string',
28✔
46
            'Optional error message to display if error occur while rendering. If NULL, lets the error Exception ' .
28✔
47
            'pass trough (and break rendering)'
28✔
48
        );
28✔
49
        $this->registerArgument(
28✔
50
            'graceful',
28✔
51
            'boolean',
28✔
52
            'If forced to FALSE, errors are not caught but rather "transmitted" as every other error would be',
28✔
53
            false,
28✔
54
            false
28✔
55
        );
28✔
56
    }
57

58
    protected static function getPreparedNamespaces(array $arguments): array
59
    {
60
        $namespaces = [];
×
61
        foreach ((array) $arguments['namespaces'] as $namespaceIdentifier => $namespace) {
×
62
            $addedOverriddenNamespace = '{namespace ' . $namespaceIdentifier . '=' . $namespace . '}';
×
63
            $namespaces[] = $addedOverriddenNamespace;
×
64
        }
65
        return $namespaces;
×
66
    }
67

68
    protected static function getPreparedClonedView(RenderingContextInterface $renderingContext): StandaloneView
69
    {
70
        $view = static::getPreparedView();
×
71
        $newRenderingContext = $view->getRenderingContext();
×
72
        if (method_exists($renderingContext, 'getControllerContext')) {
×
73
            $controllerContext = clone $renderingContext->getControllerContext();
×
74

75
            $view->setFormat($controllerContext->getRequest()->getFormat());
×
76
            $newRenderingContext->setViewHelperVariableContainer(
×
77
                $renderingContext->getViewHelperVariableContainer()
×
78
            );
×
79
            if (method_exists($newRenderingContext, 'setControllerContext')) {
×
80
                $newRenderingContext->setControllerContext($controllerContext);
×
81
            }
82
        } elseif (method_exists($renderingContext, 'getRequest') && method_exists($newRenderingContext, 'setRequest')) {
×
83
            $newRenderingContext->setRequest($renderingContext->getRequest());
×
84
        }
85
        $variables = (array) $renderingContext->getVariableProvider()->getAll();
×
86
        $view->assignMultiple($variables);
×
87
        return $view;
×
88
    }
89

90
    /**
91
     * @param \TYPO3\CMS\Extbase\Mvc\View\ViewInterface|ViewInterface $view
92
     */
93
    protected static function renderView($view, array $arguments): string
94
    {
95
        try {
96
            /** @var string|null $content */
97
            $content = $view->render();
7✔
98
        } catch (\Exception $error) {
7✔
99
            if (!($arguments['graceful'] ?? false)) {
7✔
100
                throw $error;
7✔
101
            }
102
            $content = $error->getMessage() . ' (' . $error->getCode() . ')';
×
103
        }
104
        return (string) $content;
×
105
    }
106

107
    protected static function getPreparedView(): StandaloneView
108
    {
109
        /** @var StandaloneView $view */
110
        $view = GeneralUtility::makeInstance(StandaloneView::class);
7✔
111
        return $view;
7✔
112
    }
113
}
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