[TASK] Remove closing PHP tags
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Classes / ViewHelpers / CaseViewHelper.php
1 <?php
2 namespace TYPO3\CMS\Fluid\ViewHelpers;
3
4 /* *
5 * This script is backported from the TYPO3 Flow package "TYPO3.Fluid". *
6 * *
7 * It is free software; you can redistribute it and/or modify it under *
8 * the terms of the GNU Lesser General Public License, either version 3 *
9 * of the License, or (at your option) any later version. *
10 * *
11 * The TYPO3 project - inspiring people to share! *
12 * */
13
14 /**
15 * Case view helper that is only usable within the SwitchViewHelper.
16 * @see \TYPO3\CMS\Fluid\ViewHelpers\SwitchViewHelper
17 *
18 * @api
19 */
20 class CaseViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper {
21
22 /**
23 * @param mixed $value
24 * @return string the contents of this view helper if $value equals the expression of the surrounding switch view helper, otherwise an empty string
25 * @throws \TYPO3\CMS\Fluid\Core\ViewHelper\Exception
26 * @api
27 */
28 public function render($value) {
29 $viewHelperVariableContainer = $this->renderingContext->getViewHelperVariableContainer();
30 if (!$viewHelperVariableContainer->exists('TYPO3\CMS\Fluid\ViewHelpers\SwitchViewHelper', 'switchExpression')) {
31 throw new \TYPO3\CMS\Fluid\Core\ViewHelper\Exception('The case View helper can only be used within a switch View helper', 1368112037);
32 }
33 $switchExpression = $viewHelperVariableContainer->get('TYPO3\CMS\Fluid\ViewHelpers\SwitchViewHelper', 'switchExpression');
34
35 // non-type-safe comparison by intention
36 if ($switchExpression == $value) {
37 $viewHelperVariableContainer->addOrUpdate('TYPO3\CMS\Fluid\ViewHelpers\SwitchViewHelper', 'break', TRUE);
38 return $this->renderChildren();
39 }
40 return '';
41 }
42 }