searchiterator.inc 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. /** @file searchiterator.inc
  3. * @ingroup Examples
  4. * @brief abstract class SearchIterator
  5. * @author Marcus Boerger
  6. * @date 2003 - 2005
  7. *
  8. * SPL - Standard PHP Library
  9. */
  10. /** @ingroup Examples
  11. * @brief Iterator to search for a specific element
  12. * @author Marcus Boerger
  13. * @version 1.0
  14. *
  15. * This extended FilterIterator stops after finding the first acceptable
  16. * value.
  17. */
  18. abstract class SearchIterator extends FilterIterator
  19. {
  20. /** @internal whether an entry was found already */
  21. private $done = false;
  22. /** Rewind and reset so that it once again searches.
  23. * @return void
  24. */
  25. function rewind()
  26. {
  27. parent::rewind();
  28. $this->done = false;
  29. }
  30. /** @return whether the current element is valid
  31. * which can only happen once per iteration.
  32. */
  33. function valid()
  34. {
  35. return !$this->done && parent::valid();
  36. }
  37. /** Do not move forward but instead mark as finished.
  38. * @return void
  39. */
  40. function next()
  41. {
  42. $this->done = true;
  43. }
  44. /** Aggregates the inner iterator
  45. */
  46. function __call($func, $params)
  47. {
  48. return call_user_func_array(array($this->getInnerIterator(), $func), $params);
  49. }
  50. }
  51. ?>