TYPO3  7.6
CaseViewHelper.php
Go to the documentation of this file.
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 
18 
26 {
36  public function render($value = null, $default = false)
37  {
38  return static::renderStatic(
39  array(
40  'value' => $value,
41  'default' => $default
42  ),
44  $this->renderingContext
45  );
46  }
47 
57  {
58  $value = $arguments['value'];
59  $default = $arguments['default'];
61  if (!$viewHelperVariableContainer->exists(SwitchViewHelper::class, 'stateStack')) {
62  throw new Exception('The case View helper can only be used within a switch View helper', 1368112037);
63  }
64  if (is_null($value) && $default === false) {
65  throw new Exception('The case View helper must have either value or default argument', 1382867521);
66  }
67  $stateStack = $viewHelperVariableContainer->get(SwitchViewHelper::class, 'stateStack');
68  $currentState = array_pop($stateStack);
69 
70  if ($currentState['break'] === true) {
71  return '';
72  }
73 
74  // non-type-safe comparison by intention
75  if ($default === true || $currentState['expression'] == $value) {
76  $currentState['break'] = true;
77  $stateStack[] = $currentState;
78  $viewHelperVariableContainer->addOrUpdate(SwitchViewHelper::class, 'stateStack', $stateStack);
79  return $renderChildrenClosure();
80  }
81 
82  return '';
83  }
84 }