[FEATURE] Support literal strings in boolean arguments
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Classes / Core / Parser / SyntaxTree / NumericNode.php
1 <?php
2 namespace TYPO3\CMS\Fluid\Core\Parser\SyntaxTree;
3
4 /* *
5 * This script belongs to the TYPO3 Flow package "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 * Numeric Syntax Tree Node - is a container for numerics.
16 *
17 */
18 class NumericNode extends \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\AbstractNode {
19
20 /**
21 * Contents of the numeric node
22 * @var number
23 */
24 protected $value;
25
26 /**
27 * Constructor.
28 *
29 * @param string|number $value value to store in this numericNode
30 * @throws \TYPO3\CMS\Fluid\Core\Parser\Exception
31 */
32 public function __construct($value) {
33 if (!is_numeric($value)) {
34 throw new \TYPO3\CMS\Fluid\Core\Parser\Exception('Numeric node requires an argument of type number, "' . gettype($value) . '" given.', 1360414192);
35 }
36 $this->value = $value + 0;
37 }
38
39 /**
40 * Return the value associated to the syntax tree.
41 *
42 * @param \TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface $renderingContext
43 * @return number the value stored in this node/subtree.
44 */
45 public function evaluate(\TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface $renderingContext) {
46 return $this->value;
47 }
48
49 /**
50 * Getter for value
51 *
52 * @return number The value of this node
53 */
54 public function getValue() {
55 return $this->value;
56 }
57
58 /**
59 * NumericNode does not allow adding child nodes, so this will always throw an exception.
60 *
61 * @param \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\NodeInterface $childNode The subnode to add
62 * @throws \TYPO3\CMS\Fluid\Core\Parser\Exception
63 * @return void
64 */
65 public function addChildNode(\TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\NodeInterface $childNode) {
66 throw new \TYPO3\CMS\Fluid\Core\Parser\Exception('Numeric nodes may not contain child nodes, tried to add "' . get_class($childNode) . '".', 1360414193);
67 }
68 }
69
70 ?>