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