SegmentIterator.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. /**
  3. * Segments iterator
  4. * You need PHP 5.2 at least
  5. * You need Zip Extension or PclZip library
  6. * Encoding : ISO-8859-1
  7. * Last commit by $Author: neveldo $
  8. * Date - $Date: 2009-06-17 11:11:57 +0200 (mer., 17 juin 2009) $
  9. * SVN Revision - $Rev: 42 $
  10. * Id : $Id: SegmentIterator.php 42 2009-06-17 09:11:57Z neveldo $
  11. *
  12. * @copyright GPL License 2008 - Julien Pauli - Cyril PIERRE de GEYER - Anaska (http://www.anaska.com)
  13. * @license http://www.gnu.org/copyleft/gpl.html GPL License
  14. * @version 1.3
  15. */
  16. class SegmentIterator implements RecursiveIterator
  17. {
  18. private $ref;
  19. private $key;
  20. public function __construct(array $ref)
  21. {
  22. $this->ref = $ref;
  23. $this->key = 0;
  24. $this->keys = array_keys($this->ref);
  25. }
  26. public function hasChildren()
  27. {
  28. return $this->valid() && $this->current() instanceof Segment;
  29. }
  30. public function current()
  31. {
  32. return $this->ref[$this->keys[$this->key]];
  33. }
  34. function getChildren()
  35. {
  36. return new self($this->current()->children);
  37. }
  38. public function key()
  39. {
  40. return $this->key;
  41. }
  42. public function valid()
  43. {
  44. return array_key_exists($this->key, $this->keys);
  45. }
  46. public function rewind()
  47. {
  48. $this->key = 0;
  49. }
  50. public function next()
  51. {
  52. $this->key ++;
  53. }
  54. }
  55. ?>