[TASK] Sync CMS Fluid with Flow Fluid 1.1 (part1)
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Classes / Core / Parser / SyntaxTree / AbstractNode.php
1 <?php
2 namespace TYPO3\CMS\Fluid\Core\Parser\SyntaxTree;
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 * Abstract node in the syntax tree which has been built.
16 */
17 abstract class AbstractNode implements \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\NodeInterface {
18
19 /**
20 * List of Child Nodes.
21 *
22 * @var array<\TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\NodeInterface>
23 */
24 protected $childNodes = array();
25
26 /**
27 * Evaluate all child nodes and return the evaluated results.
28 *
29 * @param \TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface $renderingContext
30 * @return mixed Normally, an object is returned - in case it is concatenated with a string, a string is returned.
31 * @throws \TYPO3\CMS\Fluid\Core\Parser\Exception
32 */
33 public function evaluateChildNodes(\TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface $renderingContext) {
34 $output = NULL;
35 foreach ($this->childNodes as $subNode) {
36 if ($output === NULL) {
37 $output = $subNode->evaluate($renderingContext);
38 } else {
39 if (is_object($output)) {
40 if (!method_exists($output, '__toString')) {
41 throw new \TYPO3\CMS\Fluid\Core\Parser\Exception('Cannot cast object of type "' . get_class($output) . '" to string.', 1248356140);
42 }
43 $output = $output->__toString();
44 } else {
45 $output = (string) $output;
46 }
47 $subNodeOutput = $subNode->evaluate($renderingContext);
48
49 if (is_object($subNodeOutput)) {
50 if (!method_exists($subNodeOutput, '__toString')) {
51 throw new \TYPO3\CMS\Fluid\Core\Parser\Exception('Cannot cast object of type "' . get_class($subNodeOutput) . '" to string.', 1273753083);
52 }
53 $output .= $subNodeOutput->__toString();
54 } else {
55 $output .= (string) $subNodeOutput;
56 }
57 }
58 }
59 return $output;
60 }
61
62 /**
63 * Returns all child nodes for a given node.
64 * This is especially needed to implement the boolean expression language.
65 *
66 * @return array<\TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\NodeInterface> A list of nodes
67 */
68 public function getChildNodes() {
69 return $this->childNodes;
70 }
71
72 /**
73 * Appends a subnode to this node. Is used inside the parser to append children
74 *
75 * @param \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\NodeInterface $childNode The subnode to add
76 * @return void
77 */
78 public function addChildNode(\TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\NodeInterface $childNode) {
79 $this->childNodes[] = $childNode;
80 }
81 }
82
83 ?>