Passed
Push — master ( af49bb...0a24d1 )
by
unknown
15:19
created

BaseViewHelper::getRequest()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the TYPO3 CMS project.
5
 *
6
 * It is free software; you can redistribute it and/or modify it under
7
 * the terms of the GNU General Public License, either version 2
8
 * of the License, or any later version.
9
 *
10
 * For the full copyright and license information, please read the
11
 * LICENSE.txt file that was distributed with this source code.
12
 *
13
 * The TYPO3 project - inspiring people to share!
14
 */
15
16
namespace TYPO3\CMS\Fluid\ViewHelpers;
17
18
use TYPO3\CMS\Core\Http\ApplicationType;
19
use TYPO3\CMS\Core\Http\NormalizedParams;
20
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
21
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
22
use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
23
24
/**
25
 * ViewHelper which creates a :html:`<base href="..."></base>` tag.
26
 *
27
 * The Base URI is taken from the current request.
28
 *
29
 * Examples
30
 * ========
31
 *
32
 * Example::
33
 *
34
 *    <f:base />
35
 *
36
 * Output::
37
 *
38
 *    <base href="http://yourdomain.tld/" />
39
 *
40
 * Depending on your domain.
41
 *
42
 * @deprecated since v11, will be removed in v12.
43
 */
44
class BaseViewHelper extends AbstractViewHelper
45
{
46
    use CompileWithRenderStatic;
47
48
    /**
49
     * As this ViewHelper renders HTML, the output must not be escaped.
50
     *
51
     * @var bool
52
     */
53
    protected $escapeOutput = false;
54
55
    /**
56
     * Render the "Base" tag by outputting site URL
57
     *
58
     * Note: renders as <base></base>, because IE6 will else refuse to display
59
     * the page...
60
     *
61
     * @param array $arguments
62
     * @param \Closure $renderChildrenClosure
63
     * @param RenderingContextInterface $renderingContext
64
     *
65
     * @return string "base"-Tag.
66
     */
67
    public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
68
    {
69
        trigger_error(__CLASS__ . ' will be removed in TYPO3 v12.', E_USER_DEPRECATED);
70
        $request = $renderingContext->getRequest();
0 ignored issues
show
Bug introduced by
The method getRequest() does not exist on TYPO3Fluid\Fluid\Core\Re...nderingContextInterface. It seems like you code against a sub-type of TYPO3Fluid\Fluid\Core\Re...nderingContextInterface such as TYPO3\CMS\Fluid\Core\Rendering\RenderingContext. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

70
        /** @scrutinizer ignore-call */ 
71
        $request = $renderingContext->getRequest();
Loading history...
71
        /** @var NormalizedParams $normalizedParams */
72
        $normalizedParams = $request->getAttribute('normalizedParams');
73
        $baseUri = $normalizedParams->getSiteUrl();
74
        if (ApplicationType::fromRequest($request)->isBackend()) {
75
            $baseUri .= TYPO3_mainDir;
76
        }
77
        return '<base href="' . htmlspecialchars($baseUri) . '" />';
78
    }
79
}
80