PageRenderTime 42ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/typo3/sysext/fluid/Classes/Core/Parser/SyntaxTree/AbstractNode.php

https://bitbucket.org/linxpinx/mercurial
PHP | 109 lines | 35 code | 12 blank | 62 comment | 6 complexity | 9220de6fae0bcc526681ca6371e74a98 MD5 | raw file
Possible License(s): BSD-3-Clause, GPL-2.0, Unlicense, LGPL-2.1, Apache-2.0
  1. <?php
  2. /* *
  3. * This script belongs to the FLOW3 package "Fluid". *
  4. * *
  5. * It is free software; you can redistribute it and/or modify it under *
  6. * the terms of the GNU Lesser General Public License as published by the *
  7. * Free Software Foundation, either version 3 of the License, or (at your *
  8. * option) any later version. *
  9. * *
  10. * This script is distributed in the hope that it will be useful, but *
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- *
  12. * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser *
  13. * General Public License for more details. *
  14. * *
  15. * You should have received a copy of the GNU Lesser General Public *
  16. * License along with the script. *
  17. * If not, see http://www.gnu.org/licenses/lgpl.html *
  18. * *
  19. * The TYPO3 project - inspiring people to share! *
  20. * */
  21. /**
  22. * Abstract node in the syntax tree which has been built.
  23. *
  24. * @version $Id: AbstractNode.php 2043 2010-03-16 08:49:45Z sebastian $
  25. * @package Fluid
  26. * @subpackage Core\Parser\SyntaxTree
  27. * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
  28. * @scope prototype
  29. */
  30. abstract class Tx_Fluid_Core_Parser_SyntaxTree_AbstractNode implements Tx_Fluid_Core_Parser_SyntaxTree_NodeInterface {
  31. /**
  32. * List of Child Nodes.
  33. * @var array<Tx_Fluid_Core_Parser_SyntaxTree_NodeInterface>
  34. */
  35. protected $childNodes = array();
  36. /**
  37. * The rendering context containing everything to correctly render the subtree
  38. * @var Tx_Fluid_Core_Rendering_RenderingContext
  39. */
  40. protected $renderingContext;
  41. /**
  42. * @param Tx_Fluid_Core_Rendering_RenderingContext $renderingContext Rendering Context to be used for this evaluation
  43. * @return void
  44. * @author Sebastian Kurf?rst <sebastian@typo3.org>
  45. */
  46. public function setRenderingContext(Tx_Fluid_Core_Rendering_RenderingContext $renderingContext) {
  47. $this->renderingContext = $renderingContext;
  48. }
  49. /**
  50. * Evaluate all child nodes and return the evaluated results.
  51. *
  52. * @return mixed Normally, an object is returned - in case it is concatenated with a string, a string is returned.
  53. * @author Sebastian Kurf?rst <sebastian@typo3.org>
  54. * @author Bastian Waidelich <bastian@typo3.org>
  55. */
  56. public function evaluateChildNodes() {
  57. $output = NULL;
  58. foreach ($this->childNodes as $subNode) {
  59. $subNode->setRenderingContext($this->renderingContext);
  60. if ($output === NULL) {
  61. $output = $subNode->evaluate();
  62. } else {
  63. if (is_object($output) && !method_exists($output, '__toString')) {
  64. throw new Tx_Fluid_Core_Parser_Exception('Cannot cast object of type "' . get_class($output) . '" to string.', 1248356140);
  65. }
  66. $output = (string)$output;
  67. $subNodeOutput = $subNode->evaluate();
  68. if (is_object($subNodeOutput) && !method_exists($subNodeOutput, '__toString')) {
  69. throw new Tx_Fluid_Core_Parser_Exception('Cannot cast object of type "' . get_class($subNodeOutput) . '" to string.', 1273753083);
  70. }
  71. $output .= (string)$subNodeOutput;
  72. }
  73. }
  74. return $output;
  75. }
  76. /**
  77. * Returns all child nodes for a given node.
  78. * This is especially needed to implement the boolean expression language.
  79. *
  80. * @return array<Tx_Fluid_Core_Parser_SyntaxTree_NodeInterface> A list of nodes
  81. * @author Sebastian Kurf?rst <sebastian@typo3.org>
  82. */
  83. public function getChildNodes() {
  84. return $this->childNodes;
  85. }
  86. /**
  87. * Appends a subnode to this node. Is used inside the parser to append children
  88. *
  89. * @param Tx_Fluid_Core_Parser_SyntaxTree_NodeInterface $childNode The subnode to add
  90. * @return void
  91. * @author Sebastian Kurf?rst <sebastian@typo3.org>
  92. */
  93. public function addChildNode(Tx_Fluid_Core_Parser_SyntaxTree_NodeInterface $childNode) {
  94. $this->childNodes[] = $childNode;
  95. }
  96. }
  97. ?>