RecursiveRegexIterator Class Reference

Recursive regular expression filter for iterators. More...

Inheritance diagram for RecursiveRegexIterator:

Inheritance graph
{RegexIterator\n|+ ALL_MATCHES\l+ GET_MATCH\l+ MATCH\l+ REPLACE\l+ SPLIT\l+ USE_KEY\l- $current\l- $flags\l- $key\l- $mode\l- $preg_flags\l- $regex\l|+ __construct()\l+ accept()\l+ current()\l+ getFlags()\l+ getMode()\l+ getPregFlags()\l+ key()\l+ setFlags()\l+ setMode()\l+ setPregFlags()\l}{RecursiveIterator\n||+ getChildren()\l+ hasChildren()\l}{Iterator\n||+ current()\l+ key()\l+ next()\l+ rewind()\l+ valid()\l}{Traversable\n||}
[legend]
Collaboration diagram for RecursiveRegexIterator:

Collaboration graph
{RegexIterator\n|+ ALL_MATCHES\l+ GET_MATCH\l+ MATCH\l+ REPLACE\l+ SPLIT\l+ USE_KEY\l- $current\l- $flags\l- $key\l- $mode\l- $preg_flags\l- $regex\l|+ __construct()\l+ accept()\l+ current()\l+ getFlags()\l+ getMode()\l+ getPregFlags()\l+ key()\l+ setFlags()\l+ setMode()\l+ setPregFlags()\l}{RecursiveIterator\n||+ getChildren()\l+ hasChildren()\l}{Iterator\n||+ current()\l+ key()\l+ next()\l+ rewind()\l+ valid()\l}{Traversable\n||}
[legend]
List of all members.

Public Member Functions

 __construct (RecursiveIterator $it, $regex, $mode=0, $flags=0, $preg_flags=0)
 accept ()
 current ()
 current ()
 getChildren ()
 getFlags ()
 getMode ()
 getPregFlags ()
 hasChildren ()
 key ()
 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

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:
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 34 of file recursiveregexiterator.inc.

References RegexIterator::$flags, $it, RegexIterator::$mode, RegexIterator::$preg_flags, and RegexIterator::$regex.

00034                                                                                                 {
00035         parent::__construct($it, $regex, $mode, $flags, $preg_flags);
00036     }


Member Function Documentation

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().

00069     {
00070         $matches       = array();
00071         $this->key     = parent::key();
00072         $this->current = parent::current();
00073         /* note that we use $this->current, rather than calling parent::current() */
00074         $subject = ($this->flags & self::USE_KEY) ? $this->key : $this->current;
00075         switch($this->mode)
00076         {
00077             case self::MATCH:
00078                 return preg_match($this->regex, $subject, $matches, $this->preg_flags);
00079 
00080             case self::GET_MATCH:
00081                 $this->current = array();
00082                 return preg_match($this->regex, $subject, $this->current, $this->preg_flags) > 0;
00083 
00084             case self::ALL_MATCHES:
00085                 $this->current = array();
00086                 return preg_match_all($this->regex, $subject, $this->current, $this->preg_flags) > 0;
00087 
00088             case self::SPLIT:
00089                 $this->current = array();
00090                 preg_split($this->regex, $subject, $this->current, $this->preg_flags) > 1;
00091 
00092             case self::REPLACE:
00093                 $this->current = array();
00094                 $result = preg_replace($this->regex, $this->replacement, $subject);
00095                 if ($this->flags & self::USE_KEY)
00096                 {
00097                     $this->key = $result;
00098                 }
00099                 else
00100                 {
00101                     $this->current = $result;
00102                 }
00103         }
00104     }

Here is the call graph for this function:

RegexIterator::currentRegexIterator::key

Iterator::current (  )  [inherited]

Return the current element.

Implemented in ArrayIterator, DirectoryIterator, RecursiveDirectoryIterator, SimpleXMLIterator, SubClasses, DbaReader, DirectoryTreeIterator, DualIterator, RecursiveTreeIterator, AppendIterator, CachingIterator, EmptyIterator, < FilterIterator >, IteratorIterator, LimitIterator, RecursiveIteratorIterator, SplFileObject, and SplObjectStorage.

