TokenList.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Markup
  17. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  18. * @license http://framework.zend.com/license/new-bsd New BSD License
  19. * @version $Id$
  20. */
  21. /**
  22. * @see Zend_Markup_Token
  23. */
  24. require_once 'Zend/Markup/Token.php';
  25. /**
  26. * @category Zend
  27. * @package Zend_Markup
  28. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  29. * @license http://framework.zend.com/license/new-bsd New BSD License
  30. */
  31. class Zend_Markup_TokenList implements RecursiveIterator
  32. {
  33. /**
  34. * Array of tokens
  35. *
  36. * @var array
  37. */
  38. protected $_tokens = array();
  39. /**
  40. * Get the current token
  41. *
  42. * @return Zend_Markup_Token
  43. */
  44. public function current()
  45. {
  46. return current($this->_tokens);
  47. }
  48. /**
  49. * Get the children of the current token
  50. *
  51. * @return Zend_Markup_TokenList
  52. */
  53. public function getChildren()
  54. {
  55. return current($this->_tokens)->getChildren();
  56. }
  57. /**
  58. * Add a new child token
  59. *
  60. * @param Zend_Markup_Token $child
  61. *
  62. * @return void
  63. */
  64. public function addChild(Zend_Markup_Token $child)
  65. {
  66. $this->_tokens[] = $child;
  67. }
  68. /**
  69. * Check if the current token has children
  70. *
  71. * @return bool
  72. */
  73. public function hasChildren()
  74. {
  75. return current($this->_tokens)->hasChildren();
  76. }
  77. /**
  78. * Get the key of the current token
  79. *
  80. * @return int
  81. */
  82. public function key()
  83. {
  84. return key($this->_tokens);
  85. }
  86. /**
  87. * Go to the next token
  88. *
  89. * @return Zend_Markup_Token
  90. */
  91. public function next()
  92. {
  93. return next($this->_tokens);
  94. }
  95. /**
  96. * Rewind the iterator
  97. *
  98. * @return void
  99. */
  100. public function rewind()
  101. {
  102. reset($this->_tokens);
  103. }
  104. /**
  105. * Check if the element is valid
  106. *
  107. * @return void
  108. */
  109. public function valid()
  110. {
  111. return $this->current() !== false;
  112. }
  113. }