PageRenderTime 39ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 1ms

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

https://github.com/andreaswolf/typo3-tceforms
PHP | 89 lines | 30 code | 9 blank | 50 comment | 6 complexity | a57e40bbad23ebd0f15b7e643efe5442 MD5 | raw file
Possible License(s): Apache-2.0, BSD-2-Clause, LGPL-3.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. * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
  25. */
  26. abstract class Tx_Fluid_Core_Parser_SyntaxTree_AbstractNode implements Tx_Fluid_Core_Parser_SyntaxTree_NodeInterface {
  27. /**
  28. * List of Child Nodes.
  29. * @var array<Tx_Fluid_Core_Parser_SyntaxTree_NodeInterface>
  30. */
  31. protected $childNodes = array();
  32. /**
  33. * Evaluate all child nodes and return the evaluated results.
  34. *
  35. * @param Tx_Fluid_Core_Rendering_RenderingContextInterface $renderingContext
  36. * @return mixed Normally, an object is returned - in case it is concatenated with a string, a string is returned.
  37. * @author Sebastian Kurfürst <sebastian@typo3.org>
  38. * @author Bastian Waidelich <bastian@typo3.org>
  39. */
  40. public function evaluateChildNodes(Tx_Fluid_Core_Rendering_RenderingContextInterface $renderingContext) {
  41. $output = NULL;
  42. foreach ($this->childNodes as $subNode) {
  43. if ($output === NULL) {
  44. $output = $subNode->evaluate($renderingContext);
  45. } else {
  46. if (is_object($output) && !method_exists($output, '__toString')) {
  47. throw new Tx_Fluid_Core_Parser_Exception('Cannot cast object of type "' . get_class($output) . '" to string.', 1248356140);
  48. }
  49. $output = (string)$output;
  50. $subNodeOutput = $subNode->evaluate($renderingContext);
  51. if (is_object($subNodeOutput) && !method_exists($subNodeOutput, '__toString')) {
  52. throw new Tx_Fluid_Core_Parser_Exception('Cannot cast object of type "' . get_class($subNodeOutput) . '" to string.', 1273753083);
  53. }
  54. $output .= (string)$subNodeOutput;
  55. }
  56. }
  57. return $output;
  58. }
  59. /**
  60. * Returns all child nodes for a given node.
  61. * This is especially needed to implement the boolean expression language.
  62. *
  63. * @return array<Tx_Fluid_Core_Parser_SyntaxTree_NodeInterface> A list of nodes
  64. * @author Sebastian Kurfürst <sebastian@typo3.org>
  65. */
  66. public function getChildNodes() {
  67. return $this->childNodes;
  68. }
  69. /**
  70. * Appends a subnode to this node. Is used inside the parser to append children
  71. *
  72. * @param Tx_Fluid_Core_Parser_SyntaxTree_NodeInterface $childNode The subnode to add
  73. * @return void
  74. * @author Sebastian Kurfürst <sebastian@typo3.org>
  75. */
  76. public function addChildNode(Tx_Fluid_Core_Parser_SyntaxTree_NodeInterface $childNode) {
  77. $this->childNodes[] = $childNode;
  78. }
  79. }
  80. ?>