RegexIterator::current (  )  [inherited]

Returns:
the current value after accept has been called

Definition at line 115 of file regexiterator.inc.

Referenced by RegexIterator::accept().

00116     {
00117         return $this->current;
00118     }

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.

00050     {
00051         if (empty($this->ref))
00052         {
00053             $this->ref = new ReflectionClass($this);
00054         }
00055         return $this->ref->newInstance($this->getInnerIterator()->getChildren());
00056     }

RegexIterator::getFlags (  )  [inherited]

Returns:
current operation flags

Definition at line 136 of file regexiterator.inc.

00137     {
00138         return $this->flags;
00139     }

RegexIterator::getMode (  )  [inherited]

Returns:
current operation mode

Definition at line 122 of file regexiterator.inc.

00123     {
00124         return $this->mode;
00125     }

RegexIterator::getPregFlags (  )  [inherited]

Returns:
current PREG flags

Definition at line 150 of file regexiterator.inc.

00151     {
00152         return $this->preg_flags;
00153     }

RecursiveRegexIterator::hasChildren (  ) 

Returns:
whether the current element has children

Implements RecursiveIterator.

Definition at line 40 of file recursiveregexiterator.inc.

00041     {
00042         return $this->getInnerIterator()->hasChildren();
00043     }

Iterator::key (  )  [inherited]

Return the key of the current element.

Implemented in ArrayIterator, DirectoryIterator, RecursiveDirectoryIterator, SimpleXMLIterator, DbaReader, DualIterator, RecursiveTreeIterator, AppendIterator, CachingIterator, EmptyIterator, < FilterIterator >, IteratorIterator, LimitIterator, RecursiveIteratorIterator, SplFileObject, and SplObjectStorage.

RegexIterator::key (  )  [inherited]

Returns:
the key after accept has been called

Definition at line 108 of file regexiterator.inc.

Referenced by RegexIterator::accept().

00109     {
00110         return $this->key;
00111     }

Iterator::next (  )  [inherited]

Move forward to next element.

Implemented in ArrayIterator, DirectoryIterator, SimpleXMLIterator, DbaReader, DualIterator, AppendIterator, CachingIterator, EmptyIterator, < FilterIterator >, InfiniteIterator, IteratorIterator, LimitIterator, RecursiveIteratorIterator, SplFileObject, and SplObjectStorage.

Iterator::rewind (  )  [inherited]

Rewind the Iterator to the first element.

Implemented in ArrayIterator, DirectoryIterator, SimpleXMLIterator, DbaReader, DualIterator, RecursiveCompareDualIterator, AppendIterator, CachingIterator, EmptyIterator, < FilterIterator >, IteratorIterator, LimitIterator, NoRewindIterator, RecursiveCachingIterator, RecursiveIteratorIterator, SplFileObject, and SplObjectStorage.

RegexIterator::setFlags ( flags  )  [inherited]

Parameters:
flags new operaion flags

Definition at line 143 of file regexiterator.inc.

References RegexIterator::$flags.

00144     {
00145         $this->flags = $flags;
00146     }

RegexIterator::setMode ( mode  )  [inherited]

Parameters:
mode new operaion mode

Definition at line 129 of file regexiterator.inc.

References RegexIterator::$mode.

00130     {
00131         $this->mode = $mode;
00132     }

RegexIterator::setPregFlags ( preg_flags  )  [inherited]

Parameters:
preg_flags new PREG flags

Definition at line 157 of file regexiterator.inc.

References RegexIterator::$preg_flags.

00158     {
00159         $this->preg_flags = $preg_flags;
00160     }

Iterator::valid (  )  [inherited]

Check if there is a current element after calls to rewind() or next().

Implemented in ArrayIterator, DirectoryIterator, SimpleXMLIterator, DbaReader, DualIterator, AppendIterator, CachingIterator, EmptyIterator, < FilterIterator >, IteratorIterator, LimitIterator, RecursiveIteratorIterator, SplFileObject, and SplObjectStorage.


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 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:
Generated on Thu Apr 26 01:07:14 2007 for SPL-StandardPHPLibrary by  doxygen 1.5.2