1<?php
2
3/** @file recursivefilteriterator.inc
4 * @ingroup SPL
5 * @brief class RecursiveFilterIterator
6 * @author  Marcus Boerger
7 * @date    2003 - 2009
8 *
9 * SPL - Standard PHP Library
10 */
11
12/** @ingroup SPL
13 * @brief   Iterator to filter recursive iterators
14 * @author  Marcus Boerger
15 * @version 1.0
16 * @since PHP 5.1
17 *
18 * Passes the RecursiveIterator interface to the inner Iterator and provides
19 * the same functionality as FilterIterator. This allows you to skip parents
20 * and all their childs before loading them all. You need to care about
21 * function getChildren() because it may not always suit your needs. The
22 * builtin behavior uses reflection to return a new instance of the exact same
23 * class it is called from. That is you extend RecursiveFilterIterator and
24 * getChildren() will create instance of that class. The problem is that doing
25 * this does not transport any state or control information of your accept()
26 * implementation to the new instance. To overcome this problem you might
27 * need to overwrite getChildren(), call this implementation and pass the
28 * control vaules manually.
29 */
30abstract class RecursiveFilterIterator extends FilterIterator implements RecursiveIterator
31{
32	/** @param $it the RecursiveIterator to filter
33	 */
34	function __construct(RecursiveIterator $it)
35	{
36		parent::__construct($it);
37	}
38
39	/** @return whether the current element has children
40	 */
41	function hasChildren()
42	{
43		return $this->getInnerIterator()->hasChildren();
44	}
45
46	/** @return an iterator for the current elements children
47	 *
48	 * @note the returned iterator will be of the same class as $this
49	 */
50	function getChildren()
51	{
52		if (empty($this->ref))
53		{
54			$this->ref = new ReflectionClass($this);
55		}
56		return $this->ref->newInstance($this->getInnerIterator()->getChildren());
57	}
58
59	private $ref;
60}
61
62?>
63