Completed
Pull Request — master (#214)
by Claus
03:52
created

DefaultCaseViewHelper::compile()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 5
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
namespace TYPO3Fluid\Fluid\ViewHelpers;
3
4
/*
5
 * This file belongs to the package "TYPO3 Fluid".
6
 * See LICENSE.txt that was shipped with this package.
7
 */
8
9
use TYPO3Fluid\Fluid\Core\Compiler\TemplateCompiler;
10
use TYPO3Fluid\Fluid\Core\Parser\SyntaxTree\ViewHelperNode;
11
use TYPO3Fluid\Fluid\Core\ViewHelper;
12
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
13
use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileEmpty;
14
15
/**
16
 * A view helper which specifies the "default" case when used within the SwitchViewHelper.
17
 * @see \TYPO3Fluid\Fluid\ViewHelpers\SwitchViewHelper
18
 *
19
 * @api
20
 */
21
class DefaultCaseViewHelper extends AbstractViewHelper
22
{
23
    use CompileEmpty;
24
25
    /**
26
     * @var boolean
27
     */
28
    protected $escapeOutput = false;
29
30
    /**
31
     * @return string the contents of this view helper if no other "Case" view helper of the surrounding switch view helper matches
32
     * @throws ViewHelper\Exception
33
     * @api
34
     */
35
    public function render()
36
    {
37
        $viewHelperVariableContainer = $this->renderingContext->getViewHelperVariableContainer();
38
        if (!$viewHelperVariableContainer->exists(SwitchViewHelper::class, 'switchExpression')) {
39
            throw new ViewHelper\Exception('The "default case" View helper can only be used within a switch View helper', 1368112037);
40
        }
41
        return $this->renderChildren();
42
    }
43
}
44