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

Public Member Functions

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

Protected Member Functions

 __clone ()
 
 fetch ()
 

Private Attributes

 $regex
 

Detailed Description

Regular expression filter for string iterators.

Author
Marcus Boerger
Version
1.1

Instances of this class act as a filter around iterators whose elements are strings. In other words you can put an iterator into the constructor and the instance will only return elements which match the given regular expression.

Definition at line 22 of file keyfilter.inc.

Constructor & Destructor Documentation

KeyFilter::__construct ( Iterator  $it,
  $regex 
)

Constructs a filter around an iterator whose elemnts are strings.

If the given iterator is of type spl_sequence then its rewind() method is called.

Parameters
itObject that implements at least spl_forward
regexRegular expression used as a filter.

Definition at line 35 of file keyfilter.inc.

References $regex.

36  {
37  parent::__construct($it);
38  $this->regex = $regex;
39  }

Member Function Documentation

FilterIterator::__call (   $func,
  $params 
)
inherited

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  }
KeyFilter::__clone ( )
protected

hidden __clone

Definition at line 58 of file keyfilter.inc.

59  {
60  // disallow clone
61  }
KeyFilter::accept ( )
Returns
whether the current key mathes the regular expression

Definition at line 43 of file keyfilter.inc.

References FilterIterator\getInnerIterator(), and FilterIterator\key().

44  {
45  return ereg($this->regex, $this->getInnerIterator()->key());
46  }

Here is the call graph for this function:

FilterIterator::current ( )
inherited
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 ( )
protectedinherited

Fetch next element and store it.

Returns
void

Definition at line 61 of file filteriterator.inc.

References FilterIterator\accept().

Referenced by FilterIterator\next(), and FilterIterator\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 ( )
inherited
KeyFilter::getRegex ( )
Returns
regular expression used as filter

Definition at line 50 of file keyfilter.inc.

References $regex.

51  {
52  return $this->regex;
53  }
FilterIterator::key ( )
inherited
Returns
The current key

Implements Iterator.

Definition at line 90 of file filteriterator.inc.

Referenced by accept().

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

Move to next element.

Returns
void

Implements Iterator.

Definition at line 75 of file filteriterator.inc.

References FilterIterator\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 ( )
inherited

Rewind the inner iterator.

Implements Iterator.

Definition at line 42 of file filteriterator.inc.

References FilterIterator\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 ( )
inherited
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

KeyFilter::$regex
private

regular exoression used as filter

Definition at line 25 of file keyfilter.inc.

Referenced by __construct(), and getRegex().


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