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

Public Member Functions

 __call ($func, $params)
 
 __construct (RecursiveIterator $it, $regex, $mode=0, $flags=0, $preg_flags=0)
 
 accept ()
 
 current ()
 
 getChildren ()
 
 getFlags ()
 
 getInnerIterator ()
 
 getMode ()
 
 getPregFlags ()
 
 getRegex ()
 
 hasChildren ()
 
 key ()
 
 next ()
 
 rewind ()
 
 setFlags ($flags)
 
 setMode ($mode)
 
 setPregFlags ($preg_flags)
 
 valid ()
 

Public Attributes

const ALL_MATCHES = 2
 
const GET_MATCH = 1
 
const MATCH = 0
 
const REPLACE = 4
 
const SPLIT = 3
 
const USE_KEY = 0x00000001
 

Protected Member Functions

 __clone ()
 
 fetch ()
 

Private Attributes

 $ref
 

Detailed Description

Recursive regular expression filter for iterators.

Author
Marcus Boerger
Version
1.0
Since
PHP 5.1

This filter iterator assumes that the inner iterator

Definition at line 20 of file recursiveregexiterator.inc.

Constructor & Destructor Documentation

RecursiveRegexIterator::__construct ( RecursiveIterator  $it,
  $regex,
  $mode = 0,
  $flags = 0,
  $preg_flags = 0 
)

Constructs a regular expression filter around an iterator whose elemnts or keys are strings.

Parameters
itinner iterator
regexthe regular expression to match
modeoperation mode (one of self::MATCH, self::GET_MATCH, self::ALL_MATCHES, self::SPLIT)
flagsspecial flags (self::USE_KEY)
preg_flagsglobal PREG_* flags, see preg_match(), preg_match_all(), preg_split()

Definition at line 34 of file recursiveregexiterator.inc.

References RegexIterator\$flags, RegexIterator\$mode, RegexIterator\$preg_flags, and RegexIterator\$regex.

34  {
35  parent::__construct($it, $regex, $mode, $flags, $preg_flags);
36  }
$flags
special flags (self::USE_KEY)
$regex
the regular expression to match against
$mode
operation mode (one of self::MATCH, self::GET_MATCH, self::ALL_MATCHES, self::SPLIT) ...
$preg_flags
PREG_* flags, see preg_match(), preg_match_all(), preg_split()

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  }
FilterIterator::__clone ( )
protectedinherited

hidden __clone

Definition at line 104 of file filteriterator.inc.

104  {
105  // disallow clone
106  }
RegexIterator::accept ( )
inherited

Match current or key against regular expression using mode, flags and preg_flags.

Returns
whether this is a match
Warning
never call this twice for the same state

Definition at line 68 of file regexiterator.inc.

References RegexIterator\current(), and RegexIterator\key().

69  {
70  $matches = array();
71  $this->key = parent::key();
72  $this->current = parent::current();
73  /* note that we use $this->current, rather than calling parent::current() */
74  $subject = ($this->flags & self::USE_KEY) ? $this->key : $this->current;
75  switch($this->mode)
76  {
77  case self::MATCH:
78  return preg_match($this->regex, $subject, $matches, $this->preg_flags);
79 
80  case self::GET_MATCH:
81  $this->current = array();
82  return preg_match($this->regex, $subject, $this->current, $this->preg_flags) > 0;
83 
84  case self::ALL_MATCHES:
85  $this->current = array();
86  return preg_match_all($this->regex, $subject, $this->current, $this->preg_flags) > 0;
87 
88  case self::SPLIT:
89  $this->current = array();
90  preg_split($this->regex, $subject, $this->current, $this->preg_flags) > 1;
91 
92  case self::REPLACE:
93  $this->current = array();
94  $result = preg_replace($this->regex, $this->replacement, $subject);
95  if ($this->flags & self::USE_KEY)
96  {
97  $this->key = $result;
98  }
99  else
100  {
101  $this->current = $result;
102  }
103  }
104  }

Here is the call graph for this function:

RegexIterator::current ( )
inherited
Returns
the current value after accept has been called

Implements Iterator.

Definition at line 115 of file regexiterator.inc.

References RegexIterator\$current.

Referenced by RegexIterator\accept().

116  {
117  return $this->current;
118  }
$current
the value used for current()
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:

RecursiveRegexIterator::getChildren ( )
Returns
an iterator for the current elements children
Note
the returned iterator will be of the same class as $this

Implements RecursiveIterator.

Definition at line 49 of file recursiveregexiterator.inc.

References FilterIterator\getInnerIterator().

50  {
51  if (empty($this->ref))
52  {
53  $this->ref = new ReflectionClass($this);
54  }
55  return $this->ref->newInstance($this->getInnerIterator()->getChildren());
56  }

Here is the call graph for this function:

RegexIterator::getFlags ( )
inherited
Returns
current operation flags

Definition at line 136 of file regexiterator.inc.

References RegexIterator\$flags.

137  {
138  return $this->flags;
139  }
$flags
special flags (self::USE_KEY)
FilterIterator::getInnerIterator ( )
inherited
RegexIterator::getMode ( )
inherited
Returns
current operation mode

Definition at line 122 of file regexiterator.inc.

References RegexIterator\$mode.

123  {
124  return $this->mode;
125  }
$mode
operation mode (one of self::MATCH, self::GET_MATCH, self::ALL_MATCHES, self::SPLIT) ...
RegexIterator::getPregFlags ( )
inherited
Returns
current PREG flags

Definition at line 150 of file regexiterator.inc.

References RegexIterator\$preg_flags.

151  {
152  return $this->preg_flags;
153  }
$preg_flags
PREG_* flags, see preg_match(), preg_match_all(), preg_split()
RegexIterator::getRegex ( )
inherited
Returns
current regular expression

Definition at line 164 of file regexiterator.inc.

References RegexIterator\$regex.

165  {
166  return $this->regex;
167  }
$regex
the regular expression to match against
RecursiveRegexIterator::hasChildren ( )
Returns
whether the current element has children

Implements RecursiveIterator.

Definition at line 40 of file recursiveregexiterator.inc.

References FilterIterator\getInnerIterator().

41  {
42  return $this->getInnerIterator()->hasChildren();
43  }

Here is the call graph for this function:

RegexIterator::key ( )
inherited
Returns
the key after accept has been called

Implements Iterator.

Definition at line 108 of file regexiterator.inc.

References RegexIterator\$key.

Referenced by RegexIterator\accept().

109  {
110  return $this->key;
111  }
$key
the value used for key()
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:

RegexIterator::setFlags (   $flags)
inherited
Parameters
flagsnew operaion flags

Definition at line 143 of file regexiterator.inc.

References RegexIterator\$flags.

144  {
145  $this->flags = $flags;
146  }
$flags
special flags (self::USE_KEY)
RegexIterator::setMode (   $mode)
inherited
Parameters
modenew operaion mode

Definition at line 129 of file regexiterator.inc.

References RegexIterator\$mode.

130  {
131  $this->mode = $mode;
132  }
$mode
operation mode (one of self::MATCH, self::GET_MATCH, self::ALL_MATCHES, self::SPLIT) ...
RegexIterator::setPregFlags (   $preg_flags)
inherited
Parameters
preg_flagsnew PREG flags

Definition at line 157 of file regexiterator.inc.

References RegexIterator\$preg_flags.

158  {
159  $this->preg_flags = $preg_flags;
160  }
$preg_flags
PREG_* flags, see preg_match(), preg_match_all(), preg_split()
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

RecursiveRegexIterator::$ref
private

Definition at line 58 of file recursiveregexiterator.inc.

const RegexIterator::ALL_MATCHES = 2
inherited

Mode: Return all matches (if any)

Definition at line 27 of file regexiterator.inc.

const RegexIterator::GET_MATCH = 1
inherited

Mode: Return the first matche (if any)

Definition at line 26 of file regexiterator.inc.

const RegexIterator::MATCH = 0
inherited

Mode: Executed a plain match only.

Definition at line 25 of file regexiterator.inc.

const RegexIterator::REPLACE = 4
inherited

Mode: Replace the input key or current.

Definition at line 29 of file regexiterator.inc.

const RegexIterator::SPLIT = 3
inherited

Mode: Return the split values (if any)

Definition at line 28 of file regexiterator.inc.

const RegexIterator::USE_KEY = 0x00000001
inherited

If present in $flags the key is used rather then the current value.

Definition at line 22 of file regexiterator.inc.


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