recursiveregexiterator.inc 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. /** @file recursiveregexiterator.inc
  3. * @ingroup SPL
  4. * @brief class RegexIterator
  5. * @author Marcus Boerger
  6. * @date 2003 - 2009
  7. *
  8. * SPL - Standard PHP Library
  9. */
  10. /**
  11. * @brief Recursive regular expression filter for iterators
  12. * @author Marcus Boerger
  13. * @version 1.0
  14. * @since PHP 5.1
  15. *
  16. * This filter iterator assumes that the inner iterator
  17. */
  18. class RecursiveRegexIterator extends RegexIterator implements RecursiveIterator
  19. {
  20. /**
  21. * Constructs a regular expression filter around an iterator whose
  22. * elemnts or keys are strings.
  23. *
  24. * @param it inner iterator
  25. * @param regex the regular expression to match
  26. * @param mode operation mode (one of self::MATCH, self::GET_MATCH,
  27. * self::ALL_MATCHES, self::SPLIT)
  28. * @param flags special flags (self::USE_KEY)
  29. * @param preg_flags global PREG_* flags, see preg_match(),
  30. * preg_match_all(), preg_split()
  31. */
  32. function __construct(RecursiveIterator $it, $regex, $mode = 0, $flags = 0, $preg_flags = 0) {
  33. parent::__construct($it, $regex, $mode, $flags, $preg_flags);
  34. }
  35. /** @return whether the current element has children
  36. */
  37. function hasChildren()
  38. {
  39. return $this->getInnerIterator()->hasChildren();
  40. }
  41. /** @return an iterator for the current elements children
  42. *
  43. * @note the returned iterator will be of the same class as $this
  44. */
  45. function getChildren()
  46. {
  47. if (empty($this->ref))
  48. {
  49. $this->ref = new ReflectionClass($this);
  50. }
  51. return $this->ref->newInstance($this->getInnerIterator()->getChildren());
  52. }
  53. private $ref;
  54. }
  55. ?>