|
SPL-StandardPHPLibrary
|


Public Member Functions | |
| __call ($func, $params) | |
| __construct (Iterator $it, $regex, $mode=0, $flags=0, $preg_flags=0) | |
| accept () | |
| current () | |
| getFlags () | |
| getInnerIterator () | |
| getMode () | |
| getPregFlags () | |
| getRegex () | |
| 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 | |
| $current | |
| $flags | |
| $key | |
| $mode | |
| $preg_flags | |
| $regex | |
Regular expression filter for iterators.
This filter iterator assumes that the inner iterator
Definition at line 20 of file regexiterator.inc.
| RegexIterator::__construct | ( | Iterator $ | it, |
| $ | regex, | ||
| $ | mode = 0, |
||
| $ | flags = 0, |
||
| $ | preg_flags = 0 |
||
| ) |
Constructs a regular expression filter around an iterator whose elemnts or keys are strings.
| it | inner iterator |
| regex | the regular expression to match |
| mode | operation mode (one of self::MATCH, self::GET_MATCH, self::ALL_MATCHES, self::SPLIT) |
| flags | special flags (self::USE_KEY) |
| preg_flags | global PREG_* flags, see preg_match(), preg_match_all(), preg_split() |
Definition at line 52 of file regexiterator.inc.
References $flags, $mode, $preg_flags, and $regex.
{
parent::__construct($it);
$this->regex = $regex;
$this->flags = $flags;
$this->mode = $mode;
$this->preg_flags = $preg_flags;
}
| FilterIterator::__call | ( | $ | func, |
| $ | params | ||
| ) | [inherited] |
Aggregate the inner iterator.
| func | Name of method to invoke |
| params | Array of parameters to pass to method |
Reimplemented in SearchIterator.
Definition at line 121 of file filteriterator.inc.
{
return call_user_func_array(array($this->it, $func), $params);
}
| FilterIterator::__clone | ( | ) | [protected, inherited] |
hidden __clone
Reimplemented in KeyFilter.
Definition at line 104 of file filteriterator.inc.
{
// disallow clone
}
| RegexIterator::accept | ( | ) |
Match current or key against regular expression using mode, flags and preg_flags.
Reimplemented from FilterIterator.
Definition at line 68 of file regexiterator.inc.
References current(), key(), and USE_KEY.
{
$matches = array();
$this->key = parent::key();
$this->current = parent::current();
/* note that we use $this->current, rather than calling parent::current() */
$subject = ($this->flags & self::USE_KEY) ? $this->key : $this->current;
switch($this->mode)
{
case self::MATCH:
return preg_match($this->regex, $subject, $matches, $this->preg_flags);
case self::GET_MATCH:
$this->current = array();
return preg_match($this->regex, $subject, $this->current, $this->preg_flags) > 0;
case self::ALL_MATCHES:
$this->current = array();
return preg_match_all($this->regex, $subject, $this->current, $this->preg_flags) > 0;
case self::SPLIT:
$this->current = array();
preg_split($this->regex, $subject, $this->current, $this->preg_flags) > 1;
case self::REPLACE:
$this->current = array();
$result = preg_replace($this->regex, $this->replacement, $subject);
if ($this->flags & self::USE_KEY)
{
$this->key = $result;
}
else
{
$this->current = $result;
}
}
}

| RegexIterator::current | ( | ) |
Reimplemented from FilterIterator.
Definition at line 115 of file regexiterator.inc.
Referenced by accept().
{
return $this->current;
}
| FilterIterator::fetch | ( | ) | [protected, inherited] |
Fetch next element and store it.
Definition at line 61 of file filteriterator.inc.
References FilterIterator\accept().
Referenced by FilterIterator\next(), and FilterIterator\rewind().
{
while ($this->it->valid()) {
if ($this->accept()) {
return;
}
$this->it->next();
};
}

