SPL-StandardPHPLibrary
Public Member Functions | Protected Member Functions | Private Attributes | List of all members
FilterIterator Class Reference
Inheritance diagram for FilterIterator:
Inheritance graph
Collaboration diagram for FilterIterator:
Collaboration graph

Public Member Functions

 __call ($func, $params)
 
 __construct (Iterator $it)
 
 accept ()
 
 current ()
 
 getInnerIterator ()
 
 key ()
 
 next ()
 
 rewind ()
 
 valid ()
 

Protected Member Functions

 __clone ()
 
 fetch ()
 

Private Attributes

 $it
 

Detailed Description

Abstract filter for iterators.

Author
Marcus Boerger
Version
1.1
Since
PHP 5.0

Instances of this class act as a filter around iterators. In other words you can put an iterator into the constructor and the instance will only return selected (accepted) elements.

The only thing that needs to be done to make this work is implementing method accept(). Typically this invloves reading the current element or key of the inner Iterator and checking whether it is acceptable.

Definition at line 26 of file filteriterator.inc.

Constructor & Destructor Documentation

FilterIterator::__construct ( Iterator  $it)

Constructs a filter around another iterator.

Parameters
itIterator to filter

Definition at line 35 of file filteriterator.inc.

References $it.

35  {
36  $this->it = $it;
37  }

Member Function Documentation

FilterIterator::__call (   $func,
  $params 
)

Aggregate the inner iterator.

Parameters
funcName of method to invoke
paramsArray of parameters to pass to method

Definition at line 121 of file filteriterator.inc.

122  {
123  return call_user_func_array(array($this->it, $func), $params);
124  }
FilterIterator::__clone ( )
protected

hidden __clone

Definition at line 104 of file filteriterator.inc.

104  {
105  // disallow clone
106  }
FilterIterator::accept ( )
abstract

Accept function to decide whether an element of the inner iterator should be accessible through the Filteriterator.

Returns
whether or not to expose the current element of the inner iterator.

Referenced by fetch().

FilterIterator::current ( )
Returns
The current value

Implements Iterator.

Definition at line 97 of file filteriterator.inc.

Referenced by RegexFindFile\accept(), and FindFile\accept().

97  {
98  return $this->it->current();
99  }
FilterIterator::fetch ( )
protected

Fetch next element and store it.

Returns
void

Definition at line 61 of file filteriterator.inc.

References accept().

Referenced by next(), and rewind().

61  {
62  while ($this->it->valid()) {
63  if ($this->accept()) {
64  return;
65  }
66  $this->it->next();
67  };
68  }
accept()
Accept function to decide whether an element of the inner iterator should be accessible through the F...

Here is the call graph for this function:

FilterIterator::getInnerIterator ( )
FilterIterator::key ( )
Returns
The current key

Implements Iterator.

Definition at line 90 of file filteriterator.inc.

Referenced by KeyFilter\accept().

90  {
91  return $this->it->key();
92  }
FilterIterator::next ( )

Move to next element.

Returns
void

Implements Iterator.

Definition at line 75 of file filteriterator.inc.

References fetch().

75  {
76  $this->it->next();
77  $this->fetch();
78  }
fetch()
Fetch next element and store it.

Here is the call graph for this function:

FilterIterator::rewind ( )

Rewind the inner iterator.

Implements Iterator.

Definition at line 42 of file filteriterator.inc.

References fetch().

42  {
43  $this->it->rewind();
44  $this->fetch();
45  }
fetch()
Fetch next element and store it.

Here is the call graph for this function:

FilterIterator::valid ( )
Returns
Whether more elements are available

Implements Iterator.

Definition at line 83 of file filteriterator.inc.

83  {
84  return $this->it->valid();
85  }

Member Data Documentation

FilterIterator::$it
private

Definition at line 28 of file filteriterator.inc.

Referenced by FindFile\__construct(), __construct(), and getInnerIterator().


The documentation for this class was generated from the following file: