forked from TYPO3/Fluid
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCaseViewHelper.php
More file actions
72 lines (64 loc) · 2.21 KB
/
CaseViewHelper.php
File metadata and controls
72 lines (64 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
namespace TYPO3Fluid\Fluid\ViewHelpers;
/*
* This file belongs to the package "TYPO3 Fluid".
* See LICENSE.txt that was shipped with this package.
*/
use TYPO3Fluid\Fluid\Core\Compiler\TemplateCompiler;
use TYPO3Fluid\Fluid\Core\Parser\SyntaxTree\ViewHelperNode;
use TYPO3Fluid\Fluid\Core\ViewHelper;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
/**
* Case ViewHelper that is only usable within the ``f:switch`` ViewHelper.
*
* @see \TYPO3Fluid\Fluid\ViewHelpers\SwitchViewHelper
*
* @api
*/
class CaseViewHelper extends AbstractViewHelper
{
/**
* @var boolean
*/
protected $escapeOutput = false;
/**
* @return void
*/
public function initializeArguments()
{
parent::initializeArguments();
$this->registerArgument('value', 'mixed', 'Value to match in this case', true);
}
/**
* @return string the contents of this ViewHelper if $value equals the expression of the surrounding switch ViewHelper, otherwise an empty string
* @throws ViewHelper\Exception
* @api
*/
public function render()
{
$value = $this->arguments['value'];
$viewHelperVariableContainer = $this->renderingContext->getViewHelperVariableContainer();
if (!$viewHelperVariableContainer->exists(SwitchViewHelper::class, 'switchExpression')) {
throw new ViewHelper\Exception('The "case" ViewHelper can only be used within a switch ViewHelper', 1368112037);
}
$switchExpression = $viewHelperVariableContainer->get(SwitchViewHelper::class, 'switchExpression');
// non-type-safe comparison by intention
if ($switchExpression == $value) {
$viewHelperVariableContainer->addOrUpdate(SwitchViewHelper::class, 'break', true);
return $this->renderChildren();
}
return '';
}
/**
* @param string $argumentsName
* @param string $closureName
* @param string $initializationPhpCode
* @param ViewHelperNode $node
* @param TemplateCompiler $compiler
* @return string
*/
public function compile($argumentsName, $closureName, &$initializationPhpCode, ViewHelperNode $node, TemplateCompiler $compiler)
{
return '\'\'';
}
}