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

FluidTYPO3 / vhs / 10213662489

02 Aug 2024 09:55AM UTC coverage: 72.717% (-0.05%) from 72.762%
10213662489

push

github

NamelessCoder
[TER] 7.0.4

5533 of 7609 relevant lines covered (72.72%)

13.49 hits per line

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

64.71
/Classes/ViewHelpers/Variable/ExtensionConfigurationViewHelper.php
1
<?php
2
namespace FluidTYPO3\Vhs\ViewHelpers\Variable;
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\RequestResolver;
12
use TYPO3\CMS\Core\Utility\GeneralUtility;
13
use TYPO3\CMS\Extbase\Reflection\ObjectAccess;
14
use TYPO3\CMS\Fluid\Core\Rendering\RenderingContext;
15
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
16
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
17
use TYPO3Fluid\Fluid\Core\ViewHelper\Exception;
18
use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
19

20
/**
21
 * ### ExtConf ViewHelper
22
 *
23
 * Reads settings from ext_conf_template.txt
24
 *
25
 * ### Examples
26
 *
27
 * ```
28
 * {v:variable.extensionConfiguration(extensionKey:'foo',path:'bar.baz')}
29
 * ```
30
 *
31
 * Returns setting `bar.baz` from extension 'foo' located in `ext_conf_template.txt`.
32
 */
33
class ExtensionConfigurationViewHelper extends AbstractViewHelper
34
{
35
    use CompileWithRenderStatic;
36

37
    /**
38
     * @var array
39
     */
40
    protected static $configurations = [];
41

42
    public function initializeArguments(): void
43
    {
44
        $this->registerArgument(
6✔
45
            'extensionKey',
6✔
46
            'string',
6✔
47
            'Extension key (lowercase_underscored format) to read configuration from'
6✔
48
        );
6✔
49
        $this->registerArgument(
6✔
50
            'path',
6✔
51
            'string',
6✔
52
            'Configuration path to read - if NULL, returns all configuration as array'
6✔
53
        );
6✔
54
    }
55

56
    /**
57
     * @return mixed
58
     */
59
    public static function renderStatic(
60
        array $arguments,
61
        \Closure $renderChildrenClosure,
62
        RenderingContextInterface $renderingContext
63
    ) {
64
        /** @var RenderingContext $renderingContext */
65
        /** @var string|null $extensionKey */
66
        $extensionKey = $arguments['extensionKey'];
36✔
67
        /** @var string $path */
68
        $path = $arguments['path'];
36✔
69

70
        if (null === $extensionKey) {
36✔
71
            $extensionName = RequestResolver::resolveControllerExtensionNameFromRenderingContext($renderingContext);
×
72
            if ($extensionName) {
×
73
                $extensionKey = GeneralUtility::camelCaseToLowerCaseUnderscored($extensionName);
×
74
            }
75
        }
76

77
        if (!$extensionKey) {
36✔
78
            throw new Exception(
×
79
                'Could not resolve extension key from request. Please pass argument "extensionKey".',
×
80
                1721314563
×
81
            );
×
82
        }
83

84
        if (!isset($GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS'][$extensionKey]) &&
36✔
85
            !isset($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf'][$extensionKey])) {
36✔
86
            return null;
×
87
        } elseif (!array_key_exists($extensionKey, static::$configurations)) {
36✔
88
            if (isset($GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS'][$extensionKey])) {
6✔
89
                $extConf = $GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS'][$extensionKey];
6✔
90
            } elseif (is_string($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf'][$extensionKey])) {
×
91
                $extConf = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf'][$extensionKey]);
×
92
            } else {
93
                $extConf = $GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf'][$extensionKey];
×
94
            }
95
            static::$configurations[$extensionKey] = GeneralUtility::removeDotsFromTS($extConf);
6✔
96
        }
97

98
        if (!$path) {
36✔
99
            return static::$configurations[$extensionKey];
×
100
        }
101

102
        return ObjectAccess::getPropertyPath(static::$configurations[$extensionKey], $path);
36✔
103
    }
104
}
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