[TASK] Remove ext:dbal from installation steps
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Classes / ViewHelpers / SwitchViewHelper.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 use TYPO3Fluid\Fluid\Core\Compiler\StopCompilingException;
15 use TYPO3Fluid\Fluid\Core\Compiler\TemplateCompiler;
16 use TYPO3Fluid\Fluid\Core\Parser\SyntaxTree\NodeInterface;
17 use TYPO3Fluid\Fluid\Core\Parser\SyntaxTree\ViewHelperNode;
18 use TYPO3Fluid\Fluid\ViewHelpers\CaseViewHelper as OriginalCaseViewHelper;
19 use TYPO3Fluid\Fluid\ViewHelpers\DefaultCaseViewHelper;
20
21 /**
22 * Switch view helper which can be used to render content depending on a value or expression.
23 * Implements what a basic switch()-PHP-method does.
24 *
25 * = Examples =
26 *
27 * <code title="Simple Switch statement">
28 * <f:switch expression="{person.gender}">
29 * <f:case value="male">Mr.</f:case>
30 * <f:case value="female">Mrs.</f:case>
31 * <f:defaultCase>Mrs. or Mr.</f:defaultCase>
32 * </f:switch>
33 * </code>
34 * <output>
35 * Mr. / Mrs. (depending on the value of {person.gender}) or if no value evaluates to TRUE, defaultCase
36 * </output>
37 *
38 * Note: Using this view helper can be a sign of weak architecture. If you end up using it extensively
39 * you might want to consider restructuring your controllers/actions and/or use partials and sections.
40 * E.g. the above example could be achieved with <f:render partial="title.{person.gender}" /> and the partials
41 * "title.male.html", "title.female.html", ...
42 * Depending on the scenario this can be easier to extend and possibly contains less duplication.
43 *
44 * @api
45 */
46 class SwitchViewHelper extends \TYPO3Fluid\Fluid\ViewHelpers\SwitchViewHelper
47 {
48 /**
49 * @param NodeInterface $node
50 * @return bool
51 */
52 protected function isDefaultCaseNode(NodeInterface $node)
53 {
54 if ($node instanceof ViewHelperNode) {
55 $viewHelperClassName = $node->getViewHelperClassName();
56 $arguments = $node->getArguments();
57 return (
58 $viewHelperClassName === DefaultCaseViewHelper::class ||
59 (
60 $viewHelperClassName === CaseViewHelper::class && isset($arguments['default']) && $arguments['default']
61 )
62 );
63 }
64 return false;
65 }
66
67 /**
68 * @param NodeInterface $node
69 * @return bool
70 */
71 protected function isCaseNode(NodeInterface $node)
72 {
73 if ($node instanceof ViewHelperNode) {
74 $viewHelperClassName = $node->getViewHelperClassName();
75 return ($viewHelperClassName === CaseViewHelper::class || $viewHelperClassName === OriginalCaseViewHelper::class);
76 }
77 return false;
78 }
79
80 /**
81 * @param string $argumentsName
82 * @param string $closureName
83 * @param string $initializationPhpCode
84 * @param ViewHelperNode $node
85 * @param TemplateCompiler $compiler
86 */
87 public function compile($argumentsName, $closureName, &$initializationPhpCode, ViewHelperNode $node, TemplateCompiler $compiler)
88 {
89 if (count($node->getChildNodes())) {
90 throw new StopCompilingException();
91 }
92 }
93 }