PPNode.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. /**
  3. * This program is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation; either version 2 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License along
  14. * with this program; if not, write to the Free Software Foundation, Inc.,
  15. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  16. * http://www.gnu.org/copyleft/gpl.html
  17. *
  18. * @file
  19. * @ingroup Parser
  20. */
  21. /**
  22. * There are three types of nodes:
  23. * * Tree nodes, which have a name and contain other nodes as children
  24. * * Array nodes, which also contain other nodes but aren't considered part of a tree
  25. * * Leaf nodes, which contain the actual data
  26. *
  27. * This interface provides access to the tree structure and to the contents of array nodes,
  28. * but it does not provide access to the internal structure of leaf nodes. Access to leaf
  29. * data is provided via two means:
  30. * * PPFrame::expand(), which provides expanded text
  31. * * The PPNode::split*() functions, which provide metadata about certain types of tree node
  32. * @ingroup Parser
  33. */
  34. interface PPNode {
  35. /**
  36. * Get an array-type node containing the children of this node.
  37. * Returns false if this is not a tree node.
  38. * @return false|PPNode
  39. */
  40. public function getChildren();
  41. /**
  42. * Get the first child of a tree node. False if there isn't one.
  43. *
  44. * @return false|PPNode
  45. */
  46. public function getFirstChild();
  47. /**
  48. * Get the next sibling of any node. False if there isn't one
  49. * @return false|PPNode
  50. */
  51. public function getNextSibling();
  52. /**
  53. * Get all children of this tree node which have a given name.
  54. * Returns an array-type node, or false if this is not a tree node.
  55. * @param string $type
  56. * @return false|PPNode
  57. */
  58. public function getChildrenOfType( $type );
  59. /**
  60. * Returns the length of the array, or false if this is not an array-type node
  61. */
  62. public function getLength();
  63. /**
  64. * Returns an item of an array-type node
  65. * @param int $i
  66. * @return bool|PPNode
  67. */
  68. public function item( $i );
  69. /**
  70. * Get the name of this node. The following names are defined here:
  71. *
  72. * h A heading node.
  73. * template A double-brace node.
  74. * tplarg A triple-brace node.
  75. * title The first argument to a template or tplarg node.
  76. * part Subsequent arguments to a template or tplarg node.
  77. * #nodelist An array-type node
  78. *
  79. * The subclass may define various other names for tree and leaf nodes.
  80. * @return string
  81. */
  82. public function getName();
  83. /**
  84. * Split a "<part>" node into an associative array containing:
  85. * name PPNode name
  86. * index String index
  87. * value PPNode value
  88. * @return array
  89. */
  90. public function splitArg();
  91. /**
  92. * Split an "<ext>" node into an associative array containing name, attr, inner and close
  93. * All values in the resulting array are PPNodes. Inner and close are optional.
  94. * @return array
  95. */
  96. public function splitExt();
  97. /**
  98. * Split an "<h>" node
  99. * @return array
  100. */
  101. public function splitHeading();
  102. }