| RegexIterator::getFlags | ( | ) |
Definition at line 136 of file regexiterator.inc.
{
return $this->flags;
}
| FilterIterator::getInnerIterator | ( | ) | [inherited] |
Implements OuterIterator.
Definition at line 111 of file filteriterator.inc.
Referenced by SearchIterator\__call(), DirectoryFilterDots\accept(), KeyFilter\accept(), RecursiveRegexIterator\getChildren(), RecursiveFilterIterator\getChildren(), RecursiveRegexIterator\hasChildren(), RecursiveFilterIterator\hasChildren(), and DirectoryFilterDots\key().
{
return $this->it;
}
| RegexIterator::getMode | ( | ) |
Definition at line 122 of file regexiterator.inc.
{
return $this->mode;
}
| RegexIterator::getPregFlags | ( | ) |
Definition at line 150 of file regexiterator.inc.
{
return $this->preg_flags;
}
| RegexIterator::getRegex | ( | ) |
Definition at line 164 of file regexiterator.inc.
{
return $this->regex;
}
| RegexIterator::key | ( | ) |
Reimplemented from FilterIterator.
Definition at line 108 of file regexiterator.inc.
Referenced by accept().
{
return $this->key;
}
| FilterIterator::next | ( | ) | [inherited] |
Move to next element.
Implements Iterator.
Reimplemented in SearchIterator.
Definition at line 75 of file filteriterator.inc.
References FilterIterator\fetch().
{
$this->it->next();
$this->fetch();
}

| FilterIterator::rewind | ( | ) | [inherited] |
Rewind the inner iterator.
Implements Iterator.
Reimplemented in SearchIterator.
Definition at line 42 of file filteriterator.inc.
References FilterIterator\fetch().
{
$this->it->rewind();
$this->fetch();
}

| RegexIterator::setFlags | ( | $ | flags | ) |
| flags | new operaion flags |
Definition at line 143 of file regexiterator.inc.
References $flags.
{
$this->flags = $flags;
}
| RegexIterator::setMode | ( | $ | mode | ) |
| mode | new operaion mode |
Definition at line 129 of file regexiterator.inc.
References $mode.
{
$this->mode = $mode;
}
| RegexIterator::setPregFlags | ( | $ | preg_flags | ) |
| preg_flags | new PREG flags |
Definition at line 157 of file regexiterator.inc.
References $preg_flags.
{
$this->preg_flags = $preg_flags;
}
| FilterIterator::valid | ( | ) | [inherited] |
Implements Iterator.
Reimplemented in SearchIterator.
Definition at line 83 of file filteriterator.inc.
{
return $this->it->valid();
}
RegexIterator::$current [private] |
the value used for current()
Definition at line 38 of file regexiterator.inc.
RegexIterator::$flags [private] |
special flags (self::USE_KEY)
Definition at line 34 of file regexiterator.inc.
Referenced by RecursiveRegexIterator\__construct(), __construct(), and setFlags().
RegexIterator::$key [private] |
the value used for key()
Definition at line 37 of file regexiterator.inc.
RegexIterator::$mode [private] |
operation mode (one of self::MATCH, self::GET_MATCH, self::ALL_MATCHES, self::SPLIT)
Definition at line 32 of file regexiterator.inc.
Referenced by RecursiveRegexIterator\__construct(), __construct(), and setMode().
RegexIterator::$preg_flags [private] |
PREG_* flags, see preg_match(), preg_match_all(), preg_split()
Definition at line 35 of file regexiterator.inc.
Referenced by RecursiveRegexIterator\__construct(), __construct(), and setPregFlags().
RegexIterator::$regex [private] |
the regular expression to match against
Definition at line 31 of file regexiterator.inc.
Referenced by RecursiveRegexIterator\__construct(), and __construct().
| const RegexIterator::ALL_MATCHES = 2 |
Mode: Return all matches (if any)
Definition at line 27 of file regexiterator.inc.
| const RegexIterator::GET_MATCH = 1 |
Mode: Return the first matche (if any)
Definition at line 26 of file regexiterator.inc.
| const RegexIterator::MATCH = 0 |
Mode: Executed a plain match only.
Definition at line 25 of file regexiterator.inc.
| const RegexIterator::REPLACE = 4 |
Mode: Replace the input key or current.
Definition at line 29 of file regexiterator.inc.
| const RegexIterator::SPLIT = 3 |
Mode: Return the split values (if any)
Definition at line 28 of file regexiterator.inc.
| const RegexIterator::USE_KEY = 0x00000001 |
If present in $flags the key is used rather then the current value.
Definition at line 22 of file regexiterator.inc.
Referenced by accept().
1.7.5.1