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

eliashaeussler / typo3-warming / 15378376261

01 Jun 2025 06:58PM UTC coverage: 91.027% (-0.01%) from 91.04%
15378376261

push

github

web-flow
Merge pull request #864 from eliashaeussler/task/view-factory

9 of 10 new or added lines in 1 file covered. (90.0%)

1339 of 1471 relevant lines covered (91.03%)

9.86 hits per line

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

95.45
/Classes/View/TemplateRenderer.php
1
<?php
2

3
declare(strict_types=1);
4

5
/*
6
 * This file is part of the TYPO3 CMS extension "warming".
7
 *
8
 * Copyright (C) 2021-2025 Elias Häußler <elias@haeussler.dev>
9
 *
10
 * This program is free software: you can redistribute it and/or modify
11
 * it under the terms of the GNU General Public License as published by
12
 * the Free Software Foundation, either version 2 of the License, or
13
 * (at your option) any later version.
14
 *
15
 * This program is distributed in the hope that it will be useful,
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
 * GNU General Public License for more details.
19
 *
20
 * You should have received a copy of the GNU General Public License
21
 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22
 */
23

24
namespace EliasHaeussler\Typo3Warming\View;
25

26
use TYPO3\CMS\Core;
27
use TYPO3\CMS\Fluid;
28

29
/**
30
 * TemplateRenderer
31
 *
32
 * @author Elias Häußler <elias@haeussler.dev>
33
 * @license GPL-2.0-or-later
34
 */
35
final readonly class TemplateRenderer
36
{
37
    private Fluid\Core\Rendering\RenderingContext $renderingContext;
38

39
    public function __construct(
30✔
40
        private Fluid\Core\Rendering\RenderingContextFactory $renderingContextFactory,
41
    ) {
42
        $this->renderingContext = $this->createRenderingContext();
30✔
43
    }
44

45
    /**
46
     * @param array<string, mixed> $variables
47
     */
48
    public function render(string $templatePath, array $variables = []): string
26✔
49
    {
50
        if ((new Core\Information\Typo3Version())->getMajorVersion() >= 13) {
26✔
51
            $templatePaths = $this->renderingContext->getTemplatePaths();
26✔
52
            $data = new Core\View\ViewFactoryData(
26✔
53
                templateRootPaths: $templatePaths->getTemplateRootPaths(),
26✔
54
                partialRootPaths: $templatePaths->getPartialRootPaths(),
26✔
55
                layoutRootPaths: $templatePaths->getLayoutRootPaths(),
26✔
56
            );
26✔
57
            $viewFactory = Core\Utility\GeneralUtility::makeInstance(Core\View\ViewFactoryInterface::class);
26✔
58
            $view = $viewFactory->create($data);
26✔
59
        } else {
60
            // @todo Remove once support for TYPO3 v12 is dropped
61
            /* @phpstan-ignore classConstant.deprecatedClass */
NEW
62
            $view = Core\Utility\GeneralUtility::makeInstance(Fluid\View\StandaloneView::class, $this->renderingContext);
×
63
        }
64

65
        $view->assignMultiple($variables);
26✔
66

67
        return $view->render($templatePath);
26✔
68
    }
69

70
    private function createRenderingContext(): Fluid\Core\Rendering\RenderingContext
30✔
71
    {
72
        $rootPath = dirname(__DIR__, 2) . '/Resources/Private';
30✔
73

74
        return $this->renderingContextFactory->create([
30✔
75
            'templateRootPaths' => [$rootPath . '/Templates'],
30✔
76
            'partialRootPaths' => [$rootPath . '/Partials'],
30✔
77
            'layoutRootPaths' => [$rootPath . '/Layouts'],
30✔
78
        ]);
30✔
79
    }
80
}
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

© 2025 Coveralls, Inc