Back to index

php5  5.3.10
Files | Classes
Example classes

The classes and interfaces in this group are contained as PHP code in the examples subdirectory of ext/SPL. More...

Files

file  autoload.inc
 

function __autoload


file  cachingrecursiveiterator.inc
 

class CachingRecursiveIterator


file  callbackfilteriterator.inc
 

class CallbackFilterIterator


file  class_tree.php
 

Class Tree example.


file  dba_array.php
 

Program DBA array utility.


file  dba_dump.php
 

Program DBA dump utility.


file  dbaarray.inc
 

class DbaArray


file  dbareader.inc
 

class DbaReader


file  directoryfilterdots.inc
 

class DirectoryFilterDots


file  directorytree.inc
 

class DirectoryTree


file  directorytree.php
 

Program Directory tree example.


file  dualiterator.inc
 

class DualIterator


file  findfile.inc
 

class FindFile


file  findfile.php
 

Program Find a specific file by name.


file  findregex.php
 

Program Find a specific file by name.


file  ini_groups.php
 

Program List groups within an ini file.


file  inigroups.inc
 

class IniGroups


file  keyfilter.inc
 

class KeyFilter


file  nocvsdir.php
 

Program Dir without CVS subdirs.


file  recursivecomparedualiterator.inc
 

class DualIterator


file  recursivedualiterator.inc
 

class RecursiveDualIterator


file  regexfindfile.inc
 

class RegexFindFile


file  searchiterator.inc
 

abstract class SearchIterator


file  tree.php
 

Program Tree view example.


file  recursivearrayiterator.inc
 

class RecursiveArrayIterator


Classes

class  DirectoryGraphIterator
 A tree iterator that only shows directories. More...
class  DirectoryTreeIterator
 DirectoryIterator to generate ASCII graphic directory trees. More...
class  CachingRecursiveIterator
 Compatibility to PHP 5.0. More...
class  CallbackFilterIterator
 A non abstract FiletrIterator that uses a callback foreach element. More...
class  DbaArray
 This implements a DBA Array. More...
class  DbaReader
 This implements a DBA Iterator. More...
class  DirectoryFilterDots
 A filtered DirectoryIterator. More...
class  DirectoryTree
 A directory iterator that does not show '. More...
class  DualIterator
 Synchronous iteration over two iterators. More...
class  FindFile
 Base class to find files. More...
class  IniGroups
 Class to iterate all groups within an ini file. More...
class  KeyFilter
 Regular expression filter for string iterators. More...
class  RecursiveCompareDualIterator
 Recursive comparison iterator for a RecursiveDualIterator. More...
class  RecursiveDualIterator
 Synchronous iteration over two recursive iterators. More...
class  RegexFindFile
 Find files by regular expression. More...
class  SearchIterator
 Iterator to search for a specific element. More...

Detailed Description

The classes and interfaces in this group are contained as PHP code in the examples subdirectory of ext/SPL.

Sooner or later they will be moved to c-code.


Class Documentation

class DirectoryGraphIterator

A tree iterator that only shows directories.

Author:
Marcus Boerger
Version:
1.1

Definition at line 17 of file directorygraphiterator.inc.

Inheritance diagram for DirectoryGraphIterator:
Collaboration diagram for DirectoryGraphIterator:

Public Member Functions

 __construct ($path)
 Construct from a path.
 __construct ($path)
 Construct from a path.
 current ()
 current ()
 __call ($func, $params)
 Aggregates the inner iterator.
 __call ($func, $params)
 Aggregates the inner iterator.
 rewind ()
 Rewind to top iterator as set in constructor.
 valid ()
 key ()
 next ()
 Forward to next element.
 getSubIterator ($level=NULL)
 getInnerIterator ()
 getDepth ()
 callHasChildren ()
 callGetChildren ()
 beginChildren ()
 Called right after calling getChildren() and its rewind().
 endChildren ()
 Called after current child iterator is invalid and right before it gets destructed.
 nextElement ()
 Called when the next element is available.

Public Attributes

const LEAVES_ONLY = 0
 Mode: Only show leaves.
const SELF_FIRST = 1
 Mode: Show parents prior to their children.
const CHILD_FIRST = 2
 Mode: Show all children prior to their parent.
const CATCH_GET_CHILD = 0x00000002
 Flag: Catches exceptions during getChildren() calls and simply jumps to the next element.

Constructor & Destructor Documentation

Construct from a path.

Parameters:
$pathdirectory to iterate

Reimplemented from DirectoryTreeIterator.

Definition at line 19 of file directorygraphiterator.inc.

Here is the caller graph for this function:

Construct from a path.

Parameters:
$pathdirectory to iterate

Reimplemented from DirectoryTreeIterator.

Definition at line 19 of file directorygraphiterator.inc.

Here is the call graph for this function:


Member Function Documentation

DirectoryTreeIterator::__call ( func,
params 
) [inherited]

Aggregates the inner iterator.

Definition at line 48 of file directorytreeiterator.inc.

       {
              return call_user_func_array(array($this->getSubIterator(), $func), $params);
       }

Here is the call graph for this function:

DirectoryTreeIterator::__call ( func,
params 
) [inherited]

Aggregates the inner iterator.

Definition at line 48 of file directorytreeiterator.inc.

       {
              return call_user_func_array(array($this->getSubIterator(), $func), $params);
       }

Here is the call graph for this function:

Called right after calling getChildren() and its rewind().

Since:
PHP 5.1

Definition at line 201 of file recursiveiteratoriterator.inc.

       {
       }

Here is the caller graph for this function:

Returns:
current sub iterators current children
Since:
PHP 5.1

Definition at line 193 of file recursiveiteratoriterator.inc.

       {
              return $this->ait[$this->count]->getChildren();
       }

Here is the caller graph for this function:

Returns:
whether current sub iterators current element has children
Since:
PHP 5.1

Definition at line 185 of file recursiveiteratoriterator.inc.

       {
              return $this->ait[$this->count]->hasChildren();
       }

Here is the caller graph for this function:

Returns:
the current element prefixed with ASCII graphics

Reimplemented from RecursiveIteratorIterator.

Definition at line 36 of file directorytreeiterator.inc.

       {
              $tree = '';
              for ($l=0; $l < $this->getDepth(); $l++) {
                     $tree .= $this->getSubIterator($l)->hasNext() ? '| ' : '  ';
              }
              return $tree . ($this->getSubIterator($l)->hasNext() ? '|-' : '\-') 
                     . $this->getSubIterator($l)->__toString();
       }

Here is the call graph for this function:

Returns:
the current element prefixed with ASCII graphics

Reimplemented from RecursiveIteratorIterator.

Definition at line 36 of file directorytreeiterator.inc.

       {
              $tree = '';
              for ($l=0; $l < $this->getDepth(); $l++) {
                     $tree .= $this->getSubIterator($l)->hasNext() ? '| ' : '  ';
              }
              return $tree . ($this->getSubIterator($l)->hasNext() ? '|-' : '\-')
                                    . $this->getSubIterator($l)->__toString();
       }

Here is the call graph for this function:

Called after current child iterator is invalid and right before it gets destructed.

Since:
PHP 5.1

Reimplemented in RecursiveCompareDualIterator.

Definition at line 209 of file recursiveiteratoriterator.inc.

       {
       }

Here is the caller graph for this function:

Returns:
Current Depth (Number of parents)

Definition at line 177 of file recursiveiteratoriterator.inc.

       {
              return $this->level;
       }

Here is the caller graph for this function:

Returns:
The inner iterator

Implements OuterIterator.

Definition at line 170 of file recursiveiteratoriterator.inc.

       {
              return $this->it;
       }

Here is the caller graph for this function:

RecursiveIteratorIterator::getSubIterator ( level = NULL) [inherited]
Returns:
Sub Iterator at given level or if unspecified the current sub Iterator

Definition at line 159 of file recursiveiteratoriterator.inc.

       {
              if (is_null($level)) {
                     $level = $this->count;
              }
              return @$this->ait[$level];
       }

Here is the caller graph for this function:

Returns:
current key

Implements Iterator.

Reimplemented in RecursiveTreeIterator.

Definition at line 91 of file recursiveiteratoriterator.inc.

       {
              $it = $this->ait[$this->count];
              return $it->key();
       }

Forward to next element.

Implements Iterator.

Definition at line 107 of file recursiveiteratoriterator.inc.

       {
              while ($this->count) {
                     $it = $this->ait[$this->count];
                     if ($it->valid()) {
                            if (!$it->recursed && callHasChildren()) {
                                   $it->recursed = true;
                                   try
                                   {
                                          $sub = callGetChildren();
                                   }
                                   catch (Exception $e)
                                   {
                                          if (!($this->flags & self::CATCH_GET_CHILD))
                                          {
                                                 throw $e;
                                          }
                                          $it->next();
                                          continue;
                                   }
                                   $sub->recursed = false;
                                   $sub->rewind();
                                   if ($sub->valid()) {
                                          $this->ait[++$this->count] = $sub;
                                          if (!$sub instanceof RecursiveIterator) {
                                                 throw new Exception(get_class($sub).'::getChildren() must return an object that implements RecursiveIterator');
                                          }
                                          $this->beginChildren();
                                          return;
                                   }
                                   unset($sub);
                            }
                            $it->next();
                            $it->recursed = false;
                            if ($it->valid()) {
                                   return;
                            }
                            $it->recursed = false;
                     }
                     if ($this->count) {
                            unset($this->ait[$this->count--]);
                            $it = $this->ait[$this->count];
                            $this->endChildren();
                            callNextElement(false);
                     }
              }
              callNextElement(true);
       }

Here is the call graph for this function:

Called when the next element is available.

Definition at line 232 of file recursiveiteratoriterator.inc.

       {
       }

Here is the caller graph for this function:

Rewind to top iterator as set in constructor.

Implements Iterator.

Reimplemented in RecursiveCompareDualIterator.

Definition at line 62 of file recursiveiteratoriterator.inc.

       {
              while ($this->count) {
                     unset($this->ait[$this->count--]);
                     $this->endChildren();
              }
              $this->ait[0]->rewind();
              $this->ait[0]->recursed = false;
              callNextElement(true);
       }

Here is the call graph for this function:

Returns:
whether iterator is valid

Implements Iterator.

Definition at line 75 of file recursiveiteratoriterator.inc.

       {
              $count = $this->count;
              while ($count) {
                     $it = $this->ait[$count];
                     if ($it->valid()) {
                            return true;
                     }
                     $count--;
                     $this->endChildren();
              }
              return false;
       }

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

const RecursiveIteratorIterator::CATCH_GET_CHILD = 0x00000002 [inherited]

Flag: Catches exceptions during getChildren() calls and simply jumps to the next element.

Definition at line 33 of file recursiveiteratoriterator.inc.

Mode: Show all children prior to their parent.

Definition at line 29 of file recursiveiteratoriterator.inc.

Mode: Only show leaves.

Definition at line 25 of file recursiveiteratoriterator.inc.

Mode: Show parents prior to their children.

Definition at line 27 of file recursiveiteratoriterator.inc.

class DirectoryTreeIterator

DirectoryIterator to generate ASCII graphic directory trees.

Author:
Marcus Boerger
Version:
1.1

Definition at line 17 of file directorytreeiterator.inc.

Inheritance diagram for DirectoryTreeIterator:
Collaboration diagram for DirectoryTreeIterator:

Public Member Functions

 __construct ($path)
 Construct from a path.
 current ()
 __call ($func, $params)
 Aggregates the inner iterator.
 __construct ($path)
 Construct from a path.
 current ()
 __call ($func, $params)
 Aggregates the inner iterator.
 rewind ()
 Rewind to top iterator as set in constructor.
 valid ()
 key ()
 next ()
 Forward to next element.
 getSubIterator ($level=NULL)
 getInnerIterator ()
 getDepth ()
 callHasChildren ()
 callGetChildren ()
 beginChildren ()
 Called right after calling getChildren() and its rewind().
 endChildren ()
 Called after current child iterator is invalid and right before it gets destructed.
 nextElement ()
 Called when the next element is available.

Public Attributes

const LEAVES_ONLY = 0
 Mode: Only show leaves.
const SELF_FIRST = 1
 Mode: Show parents prior to their children.
const CHILD_FIRST = 2
 Mode: Show all children prior to their parent.
const CATCH_GET_CHILD = 0x00000002
 Flag: Catches exceptions during getChildren() calls and simply jumps to the next element.

Constructor & Destructor Documentation

Construct from a path.

Parameters:
$pathdirectory to iterate

Reimplemented in DirectoryGraphIterator, and DirectoryGraphIterator.

Definition at line 22 of file directorytreeiterator.inc.

Here is the caller graph for this function:

Construct from a path.

Parameters:
$pathdirectory to iterate

Reimplemented in DirectoryGraphIterator, and DirectoryGraphIterator.

Definition at line 22 of file directorytreeiterator.inc.

Here is the call graph for this function:


Member Function Documentation

DirectoryTreeIterator::__call ( func,
params 
)

Aggregates the inner iterator.

Definition at line 48 of file directorytreeiterator.inc.

       {
              return call_user_func_array(array($this->getSubIterator(), $func), $params);
       }

Here is the call graph for this function:

DirectoryTreeIterator::__call ( func,
params 
)

Aggregates the inner iterator.

Definition at line 48 of file directorytreeiterator.inc.

       {
              return call_user_func_array(array($this->getSubIterator(), $func), $params);
       }

Here is the call graph for this function:

Called right after calling getChildren() and its rewind().

Since:
PHP 5.1

Definition at line 201 of file recursiveiteratoriterator.inc.

       {
       }

Here is the caller graph for this function:

Returns:
current sub iterators current children
Since:
PHP 5.1

Definition at line 193 of file recursiveiteratoriterator.inc.

       {
              return $this->ait[$this->count]->getChildren();
       }

Here is the caller graph for this function:

Returns:
whether current sub iterators current element has children
Since:
PHP 5.1

Definition at line 185 of file recursiveiteratoriterator.inc.

       {
              return $this->ait[$this->count]->hasChildren();
       }

Here is the caller graph for this function:

Returns:
the current element prefixed with ASCII graphics

Reimplemented from RecursiveIteratorIterator.

Definition at line 36 of file directorytreeiterator.inc.

       {
              $tree = '';
              for ($l=0; $l < $this->getDepth(); $l++) {
                     $tree .= $this->getSubIterator($l)->hasNext() ? '| ' : '  ';
              }
              return $tree . ($this->getSubIterator($l)->hasNext() ? '|-' : '\-')
                                    . $this->getSubIterator($l)->__toString();
       }

Here is the call graph for this function:

Returns:
the current element prefixed with ASCII graphics

Reimplemented from RecursiveIteratorIterator.

Definition at line 36 of file directorytreeiterator.inc.

       {
              $tree = '';
              for ($l=0; $l < $this->getDepth(); $l++) {
                     $tree .= $this->getSubIterator($l)->hasNext() ? '| ' : '  ';
              }
              return $tree . ($this->getSubIterator($l)->hasNext() ? '|-' : '\-') 
                     . $this->getSubIterator($l)->__toString();
       }

Here is the call graph for this function:

Called after current child iterator is invalid and right before it gets destructed.

Since:
PHP 5.1

Reimplemented in RecursiveCompareDualIterator.

Definition at line 209 of file recursiveiteratoriterator.inc.

       {
       }

Here is the caller graph for this function:

Returns:
Current Depth (Number of parents)

Definition at line 177 of file recursiveiteratoriterator.inc.

       {
              return $this->level;
       }

Here is the caller graph for this function:

Returns:
The inner iterator

Implements OuterIterator.

Definition at line 170 of file recursiveiteratoriterator.inc.

       {
              return $this->it;
       }

Here is the caller graph for this function:

RecursiveIteratorIterator::getSubIterator ( level = NULL) [inherited]
Returns:
Sub Iterator at given level or if unspecified the current sub Iterator

Definition at line 159 of file recursiveiteratoriterator.inc.

       {
              if (is_null($level)) {
                     $level = $this->count;
              }
              return @$this->ait[$level];
       }

Here is the caller graph for this function:

Returns:
current key

Implements Iterator.

Reimplemented in RecursiveTreeIterator.

Definition at line 91 of file recursiveiteratoriterator.inc.

       {
              $it = $this->ait[$this->count];
              return $it->key();
       }

Forward to next element.

Implements Iterator.

Definition at line 107 of file recursiveiteratoriterator.inc.

       {
              while ($this->count) {
                     $it = $this->ait[$this->count];
                     if ($it->valid()) {
                            if (!$it->recursed && callHasChildren()) {
                                   $it->recursed = true;
                                   try
                                   {
                                          $sub = callGetChildren();
                                   }
                                   catch (Exception $e)
                                   {
                                          if (!($this->flags & self::CATCH_GET_CHILD))
                                          {
                                                 throw $e;
                                          }
                                          $it->next();
                                          continue;
                                   }
                                   $sub->recursed = false;
                                   $sub->rewind();
                                   if ($sub->valid()) {
                                          $this->ait[++$this->count] = $sub;
                                          if (!$sub instanceof RecursiveIterator) {
                                                 throw new Exception(get_class($sub).'::getChildren() must return an object that implements RecursiveIterator');
                                          }
                                          $this->beginChildren();
                                          return;
                                   }
                                   unset($sub);
                            }
                            $it->next();
                            $it->recursed = false;
                            if ($it->valid()) {
                                   return;
                            }
                            $it->recursed = false;
                     }
                     if ($this->count) {
                            unset($this->ait[$this->count--]);
                            $it = $this->ait[$this->count];
                            $this->endChildren();
                            callNextElement(false);
                     }
              }
              callNextElement(true);
       }

Here is the call graph for this function:

Called when the next element is available.

Definition at line 232 of file recursiveiteratoriterator.inc.

       {
       }

Here is the caller graph for this function:

Rewind to top iterator as set in constructor.

Implements Iterator.

Reimplemented in RecursiveCompareDualIterator.

Definition at line 62 of file recursiveiteratoriterator.inc.

       {
              while ($this->count) {
                     unset($this->ait[$this->count--]);
                     $this->endChildren();
              }
              $this->ait[0]->rewind();
              $this->ait[0]->recursed = false;
              callNextElement(true);
       }

Here is the call graph for this function:

Returns:
whether iterator is valid

Implements Iterator.

Definition at line 75 of file recursiveiteratoriterator.inc.

       {
              $count = $this->count;
              while ($count) {
                     $it = $this->ait[$count];
                     if ($it->valid()) {
                            return true;
                     }
                     $count--;
                     $this->endChildren();
              }
              return false;
       }

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

const RecursiveIteratorIterator::CATCH_GET_CHILD = 0x00000002 [inherited]

Flag: Catches exceptions during getChildren() calls and simply jumps to the next element.

Definition at line 33 of file recursiveiteratoriterator.inc.

Mode: Show all children prior to their parent.

Definition at line 29 of file recursiveiteratoriterator.inc.

Mode: Only show leaves.

Definition at line 25 of file recursiveiteratoriterator.inc.

Mode: Show parents prior to their children.

Definition at line 27 of file recursiveiteratoriterator.inc.

class CachingRecursiveIterator

Compatibility to PHP 5.0.

Author:
Marcus Boerger
Version:
1.2
Deprecated:

Class RecursiveCachingIterator was named CachingRecursiveIterator until PHP 5.0.6.

See also:
RecursiveCachingIterator

Definition at line 24 of file cachingrecursiveiterator.inc.

Inheritance diagram for CachingRecursiveIterator:
Collaboration diagram for CachingRecursiveIterator:

Public Member Functions

 rewind ()
 Rewind Iterator.
 hasChildren ()
 getChildren ()
 next ()
 Forward to the next element.
 valid ()
 hasNext ()
 current ()
 key ()
 __call ($func, $params)
 Aggregate the inner iterator.
 __toString ()
 getInnerIterator ()

Public Attributes

const CALL_TOSTRING = 0x00000001
const CATCH_GET_CHILD = 0x00000002
const TOSTRING_USE_KEY = 0x00000010
const TOSTRING_USE_CURRENT = 0x00000020

Member Function Documentation

CachingIterator::__call ( func,
params 
) [inherited]

Aggregate the inner iterator.

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

Definition at line 122 of file cachingiterator.inc.

       {
              return call_user_func_array(array($this->it, $func), $params);
       }
CachingIterator::__toString ( ) [inherited]
Returns:
the string represenatation that was generated for the current element
Exceptions:
exceptionwhen CALL_TOSTRING was not specified in constructor

Definition at line 131 of file cachingiterator.inc.

       {
              if ($this->flags & self::TOSTRING_USE_KEY)
              {
                     return $this->key;
              }
              else if ($this->flags & self::TOSTRING_USE_CURRENT)
              {
                     return $this->current;
              }
              if (!$this->flags & self::CALL_TOSTRING)
              {
                     throw new exception('CachingIterator does not fetch string value (see CachingIterator::__construct)');
              }
              return $this->strValue;
       }
CachingIterator::current ( ) [inherited]
Returns:
the current element

Implements Iterator.

Definition at line 105 of file cachingiterator.inc.

       {
              return $this->current;
       }

Here is the caller graph for this function:

Returns:
An Iterator for the children

Implements RecursiveIterator.

Definition at line 93 of file recursivecachingiterator.inc.

       {
              return $this->getChildren;
       }
Returns:
The inner iterator

Implements OuterIterator.

Definition at line 151 of file cachingiterator.inc.

       {
              return $this->it;
       }
Returns:
whether the current element has children
Note:
The check whether the Iterator for the children can be created was already executed. Hence when flag CATCH_GET_CHILD was given in constructor this fucntion returns false so that getChildren does not try to access those children.

Implements RecursiveIterator.

Definition at line 86 of file recursivecachingiterator.inc.

       {
              return $this->hasChildren;
       }
CachingIterator::hasNext ( ) [inherited]
Returns:
whether there is one more element

Definition at line 98 of file cachingiterator.inc.

       {
              return $this->it->valid();
       }
CachingIterator::key ( ) [inherited]
Returns:
the current key

Implements Iterator.

Definition at line 112 of file cachingiterator.inc.

       {
              return $this->key;
       }

Here is the caller graph for this function:

CachingIterator::next ( ) [inherited]

Forward to the next element.

Implements Iterator.

Definition at line 69 of file cachingiterator.inc.

       {
              if ($this->valid = $this->it->valid()) {
                     $this->current = $this->it->current();
                     $this->key = $this->it->key();
                     if ($this->flags & self::CALL_TOSTRING) {
                            if (is_object($this->current)) {
                                   $this->strValue = $this->current->__toString();
                            } else {
                                   $this->strValue = (string)$this->current;
                            }
                     }
              } else {
                     $this->current = NULL;
                     $this->key = NULL;
                     $this->strValue = NULL;
              }
              $this->it->next();
       }

Here is the call graph for this function:

Here is the caller graph for this function:

Rewind Iterator.

Reimplemented from CachingIterator.

CachingIterator::valid ( ) [inherited]
Returns:
whether the iterator is valid

Implements Iterator.

Definition at line 91 of file cachingiterator.inc.

       {
              return $this->valid;
       }

Here is the caller graph for this function:


Member Data Documentation

const CachingIterator::CALL_TOSTRING = 0x00000001 [inherited]

Definition at line 30 of file cachingiterator.inc.

const CachingIterator::CATCH_GET_CHILD = 0x00000002 [inherited]

Definition at line 31 of file cachingiterator.inc.

const CachingIterator::TOSTRING_USE_CURRENT = 0x00000020 [inherited]

Definition at line 33 of file cachingiterator.inc.

const CachingIterator::TOSTRING_USE_KEY = 0x00000010 [inherited]

Definition at line 32 of file cachingiterator.inc.

class CallbackFilterIterator

A non abstract FiletrIterator that uses a callback foreach element.

Author:
Marcus Boerger
Kevin McArthur
Version:
1.0

Definition at line 19 of file callbackfilteriterator.inc.

Inheritance diagram for CallbackFilterIterator:
Collaboration diagram for CallbackFilterIterator:

Public Member Functions

 __construct (Iterator $it, $callback, $mode=self::USE_VALUE, $flags=0)
 Construct a CallbackFilterIterator.
 accept ()
 Call the filter callback.
 key ()
 current ()
 getMode ()
 setMode ($mode)
 getFlags ()
 setFlags ($flags)
 rewind ()
 Rewind the inner iterator.
 next ()
 Move to next element.
 valid ()
 getInnerIterator ()
 __call ($func, $params)
 Aggregate the inner iterator.

Public Attributes

const USE_FALSE = 0
 mode: accept no elements, no callback
const USE_TRUE = 1
 mode: accept all elements, no callback
const USE_VALUE = 2
 mode: pass value to callback
const USE_KEY = 3
 mode: pass key to callback
const USE_BOTH = 4
 mode: pass value and key to callback
const REPLACE = 0x00000001
 flag: pass key/value by reference

Protected Member Functions

 fetch ()
 Fetch next element and store it.
 __clone ()
 hidden __clone

Private Attributes

 $callback
 callback to use
 $mode
 mode any of USE_VALUE, USE_KEY, USE_BOTH
 $flags
 flags (REPLACE)
 $key
 key value
 $current
 current value

Constructor & Destructor Documentation

CallbackFilterIterator::__construct ( Iterator it,
callback,
mode = self::USE_VALUE,
flags = 0 
)

Construct a CallbackFilterIterator.

Parameters:
itinner iterator (iterator to filter)
callbackcallback function
modeany of USE_VALUE, USE_KEY, USE_BOTH
flagsany of 0, REPLACE

Definition at line 42 of file callbackfilteriterator.inc.

       {
              parent::__construct($it);
              $this->callback = $callback;
              $this->mode     = $mode;
              $this->flags    = $flags;
       }

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

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 
       }

Call the filter callback.

Returns:
result of filter callback

Reimplemented from FilterIterator.

Definition at line 53 of file callbackfilteriterator.inc.

       {
              $this->key     = parent::key();
              $this->current = parent::current();

              switch($this->mode) {
              default:
              case self::USE_FALSE;
                     return false;
              case self::USE_TRUE:
                     return true;
              case self::USE_VALUE:
                     if($this->flags & self::REPLACE) {
                            return (bool) call_user_func($this->callback, &$this->current);
                     } else {
                            return (bool) call_user_func($this->callback, $this->current);
                     }
              case self::USE_KEY:
                     if($this->flags & self::REPLACE) {
                            return (bool) call_user_func($this->callback, &$this->key);
                     } else {
                            return (bool) call_user_func($this->callback, $this->key);
                     }
              case SELF::USE_BOTH:
                     if($this->flags & self::REPLACE) {
                            return (bool) call_user_func($this->callback, &$this->key, &$this->current);
                     } else {
                            return (bool) call_user_func($this->callback, $this->key, $this->current);
                     }
              }
       }

Here is the call graph for this function:

Returns:
current value

Reimplemented from FilterIterator.

Definition at line 92 of file callbackfilteriterator.inc.

       {
              return $this->current;
       }

Here is the caller graph for this function:

FilterIterator::fetch ( ) [protected, inherited]

Fetch next element and store it.

Returns:
void

Definition at line 61 of file filteriterator.inc.

                                  {
              while ($this->it->valid()) {
                     if ($this->accept()) {
                            return;
                     }
                     $this->it->next();
              };
       }

Here is the call graph for this function:

Here is the caller graph for this function:

Returns:
operation flags

Definition at line 110 of file callbackfilteriterator.inc.

       {
              return $this->flags;
       }
Returns:
The inner iterator

Implements OuterIterator.

Definition at line 111 of file filteriterator.inc.

       {
              return $this->it;
       }

Here is the caller graph for this function:

Returns:
operation mode

Definition at line 98 of file callbackfilteriterator.inc.

       {
              return $this->mode;
       }
Returns:
current key value

Reimplemented from FilterIterator.

Definition at line 86 of file callbackfilteriterator.inc.

       {
              return $this->key;
       }

Here is the caller graph for this function:

FilterIterator::next ( ) [inherited]

Move to next element.

Returns:
void

Implements Iterator.

Reimplemented in SearchIterator.

Definition at line 75 of file filteriterator.inc.

                       {
              $this->it->next();
              $this->fetch();
       }

Here is the call graph for this function:

FilterIterator::rewind ( ) [inherited]

Rewind the inner iterator.

Implements Iterator.

Reimplemented in SearchIterator.

Definition at line 42 of file filteriterator.inc.

                         {  
              $this->it->rewind();
              $this->fetch();
       }

Here is the call graph for this function:

Parameters:
$flagsset new flags,
See also:
flags

Definition at line 116 of file callbackfilteriterator.inc.

       {
              $this->flags = $flags;
       }
Parameters:
$modeset new mode,
See also:
mode

Definition at line 104 of file callbackfilteriterator.inc.

       {
              $this->mode = $mode;
       }
FilterIterator::valid ( ) [inherited]
Returns:
Whether more elements are available

Implements Iterator.

Reimplemented in SearchIterator.

Definition at line 83 of file filteriterator.inc.

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

Member Data Documentation

callback to use

Definition at line 29 of file callbackfilteriterator.inc.

current value

Definition at line 33 of file callbackfilteriterator.inc.

flags (REPLACE)

Definition at line 31 of file callbackfilteriterator.inc.

key value

Definition at line 32 of file callbackfilteriterator.inc.

mode any of USE_VALUE, USE_KEY, USE_BOTH

Definition at line 30 of file callbackfilteriterator.inc.

const CallbackFilterIterator::REPLACE = 0x00000001

flag: pass key/value by reference

Definition at line 27 of file callbackfilteriterator.inc.

mode: pass value and key to callback

Definition at line 25 of file callbackfilteriterator.inc.

mode: accept no elements, no callback

Definition at line 21 of file callbackfilteriterator.inc.

mode: pass key to callback

Definition at line 24 of file callbackfilteriterator.inc.

mode: accept all elements, no callback

Definition at line 22 of file callbackfilteriterator.inc.

mode: pass value to callback

Definition at line 23 of file callbackfilteriterator.inc.

class DbaArray

This implements a DBA Array.

Author:
Marcus Boerger
Version:
1.0

Definition at line 19 of file dbaarray.inc.

Inheritance diagram for DbaArray:
Collaboration diagram for DbaArray:

Public Member Functions

 __construct ($file, $handler)
 Open database $file with $handler in read only mode.
 __destruct ()
 Close database.
 offsetGet ($name)
 Read an entry.
 offsetSet ($name, $value)
 Set an entry.
 offsetExists ($name)
 offsetUnset ($name)
 Delete a key/value pair.
 rewind ()
 Rewind to first element.
 next ()
 Move to next element.
 current ()
 valid ()
 key ()

Protected Attributes

 $db = NULL

Constructor & Destructor Documentation

DbaArray::__construct ( file,
handler 
)

Open database $file with $handler in read only mode.

Parameters:
fileDatabase file to open.
handlerHandler to use for database access.

Reimplemented from DbaReader.

Definition at line 28 of file dbaarray.inc.

       {
              $this->db = dba_popen($file, "c", $handler);
              if (!$this->db) {
                     throw new exception("Databse could not be opened");
              }
       }

Close database.

Reimplemented from DbaReader.

Definition at line 39 of file dbaarray.inc.


Member Function Documentation

DbaReader::current ( ) [inherited]
Returns:
Current data.

Implements Iterator.

Definition at line 73 of file dbareader.inc.

                          {
              return $this->val;
       }
DbaReader::key ( ) [inherited]
Returns:
Current key.

Implements Iterator.

Definition at line 91 of file dbareader.inc.

                      {
              return $this->key;
       }

Here is the caller graph for this function:

DbaReader::next ( ) [inherited]

Move to next element.

Returns:
void

Implements Iterator.

Definition at line 56 of file dbareader.inc.

                       {
              $this->key = dba_nextkey($this->db);
              $this->fetch_data();
       }

Here is the call graph for this function:

Returns:
whether key $name exists.

Implements ArrayAccess.

Definition at line 82 of file dbaarray.inc.

       {
              return dba_exists($name, $this->db);
       }
DbaArray::offsetGet ( name)

Read an entry.

Parameters:
$namekey to read from
Returns:
value associated with $name

Implements ArrayAccess.

Definition at line 50 of file dbaarray.inc.

       {
              $data = dba_fetch($name, $this->db); 
              if($data) {
                     if (ini_get('magic_quotes_runtime')) {
                            $data = stripslashes($data);
                     }
                     //return unserialize($data);
                     return $data;
              }
              else 
              {
                     return NULL;
              }
       }
DbaArray::offsetSet ( name,
value 
)

Set an entry.

Parameters:
$namekey to write to
$valuevalue to write

Implements ArrayAccess.

Definition at line 72 of file dbaarray.inc.

       {
              //dba_replace($name, serialize($value), $this->db);
              dba_replace($name, $value, $this->db);
              return $value;
       }
DbaArray::offsetUnset ( name)

Delete a key/value pair.

Parameters:
$namekey to delete.

Implements ArrayAccess.

Definition at line 92 of file dbaarray.inc.

       {
              return dba_delete($name, $this->db);
       }
DbaReader::rewind ( ) [inherited]

Rewind to first element.

Implements Iterator.

Definition at line 46 of file dbareader.inc.

                         {
              $this->key = dba_firstkey($this->db);
              $this->fetch_data();
       }

Here is the call graph for this function:

DbaReader::valid ( ) [inherited]
Returns:
Whether more elements are available.

Implements Iterator.

Definition at line 80 of file dbareader.inc.

                        {
              if ($this->db && $this->key !== false) {
                     return true;
              } else {
                     return false;
              }
       }

Here is the call graph for this function:


Member Data Documentation

DbaReader::$db = NULL [protected, inherited]

Definition at line 20 of file dbareader.inc.

class DbaReader

This implements a DBA Iterator.

Author:
Marcus Boerger
Version:
1.0

Definition at line 17 of file dbareader.inc.

Inheritance diagram for DbaReader:
Collaboration diagram for DbaReader:

Public Member Functions

 __construct ($file, $handler)
 Open database $file with $handler in read only mode.
 __destruct ()
 Close database.
 rewind ()
 Rewind to first element.
 next ()
 Move to next element.
 current ()
 valid ()
 key ()

Protected Attributes

 $db = NULL

Private Member Functions

 fetch_data ()
 Fetches the current data if $key is valid.

Private Attributes

 $key = false
 $val = false

Constructor & Destructor Documentation

DbaReader::__construct ( file,
handler 
)

Open database $file with $handler in read only mode.

Parameters:
fileDatabase file to open.
handlerHandler to use for database access.

Reimplemented in DbaArray.

Definition at line 30 of file dbareader.inc.

                                             {
              if (!$this->db = dba_open($file, 'r', $handler)) {
                  throw new exception('Could not open file ' . $file);
              }
       }

Close database.

Reimplemented in DbaArray.

Definition at line 39 of file dbareader.inc.

                             {
              dba_close($this->db);
       }

Member Function Documentation

Returns:
Current data.

Implements Iterator.

Definition at line 73 of file dbareader.inc.

                          {
              return $this->val;
       }
DbaReader::fetch_data ( ) [private]

Fetches the current data if $key is valid.

Definition at line 64 of file dbareader.inc.

                                     {
              if ($this->key !== false) {
                     $this->val = dba_fetch($this->key, $this->db);
              }
       }

Here is the call graph for this function:

Here is the caller graph for this function:

Returns:
Current key.

Implements Iterator.

Definition at line 91 of file dbareader.inc.

                      {
              return $this->key;
       }

Here is the caller graph for this function:

Move to next element.

Returns:
void

Implements Iterator.

Definition at line 56 of file dbareader.inc.

                       {
              $this->key = dba_nextkey($this->db);
              $this->fetch_data();
       }

Here is the call graph for this function:

Rewind to first element.

Implements Iterator.

Definition at line 46 of file dbareader.inc.

                         {
              $this->key = dba_firstkey($this->db);
              $this->fetch_data();
       }

Here is the call graph for this function:

Returns:
Whether more elements are available.

Implements Iterator.

Definition at line 80 of file dbareader.inc.

                        {
              if ($this->db && $this->key !== false) {
                     return true;
              } else {
                     return false;
              }
       }

Here is the call graph for this function:


Member Data Documentation

DbaReader::$db = NULL [protected]

Definition at line 20 of file dbareader.inc.

DbaReader::$key = false [private]

Definition at line 21 of file dbareader.inc.

DbaReader::$val = false [private]

Definition at line 22 of file dbareader.inc.

class DirectoryFilterDots

A filtered DirectoryIterator.

Author:
Marcus Boerger
Version:
1.2

This Iterator takes a pathname from which it creates a RecursiveDirectoryIterator and makes it recursive. Further more it filters the entries '.' and '..'.

Definition at line 20 of file directoryfilterdots.inc.

Inheritance diagram for DirectoryFilterDots:
Collaboration diagram for DirectoryFilterDots:

Public Member Functions

 __construct ($path)
 Construct from a path.
 accept ()
 key ()
 hasChildren ()
 getChildren ()
 rewind ()
 Rewind the inner iterator.
 next ()
 Move to next element.
 valid ()
 current ()
 getInnerIterator ()
 __call ($func, $params)
 Aggregate the inner iterator.

Protected Member Functions

 fetch ()
 Fetch next element and store it.
 __clone ()
 hidden __clone

Constructor & Destructor Documentation

Construct from a path.

Parameters:
$pathdirectory to iterate

Definition at line 25 of file directoryfilterdots.inc.


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

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 
       }
Returns:
whether the current entry is neither '.' nor '..'

Reimplemented from FilterIterator.

Definition at line 32 of file directoryfilterdots.inc.

       {
              return !$this->getInnerIterator()->isDot();
       }

Here is the call graph for this function:

FilterIterator::current ( ) [inherited]
Returns:
The current value

Implements Iterator.

Reimplemented in RegexIterator, CallbackFilterIterator, and IniGroups.

Definition at line 97 of file filteriterator.inc.

                          {
              return $this->it->current();
       }

Here is the caller graph for this function:

FilterIterator::fetch ( ) [protected, inherited]

Fetch next element and store it.

Returns:
void

Definition at line 61 of file filteriterator.inc.

                                  {
              while ($this->it->valid()) {
                     if ($this->accept()) {
                            return;
                     }
                     $this->it->next();
              };
       }

Here is the call graph for this function:

Here is the caller graph for this function:

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

Implements RecursiveIterator.

Reimplemented in NoCvsDirectory.

Definition at line 50 of file recursivefilteriterator.inc.

       {
              if (empty($this->ref))
              {
                     $this->ref = new ReflectionClass($this);
              }
              return $this->ref->newInstance($this->getInnerIterator()->getChildren());
       }

Here is the call graph for this function:

Returns:
The inner iterator

Implements OuterIterator.

Definition at line 111 of file filteriterator.inc.

       {
              return $this->it;
       }

Here is the caller graph for this function:

Returns:
whether the current element has children

Implements RecursiveIterator.

Definition at line 41 of file recursivefilteriterator.inc.

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

Here is the call graph for this function:

Returns:
the current entries path name

Reimplemented from FilterIterator.

Definition at line 39 of file directoryfilterdots.inc.

       {
              return $this->getInnerIterator()->getPathname();
       }

Here is the call graph for this function:

FilterIterator::next ( ) [inherited]

Move to next element.

Returns:
void

Implements Iterator.

Reimplemented in SearchIterator.

Definition at line 75 of file filteriterator.inc.

                       {
              $this->it->next();
              $this->fetch();
       }

Here is the call graph for this function:

FilterIterator::rewind ( ) [inherited]

Rewind the inner iterator.

Implements Iterator.

Reimplemented in SearchIterator.

Definition at line 42 of file filteriterator.inc.

                         {  
              $this->it->rewind();
              $this->fetch();
       }

Here is the call graph for this function:

FilterIterator::valid ( ) [inherited]
Returns:
Whether more elements are available

Implements Iterator.

Reimplemented in SearchIterator.

Definition at line 83 of file filteriterator.inc.

                        {
              return $this->it->valid();
       }
class DirectoryTree

A directory iterator that does not show '.

' and '..'.

Author:
Marcus Boerger
Version:
1.0

Definition at line 17 of file directorytree.inc.

Inheritance diagram for DirectoryTree:
Collaboration diagram for DirectoryTree:

Public Member Functions

 __construct ($path)
 Construct from a path.
 rewind ()
 Rewind to top iterator as set in constructor.
 valid ()
 key ()
 current ()
 next ()
 Forward to next element.
 getSubIterator ($level=NULL)
 getInnerIterator ()
 getDepth ()
 callHasChildren ()
 callGetChildren ()
 beginChildren ()
 Called right after calling getChildren() and its rewind().
 endChildren ()
 Called after current child iterator is invalid and right before it gets destructed.
 nextElement ()
 Called when the next element is available.

Public Attributes

const LEAVES_ONLY = 0
 Mode: Only show leaves.
const SELF_FIRST = 1
 Mode: Show parents prior to their children.
const CHILD_FIRST = 2
 Mode: Show all children prior to their parent.
const CATCH_GET_CHILD = 0x00000002
 Flag: Catches exceptions during getChildren() calls and simply jumps to the next element.

Constructor & Destructor Documentation

Construct from a path.

Parameters:
$pathdirectory to iterate

Definition at line 22 of file directorytree.inc.


Member Function Documentation

Called right after calling getChildren() and its rewind().

Since:
PHP 5.1

Definition at line 201 of file recursiveiteratoriterator.inc.

       {
       }

Here is the caller graph for this function:

Returns:
current sub iterators current children
Since:
PHP 5.1

Definition at line 193 of file recursiveiteratoriterator.inc.

       {
              return $this->ait[$this->count]->getChildren();
       }

Here is the caller graph for this function:

Returns:
whether current sub iterators current element has children
Since:
PHP 5.1

Definition at line 185 of file recursiveiteratoriterator.inc.

       {
              return $this->ait[$this->count]->hasChildren();
       }

Here is the caller graph for this function:

Returns:
current element

Implements Iterator.

Reimplemented in RecursiveTreeIterator, DirectoryTreeIterator, and DirectoryTreeIterator.

Definition at line 99 of file recursiveiteratoriterator.inc.

       {
              $it = $this->ait[$this->count];
              return $it->current();
       }

Called after current child iterator is invalid and right before it gets destructed.

Since:
PHP 5.1

Reimplemented in RecursiveCompareDualIterator.

Definition at line 209 of file recursiveiteratoriterator.inc.

       {
       }

Here is the caller graph for this function:

Returns:
Current Depth (Number of parents)

Definition at line 177 of file recursiveiteratoriterator.inc.

       {
              return $this->level;
       }

Here is the caller graph for this function:

Returns:
The inner iterator

Implements OuterIterator.

Definition at line 170 of file recursiveiteratoriterator.inc.

       {
              return $this->it;
       }

Here is the caller graph for this function:

RecursiveIteratorIterator::getSubIterator ( level = NULL) [inherited]
Returns:
Sub Iterator at given level or if unspecified the current sub Iterator

Definition at line 159 of file recursiveiteratoriterator.inc.

       {
              if (is_null($level)) {
                     $level = $this->count;
              }
              return @$this->ait[$level];
       }

Here is the caller graph for this function:

Returns:
current key

Implements Iterator.

Reimplemented in RecursiveTreeIterator.

Definition at line 91 of file recursiveiteratoriterator.inc.

       {
              $it = $this->ait[$this->count];
              return $it->key();
       }

Forward to next element.

Implements Iterator.

Definition at line 107 of file recursiveiteratoriterator.inc.

       {
              while ($this->count) {
                     $it = $this->ait[$this->count];
                     if ($it->valid()) {
                            if (!$it->recursed && callHasChildren()) {
                                   $it->recursed = true;
                                   try
                                   {
                                          $sub = callGetChildren();
                                   }
                                   catch (Exception $e)
                                   {
                                          if (!($this->flags & self::CATCH_GET_CHILD))
                                          {
                                                 throw $e;
                                          }
                                          $it->next();
                                          continue;
                                   }
                                   $sub->recursed = false;
                                   $sub->rewind();
                                   if ($sub->valid()) {
                                          $this->ait[++$this->count] = $sub;
                                          if (!$sub instanceof RecursiveIterator) {
                                                 throw new Exception(get_class($sub).'::getChildren() must return an object that implements RecursiveIterator');
                                          }
                                          $this->beginChildren();
                                          return;
                                   }
                                   unset($sub);
                            }
                            $it->next();
                            $it->recursed = false;
                            if ($it->valid()) {
                                   return;
                            }
                            $it->recursed = false;
                     }
                     if ($this->count) {
                            unset($this->ait[$this->count--]);
                            $it = $this->ait[$this->count];
                            $this->endChildren();
                            callNextElement(false);
                     }
              }
              callNextElement(true);
       }

Here is the call graph for this function:

Called when the next element is available.

Definition at line 232 of file recursiveiteratoriterator.inc.

       {
       }

Here is the caller graph for this function:

Rewind to top iterator as set in constructor.

Implements Iterator.

Reimplemented in RecursiveCompareDualIterator.

Definition at line 62 of file recursiveiteratoriterator.inc.

       {
              while ($this->count) {
                     unset($this->ait[$this->count--]);
                     $this->endChildren();
              }
              $this->ait[0]->rewind();
              $this->ait[0]->recursed = false;
              callNextElement(true);
       }

Here is the call graph for this function:

Returns:
whether iterator is valid

Implements Iterator.

Definition at line 75 of file recursiveiteratoriterator.inc.

       {
              $count = $this->count;
              while ($count) {
                     $it = $this->ait[$count];
                     if ($it->valid()) {
                            return true;
                     }
                     $count--;
                     $this->endChildren();
              }
              return false;
       }

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

const RecursiveIteratorIterator::CATCH_GET_CHILD = 0x00000002 [inherited]

Flag: Catches exceptions during getChildren() calls and simply jumps to the next element.

Definition at line 33 of file recursiveiteratoriterator.inc.

Mode: Show all children prior to their parent.

Definition at line 29 of file recursiveiteratoriterator.inc.

Mode: Only show leaves.

Definition at line 25 of file recursiveiteratoriterator.inc.

Mode: Show parents prior to their children.

Definition at line 27 of file recursiveiteratoriterator.inc.

class DualIterator

Synchronous iteration over two iterators.

Author:
Marcus Boerger
Version:
1.3

Definition at line 17 of file dualiterator.inc.

Inheritance diagram for DualIterator:
Collaboration diagram for DualIterator:

Public Member Functions

 __construct (Iterator $lhs, Iterator $rhs, $flags=0x13)
 construct iterator from two iterators
 getLHS ()
 getRHS ()
 setFlags ($flags)
 getFlags ()
 rewind ()
 rewind both inner iterators
 valid ()
 current ()
 key ()
 next ()
 move both inner iterators forward
 areIdentical ()
 areEqual ()

Static Public Member Functions

static compareIterators (Iterator $lhs, Iterator $rhs, $identical=false)
 Compare two iterators.

Public Attributes

const CURRENT_LHS = 0x01
const CURRENT_RHS = 0x02
const CURRENT_ARRAY = 0x03
const CURRENT_0 = 0x00
const KEY_LHS = 0x10
const KEY_RHS = 0x20
const KEY_0 = 0x00
const DEFAULT_FLAGS = 0x13

Private Attributes

 $lhs
 $rhs
 $flags

Constructor & Destructor Documentation

DualIterator::__construct ( Iterator lhs,
Iterator rhs,
flags = 0x13 
)

construct iterator from two iterators

Parameters:
lhsLeft Hand Side Iterator
rhsRight Hand Side Iterator
flagsiteration flags

Definition at line 40 of file dualiterator.inc.

       {
              $this->lhs   = $lhs;
              $this->rhs   = $rhs;
              $this->flags = $flags;
       }

Member Function Documentation

Returns:
whether both inner iterators are valid and have equal current and key values or both are non valid.

Reimplemented in RecursiveDualIterator.

Definition at line 147 of file dualiterator.inc.

       {
              return $this->valid()
                   ? $this->lhs->current() ==  $this->rhs->current()
                     && $this->lhs->key()     ==  $this->rhs->key()
                      : $this->lhs->valid()   ==  $this->rhs->valid();
       }

Here is the call graph for this function:

Returns:
whether both inner iterators are valid and have identical current and key values or both are non valid.

Reimplemented in RecursiveDualIterator.

Definition at line 136 of file dualiterator.inc.

       {
              return $this->valid()
                   ? $this->lhs->current() === $this->rhs->current()
                     && $this->lhs->key()     === $this->rhs->key()
                      : $this->lhs->valid()   ==  $this->rhs->valid();
       }

Here is the call graph for this function:

static DualIterator::compareIterators ( Iterator lhs,
Iterator rhs,
identical = false 
) [static]

Compare two iterators.

Parameters:
lhsLeft Hand Side Iterator
rhsRight Hand Side Iterator
identicalwhether to use areEqual() or areIdentical()
Returns:
whether both iterators are equal/identical
Note:
If one implements RecursiveIterator the other must do as well. And if both do then a recursive comparison is being used.

Definition at line 165 of file dualiterator.inc.

       {
              if ($lhs instanceof RecursiveIterator)
              {
                     if ($rhs instanceof RecursiveIterator)
                     {
                            $it = new RecursiveDualIterator($lhs, $rhs, 
                                                        self::CURRENT_0 | self::KEY_0);
                            $it = new RecursiveCompareDualIterator($it);
                     }
                     else
                     {
                            return false;
                     }
              }
              else
              {
                     $it = new DualIterator($lhs, $rhs, self::CURRENT_0 | self::KEY_0);
              }

              if ($identical)
              {
                     foreach($it as $n)
                     {
                            if (!$it->areIdentical())
                            {
                                   return false;
                            }
                     }
              }
              else
              {
                     foreach($it as $n)
                     {
                            if (!$it->areEqual())
                            {
                                   return false;
                            }
                     }
              }
              return $identical ? $it->areIdentical() : $it->areEqual();
       }
Returns:
current value depending on CURRENT_* flags

Implements Iterator.

Definition at line 93 of file dualiterator.inc.

       {
              switch($this->flags & 0x0F)
              {
              default:
              case self::CURRENT_ARRAY:
                     return array($this->lhs->current(), $this->rhs->current());
              case self::CURRENT_LHS:
                     return $this->lhs->current();
              case self::CURRENT_RHS:
                     return $this->rhs->current();
              case self::CURRENT_0:
                     return NULL;
              }
       }
Returns:
current flags

Definition at line 71 of file dualiterator.inc.

       {
              return $this->flags;
       }

Here is the caller graph for this function:

Returns:
Left Hand Side Iterator

Definition at line 50 of file dualiterator.inc.

       {
              return $this->lhs;
       }

Here is the caller graph for this function:

Returns:
Right Hand Side Iterator

Definition at line 57 of file dualiterator.inc.

       {
              return $this->rhs;
       }

Here is the caller graph for this function:

Returns:
key value depending on KEY_* flags

Implements Iterator.

Definition at line 111 of file dualiterator.inc.

       {
              switch($this->flags & 0xF0)
              {
              default:
              case self::KEY_LHS:
                     return $this->lhs->key();
              case self::KEY_RHS:
                     return $this->rhs->key();
              case self::KEY_0:
                     return NULL;
              }
       }

move both inner iterators forward

Implements Iterator.

Definition at line 127 of file dualiterator.inc.

       {
              $this->lhs->next();
              $this->rhs->next();
       }

rewind both inner iterators

Implements Iterator.

Definition at line 78 of file dualiterator.inc.

       {
              $this->lhs->rewind();
              $this->rhs->rewind();       
       }
DualIterator::setFlags ( flags)
Parameters:
flagsnew flags

Definition at line 64 of file dualiterator.inc.

       {
              $this->flags = $flags;
       }
Returns:
whether both inner iterators are valid

Implements Iterator.

Definition at line 86 of file dualiterator.inc.

       {
              return $this->lhs->valid() && $this->rhs->valid();      
       }

Here is the caller graph for this function:


Member Data Documentation

Definition at line 32 of file dualiterator.inc.

DualIterator::$lhs [private]

Definition at line 30 of file dualiterator.inc.

DualIterator::$rhs [private]

Definition at line 31 of file dualiterator.inc.

Definition at line 22 of file dualiterator.inc.

Definition at line 21 of file dualiterator.inc.

Definition at line 19 of file dualiterator.inc.

Definition at line 20 of file dualiterator.inc.

Definition at line 28 of file dualiterator.inc.

const DualIterator::KEY_0 = 0x00

Definition at line 26 of file dualiterator.inc.

const DualIterator::KEY_LHS = 0x10

Definition at line 24 of file dualiterator.inc.

const DualIterator::KEY_RHS = 0x20

Definition at line 25 of file dualiterator.inc.

class FindFile

Base class to find files.

Author:
Marcus Boerger
Version:
1.1

Definition at line 21 of file findfile.inc.

Inheritance diagram for FindFile:
Collaboration diagram for FindFile:

Public Member Functions

 __construct ($path, $file)
 Construct from path and filename.
 accept ()
 getSearch ()
 rewind ()
 Rewind the inner iterator.
 next ()
 Move to next element.
 valid ()
 key ()
 current ()
 getInnerIterator ()
 __call ($func, $params)
 Aggregate the inner iterator.

Protected Member Functions

 fetch ()
 Fetch next element and store it.
 __clone ()
 hidden __clone

Private Attributes

 $file

Constructor & Destructor Documentation

FindFile::__construct ( path,
file 
)

Construct from path and filename.

Parameters:
$paththe directory to search in If path contains ';' then this parameter is split and every part of it is used as separate directory.
$filethe name of the files to search fro

Reimplemented in RegexFindFile.

Definition at line 33 of file findfile.inc.

       {
              $this->file = $file;
              $list = split(PATH_SEPARATOR, $path);
              if (count($list) <= 1) {
                     parent::__construct(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path)));
              } else {
                     $it = new AppendIterator();
                     foreach($list as $path) {
                            $it->append(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path)));
                     }
                     parent::__construct($it);
              }
       }

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

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 
       }
Returns:
whether the current file matches the given filename

Reimplemented from FilterIterator.

Reimplemented in RegexFindFile.

Definition at line 50 of file findfile.inc.

       {
              return !strcmp($this->current(), $this->file);
       }

Here is the call graph for this function:

FilterIterator::current ( ) [inherited]
Returns:
The current value

Implements Iterator.

Reimplemented in RegexIterator, CallbackFilterIterator, and IniGroups.

Definition at line 97 of file filteriterator.inc.

                          {
              return $this->it->current();
       }

Here is the caller graph for this function:

FilterIterator::fetch ( ) [protected, inherited]

Fetch next element and store it.

Returns:
void

Definition at line 61 of file filteriterator.inc.

                                  {
              while ($this->it->valid()) {
                     if ($this->accept()) {
                            return;
                     }
                     $this->it->next();
              };
       }

Here is the call graph for this function:

Here is the caller graph for this function:

Returns:
The inner iterator

Implements OuterIterator.

Definition at line 111 of file filteriterator.inc.

       {
              return $this->it;
       }

Here is the caller graph for this function:

Returns:
the filename to search for.
Note:
This may be overloaded and contain a regular expression for an extended class that uses regular expressions to search.

Definition at line 59 of file findfile.inc.

       {
              return $this->file;
       }

Here is the caller graph for this function:

FilterIterator::key ( ) [inherited]
Returns:
The current key

Implements Iterator.

Reimplemented in RegexIterator, CallbackFilterIterator, IniGroups, and DirectoryFilterDots.

Definition at line 90 of file filteriterator.inc.

                      {
              return $this->it->key();
       }

Here is the caller graph for this function:

FilterIterator::next ( ) [inherited]

Move to next element.

Returns:
void

Implements Iterator.

Reimplemented in SearchIterator.

Definition at line 75 of file filteriterator.inc.

                       {
              $this->it->next();
              $this->fetch();
       }

Here is the call graph for this function:

FilterIterator::rewind ( ) [inherited]

Rewind the inner iterator.

Implements Iterator.

Reimplemented in SearchIterator.

Definition at line 42 of file filteriterator.inc.

                         {  
              $this->it->rewind();
              $this->fetch();
       }

Here is the call graph for this function:

FilterIterator::valid ( ) [inherited]
Returns:
Whether more elements are available

Implements Iterator.

Reimplemented in SearchIterator.

Definition at line 83 of file filteriterator.inc.

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

Member Data Documentation

FindFile::$file [private]

filename to find

Definition at line 24 of file findfile.inc.

class IniGroups

Class to iterate all groups within an ini file.

Author:
Marcus Boerger
Version:
1.1

Using this class you can iterator over all groups of a ini file.

This class uses a 'is-a' relation to KeyFilter in contrast to a 'has-a' relation. Doing so both current() and key() methods must be overwritten. If it would use a 'has-a' relation there would be much more to type... but for puritists that would allow correctness in so far as then no key() would be needed.

Definition at line 28 of file inigroups.inc.

Inheritance diagram for IniGroups:
Collaboration diagram for IniGroups:

Public Member Functions

 __construct ($file)
 Construct an ini file group iterator from a filename.
 current ()
 key ()
 accept ()
 getRegex ()
 rewind ()
 Rewind the inner iterator.
 next ()
 Move to next element.
 valid ()
 getInnerIterator ()
 __call ($func, $params)
 Aggregate the inner iterator.

Protected Member Functions

 __clone ()
 hidden __clone
 fetch ()
 Fetch next element and store it.

Constructor & Destructor Documentation

Construct an ini file group iterator from a filename.

Parameters:
fileIni file to open.

Definition at line 35 of file inigroups.inc.

                                   {
              parent::__construct(new DbaReader($file, 'inifile'), '^\[.*\]$');
       }

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

Reimplemented in SearchIterator.

Definition at line 121 of file filteriterator.inc.

       {
              return call_user_func_array(array($this->it, $func), $params);
       }
KeyFilter::__clone ( ) [protected, inherited]

hidden __clone

Reimplemented from FilterIterator.

Definition at line 58 of file keyfilter.inc.

       {
              // disallow clone 
       }
KeyFilter::accept ( ) [inherited]
Returns:
whether the current key mathes the regular expression

Reimplemented from FilterIterator.

Definition at line 43 of file keyfilter.inc.

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

Here is the call graph for this function:

Returns:
The current group.

Reimplemented from FilterIterator.

Definition at line 42 of file inigroups.inc.

                          {
              return substr(parent::key(),1,-1);
       }
FilterIterator::fetch ( ) [protected, inherited]

Fetch next element and store it.

Returns:
void

Definition at line 61 of file filteriterator.inc.

                                  {
              while ($this->it->valid()) {
                     if ($this->accept()) {
                            return;
                     }
                     $this->it->next();
              };
       }

Here is the call graph for this function:

Here is the caller graph for this function:

Returns:
The inner iterator

Implements OuterIterator.

Definition at line 111 of file filteriterator.inc.

       {
              return $this->it;
       }

Here is the caller graph for this function:

KeyFilter::getRegex ( ) [inherited]
Returns:
regular expression used as filter

Definition at line 50 of file keyfilter.inc.

       {
              return $this->regex;
       }
Returns:
The current group.

Reimplemented from FilterIterator.

Definition at line 49 of file inigroups.inc.

                      {
              return substr(parent::key(),1,-1);
       }
FilterIterator::next ( ) [inherited]

Move to next element.

Returns:
void

Implements Iterator.

Reimplemented in SearchIterator.

Definition at line 75 of file filteriterator.inc.

                       {
              $this->it->next();
              $this->fetch();
       }

Here is the call graph for this function:

FilterIterator::rewind ( ) [inherited]

Rewind the inner iterator.

Implements Iterator.

Reimplemented in SearchIterator.

Definition at line 42 of file filteriterator.inc.

                         {  
              $this->it->rewind();
              $this->fetch();
       }

Here is the call graph for this function:

FilterIterator::valid ( ) [inherited]
Returns:
Whether more elements are available

Implements Iterator.

Reimplemented in SearchIterator.

Definition at line 83 of file filteriterator.inc.

                        {
              return $this->it->valid();
       }
class KeyFilter

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.

Inheritance diagram for KeyFilter:
Collaboration diagram for KeyFilter:

Public Member Functions

 __construct (Iterator $it, $regex)
 Constructs a filter around an iterator whose elemnts are strings.
 accept ()
 getRegex ()
 rewind ()
 Rewind the inner iterator.
 next ()
 Move to next element.
 valid ()
 key ()
 current ()
 getInnerIterator ()
 __call ($func, $params)
 Aggregate the inner iterator.

Protected Member Functions

 __clone ()
 hidden __clone
 fetch ()
 Fetch next element and store it.

Private Attributes

 $regex

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.

       {
              parent::__construct($it);
              $this->regex = $regex;
       }

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

Reimplemented in SearchIterator.

Definition at line 121 of file filteriterator.inc.

       {
              return call_user_func_array(array($this->it, $func), $params);
       }
KeyFilter::__clone ( ) [protected]

hidden __clone

Reimplemented from FilterIterator.

Definition at line 58 of file keyfilter.inc.

       {
              // disallow clone 
       }
Returns:
whether the current key mathes the regular expression

Reimplemented from FilterIterator.

Definition at line 43 of file keyfilter.inc.

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

Here is the call graph for this function:

FilterIterator::current ( ) [inherited]
Returns:
The current value

Implements Iterator.

Reimplemented in RegexIterator, CallbackFilterIterator, and IniGroups.

Definition at line 97 of file filteriterator.inc.

                          {
              return $this->it->current();
       }

Here is the caller graph for this function:

FilterIterator::fetch ( ) [protected, inherited]

Fetch next element and store it.

Returns:
void

Definition at line 61 of file filteriterator.inc.

                                  {
              while ($this->it->valid()) {
                     if ($this->accept()) {
                            return;
                     }
                     $this->it->next();
              };
       }

Here is the call graph for this function:

Here is the caller graph for this function:

Returns:
The inner iterator

Implements OuterIterator.

Definition at line 111 of file filteriterator.inc.

       {
              return $this->it;
       }

Here is the caller graph for this function:

Returns:
regular expression used as filter

Definition at line 50 of file keyfilter.inc.

       {
              return $this->regex;
       }
FilterIterator::key ( ) [inherited]
Returns:
The current key

Implements Iterator.

Reimplemented in RegexIterator, CallbackFilterIterator, IniGroups, and DirectoryFilterDots.

Definition at line 90 of file filteriterator.inc.

                      {
              return $this->it->key();
       }

Here is the caller graph for this function:

FilterIterator::next ( ) [inherited]

Move to next element.

Returns:
void

Implements Iterator.

Reimplemented in SearchIterator.

Definition at line 75 of file filteriterator.inc.

                       {
              $this->it->next();
              $this->fetch();
       }

Here is the call graph for this function:

FilterIterator::rewind ( ) [inherited]

Rewind the inner iterator.

Implements Iterator.

Reimplemented in SearchIterator.

Definition at line 42 of file filteriterator.inc.

                         {  
              $this->it->rewind();
              $this->fetch();
       }

Here is the call graph for this function:

FilterIterator::valid ( ) [inherited]
Returns:
Whether more elements are available

Implements Iterator.

Reimplemented in SearchIterator.

Definition at line 83 of file filteriterator.inc.

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

Member Data Documentation

KeyFilter::$regex [private]

regular exoression used as filter

Definition at line 25 of file keyfilter.inc.

class RecursiveCompareDualIterator

Recursive comparison iterator for a RecursiveDualIterator.

Author:
Marcus Boerger
Version:
1.0

Definition at line 17 of file recursivecomparedualiterator.inc.

Inheritance diagram for RecursiveCompareDualIterator:
Collaboration diagram for RecursiveCompareDualIterator:

Public Member Functions

 __construct (RecursiveDualIterator $it, $mode=self::LEAVES_ONLY, $flags=0)
 Construct from RecursiveDualIterator.
 rewind ()
 Rewind iteration andcomparison process.
 endChildren ()
 Calculate $equal.
 areIdentical ()
 areEqual ()
 valid ()
 key ()
 current ()
 next ()
 Forward to next element.
 getSubIterator ($level=NULL)
 getInnerIterator ()
 getDepth ()
 callHasChildren ()
 callGetChildren ()
 beginChildren ()
 Called right after calling getChildren() and its rewind().
 nextElement ()
 Called when the next element is available.

Public Attributes

const LEAVES_ONLY = 0
 Mode: Only show leaves.
const SELF_FIRST = 1
 Mode: Show parents prior to their children.
const CHILD_FIRST = 2
 Mode: Show all children prior to their parent.
const CATCH_GET_CHILD = 0x00000002
 Flag: Catches exceptions during getChildren() calls and simply jumps to the next element.

Protected Attributes

 $equal = false
 Used to keep end of recursion equality.

Constructor & Destructor Documentation

RecursiveCompareDualIterator::__construct ( RecursiveDualIterator it,
mode = self::LEAVES_ONLY,
flags = 0 
)

Construct from RecursiveDualIterator.

Parameters:
$itRecursiveDualIterator
$modeshould be LEAVES_ONLY
$flagsshould be 0

Definition at line 30 of file recursivecomparedualiterator.inc.


Member Function Documentation

Returns:
whether both inner iterators are valid and have equal current and key values or both are non valid.

Definition at line 63 of file recursivecomparedualiterator.inc.

       {
              return $this->equal && $this->getInnerIterator()->areEqual();
       }

Here is the call graph for this function:

Returns:
whether both inner iterators are valid and have identical current and key values or both are non valid.

Definition at line 55 of file recursivecomparedualiterator.inc.

       {
              return $this->equal && $this->getInnerIterator()->areIdentical();
       }

Here is the call graph for this function:

Called right after calling getChildren() and its rewind().

Since:
PHP 5.1

Definition at line 201 of file recursiveiteratoriterator.inc.

       {
       }

Here is the caller graph for this function:

Returns:
current sub iterators current children
Since:
PHP 5.1

Definition at line 193 of file recursiveiteratoriterator.inc.

       {
              return $this->ait[$this->count]->getChildren();
       }

Here is the caller graph for this function:

Returns:
whether current sub iterators current element has children
Since:
PHP 5.1

Definition at line 185 of file recursiveiteratoriterator.inc.

       {
              return $this->ait[$this->count]->hasChildren();
       }

Here is the caller graph for this function:

Returns:
current element

Implements Iterator.

Reimplemented in RecursiveTreeIterator, DirectoryTreeIterator, and DirectoryTreeIterator.

Definition at line 99 of file recursiveiteratoriterator.inc.

       {
              $it = $this->ait[$this->count];
              return $it->current();
       }

Calculate $equal.

See also:
$equal

Reimplemented from RecursiveIteratorIterator.

Definition at line 46 of file recursivecomparedualiterator.inc.

       {
              $this->equal &= !$this->getInnerIterator()->getLHS()->valid()
                           && !$this->getInnerIterator()->getRHS()->valid();
       }

Here is the call graph for this function:

Returns:
Current Depth (Number of parents)

Definition at line 177 of file recursiveiteratoriterator.inc.

       {
              return $this->level;
       }

Here is the caller graph for this function:

Returns:
The inner iterator

Implements OuterIterator.

Definition at line 170 of file recursiveiteratoriterator.inc.

       {
              return $this->it;
       }

Here is the caller graph for this function:

RecursiveIteratorIterator::getSubIterator ( level = NULL) [inherited]
Returns:
Sub Iterator at given level or if unspecified the current sub Iterator

Definition at line 159 of file recursiveiteratoriterator.inc.

       {
              if (is_null($level)) {
                     $level = $this->count;
              }
              return @$this->ait[$level];
       }

Here is the caller graph for this function:

Returns:
current key

Implements Iterator.

Reimplemented in RecursiveTreeIterator.

Definition at line 91 of file recursiveiteratoriterator.inc.

       {
              $it = $this->ait[$this->count];
              return $it->key();
       }

Forward to next element.

Implements Iterator.

Definition at line 107 of file recursiveiteratoriterator.inc.

       {
              while ($this->count) {
                     $it = $this->ait[$this->count];
                     if ($it->valid()) {
                            if (!$it->recursed && callHasChildren()) {
                                   $it->recursed = true;
                                   try
                                   {
                                          $sub = callGetChildren();
                                   }
                                   catch (Exception $e)
                                   {
                                          if (!($this->flags & self::CATCH_GET_CHILD))
                                          {
                                                 throw $e;
                                          }
                                          $it->next();
                                          continue;
                                   }
                                   $sub->recursed = false;
                                   $sub->rewind();
                                   if ($sub->valid()) {
                                          $this->ait[++$this->count] = $sub;
                                          if (!$sub instanceof RecursiveIterator) {
                                                 throw new Exception(get_class($sub).'::getChildren() must return an object that implements RecursiveIterator');
                                          }
                                          $this->beginChildren();
                                          return;
                                   }
                                   unset($sub);
                            }
                            $it->next();
                            $it->recursed = false;
                            if ($it->valid()) {
                                   return;
                            }
                            $it->recursed = false;
                     }
                     if ($this->count) {
                            unset($this->ait[$this->count--]);
                            $it = $this->ait[$this->count];
                            $this->endChildren();
                            callNextElement(false);
                     }
              }
              callNextElement(true);
       }

Here is the call graph for this function:

Called when the next element is available.

Definition at line 232 of file recursiveiteratoriterator.inc.

       {
       }

Here is the caller graph for this function:

Rewind iteration andcomparison process.

Starting with $equal = true.

Reimplemented from RecursiveIteratorIterator.

Definition at line 37 of file recursivecomparedualiterator.inc.

       {
              $this->equal = true;
              parent::rewind();
       }
Returns:
whether iterator is valid

Implements Iterator.

Definition at line 75 of file recursiveiteratoriterator.inc.

       {
              $count = $this->count;
              while ($count) {
                     $it = $this->ait[$count];
                     if ($it->valid()) {
                            return true;
                     }
                     $count--;
                     $this->endChildren();
              }
              return false;
       }

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Used to keep end of recursion equality.

That is en leaving a nesting level we need to check whether both child iterators are at their end.

Definition at line 22 of file recursivecomparedualiterator.inc.

const RecursiveIteratorIterator::CATCH_GET_CHILD = 0x00000002 [inherited]

Flag: Catches exceptions during getChildren() calls and simply jumps to the next element.

Definition at line 33 of file recursiveiteratoriterator.inc.

Mode: Show all children prior to their parent.

Definition at line 29 of file recursiveiteratoriterator.inc.

Mode: Only show leaves.

Definition at line 25 of file recursiveiteratoriterator.inc.

Mode: Show parents prior to their children.

Definition at line 27 of file recursiveiteratoriterator.inc.

class RecursiveDualIterator

Synchronous iteration over two recursive iterators.

Author:
Marcus Boerger
Version:
1.0

Definition at line 17 of file recursivedualiterator.inc.

Inheritance diagram for RecursiveDualIterator:
Collaboration diagram for RecursiveDualIterator:

Public Member Functions

 __construct (RecursiveIterator $lhs, RecursiveIterator $rhs, $flags=0x33)
 construct iterator from two RecursiveIterator instances
 hasChildren ()
 getChildren ()
 areIdentical ()
 areEqual ()
 getLHS ()
 getRHS ()
 setFlags ($flags)
 getFlags ()
 rewind ()
 rewind both inner iterators
 valid ()
 current ()
 key ()
 next ()
 move both inner iterators forward

Static Public Member Functions

static compareIterators (Iterator $lhs, Iterator $rhs, $identical=false)
 Compare two iterators.

Public Attributes

const CURRENT_LHS = 0x01
const CURRENT_RHS = 0x02
const CURRENT_ARRAY = 0x03
const CURRENT_0 = 0x00
const KEY_LHS = 0x10
const KEY_RHS = 0x20
const KEY_0 = 0x00
const DEFAULT_FLAGS = 0x13

Private Attributes

 $ref

Constructor & Destructor Documentation

construct iterator from two RecursiveIterator instances

Parameters:
lhsLeft Hand Side Iterator
rhsRight Hand Side Iterator
flagsiteration flags

Definition at line 27 of file recursivedualiterator.inc.


Member Function Documentation

Returns:
whether both inner iterators are valid, have same hasChildren() state and equal current and key values or both are invalid.

Reimplemented from DualIterator.

Definition at line 65 of file recursivedualiterator.inc.

       {
              return $this->getLHS()->hasChildren() === $this->getRHS()->hasChildren()
                     && parent::areEqual();
       }

Here is the call graph for this function:

Returns:
whether both inner iterators are valid, have same hasChildren() state and identical current and key values or both are non valid.

Reimplemented from DualIterator.

Definition at line 56 of file recursivedualiterator.inc.

       {
              return $this->getLHS()->hasChildren() === $this->getRHS()->hasChildren()
                     && parent::areIdentical();
       }

Here is the call graph for this function:

static DualIterator::compareIterators ( Iterator lhs,
Iterator rhs,
identical = false 
) [static, inherited]

Compare two iterators.

Parameters:
lhsLeft Hand Side Iterator
rhsRight Hand Side Iterator
identicalwhether to use areEqual() or areIdentical()
Returns:
whether both iterators are equal/identical
Note:
If one implements RecursiveIterator the other must do as well. And if both do then a recursive comparison is being used.

Definition at line 165 of file dualiterator.inc.

       {
              if ($lhs instanceof RecursiveIterator)
              {
                     if ($rhs instanceof RecursiveIterator)
                     {
                            $it = new RecursiveDualIterator($lhs, $rhs, 
                                                        self::CURRENT_0 | self::KEY_0);
                            $it = new RecursiveCompareDualIterator($it);
                     }
                     else
                     {
                            return false;
                     }
              }
              else
              {
                     $it = new DualIterator($lhs, $rhs, self::CURRENT_0 | self::KEY_0);
              }

              if ($identical)
              {
                     foreach($it as $n)
                     {
                            if (!$it->areIdentical())
                            {
                                   return false;
                            }
                     }
              }
              else
              {
                     foreach($it as $n)
                     {
                            if (!$it->areEqual())
                            {
                                   return false;
                            }
                     }
              }
              return $identical ? $it->areIdentical() : $it->areEqual();
       }
DualIterator::current ( ) [inherited]
Returns:
current value depending on CURRENT_* flags

Implements Iterator.

Definition at line 93 of file dualiterator.inc.

       {
              switch($this->flags & 0x0F)
              {
              default:
              case self::CURRENT_ARRAY:
                     return array($this->lhs->current(), $this->rhs->current());
              case self::CURRENT_LHS:
                     return $this->lhs->current();
              case self::CURRENT_RHS:
                     return $this->rhs->current();
              case self::CURRENT_0:
                     return NULL;
              }
       }
Returns:
new RecursiveDualIterator (late binding) for the two inner iterators current children.

Implements RecursiveIterator.

Definition at line 43 of file recursivedualiterator.inc.

       {
              if (empty($this->ref))
              {
                     $this->ref = new ReflectionClass($this);
              }
              return $this->ref->newInstance(
                                   $this->getLHS()->getChildren(), $this->getRHS()->getChildren(), $this->getFlags());
       }

Here is the call graph for this function:

DualIterator::getFlags ( ) [inherited]
Returns:
current flags

Definition at line 71 of file dualiterator.inc.

       {
              return $this->flags;
       }

Here is the caller graph for this function:

DualIterator::getLHS ( ) [inherited]
Returns:
Left Hand Side Iterator

Definition at line 50 of file dualiterator.inc.

       {
              return $this->lhs;
       }

Here is the caller graph for this function:

DualIterator::getRHS ( ) [inherited]
Returns:
Right Hand Side Iterator

Definition at line 57 of file dualiterator.inc.

       {
              return $this->rhs;
       }

Here is the caller graph for this function:

Returns:
whether both LHS and RHS have children

Implements RecursiveIterator.

Definition at line 35 of file recursivedualiterator.inc.

       {
              return $this->getLHS()->hasChildren() && $this->getRHS()->hasChildren();     
       }

Here is the call graph for this function:

DualIterator::key ( ) [inherited]
Returns:
key value depending on KEY_* flags

Implements Iterator.

Definition at line 111 of file dualiterator.inc.

       {
              switch($this->flags & 0xF0)
              {
              default:
              case self::KEY_LHS:
                     return $this->lhs->key();
              case self::KEY_RHS:
                     return $this->rhs->key();
              case self::KEY_0:
                     return NULL;
              }
       }
DualIterator::next ( ) [inherited]

move both inner iterators forward

Implements Iterator.

Definition at line 127 of file dualiterator.inc.

       {
              $this->lhs->next();
              $this->rhs->next();
       }
DualIterator::rewind ( ) [inherited]

rewind both inner iterators

Implements Iterator.

Definition at line 78 of file dualiterator.inc.

       {
              $this->lhs->rewind();
              $this->rhs->rewind();       
       }
DualIterator::setFlags ( flags) [inherited]
Parameters:
flagsnew flags

Definition at line 64 of file dualiterator.inc.

       {
              $this->flags = $flags;
       }
DualIterator::valid ( ) [inherited]
Returns:
whether both inner iterators are valid

Implements Iterator.

Definition at line 86 of file dualiterator.inc.

       {
              return $this->lhs->valid() && $this->rhs->valid();      
       }

Here is the caller graph for this function:


Member Data Documentation

Definition at line 19 of file recursivedualiterator.inc.

const DualIterator::CURRENT_0 = 0x00 [inherited]

Definition at line 22 of file dualiterator.inc.

const DualIterator::CURRENT_ARRAY = 0x03 [inherited]

Definition at line 21 of file dualiterator.inc.

const DualIterator::CURRENT_LHS = 0x01 [inherited]

Definition at line 19 of file dualiterator.inc.

const DualIterator::CURRENT_RHS = 0x02 [inherited]

Definition at line 20 of file dualiterator.inc.

const DualIterator::DEFAULT_FLAGS = 0x13 [inherited]

Definition at line 28 of file dualiterator.inc.

const DualIterator::KEY_0 = 0x00 [inherited]

Definition at line 26 of file dualiterator.inc.

const DualIterator::KEY_LHS = 0x10 [inherited]

Definition at line 24 of file dualiterator.inc.

const DualIterator::KEY_RHS = 0x20 [inherited]

Definition at line 25 of file dualiterator.inc.

class RegexFindFile

Find files by regular expression.

Author:
Marcus Boerger
Version:
1.1

Definition at line 18 of file regexfindfile.inc.

Inheritance diagram for RegexFindFile:
Collaboration diagram for RegexFindFile:

Public Member Functions

 __construct ($path, $regex)
 Construct from path and regular expression.
 accept ()
 getSearch ()
 rewind ()
 Rewind the inner iterator.
 next ()
 Move to next element.
 valid ()
 key ()
 current ()
 getInnerIterator ()
 __call ($func, $params)
 Aggregate the inner iterator.

Protected Member Functions

 fetch ()
 Fetch next element and store it.
 __clone ()
 hidden __clone

Constructor & Destructor Documentation

RegexFindFile::__construct ( path,
regex 
)

Construct from path and regular expression.

Parameters:
$paththe directory to search in If path contains ';' then this parameter is split and every part of it is used as separate directory.
$regexperl style regular expression to find files with

Reimplemented from FindFile.

Definition at line 27 of file regexfindfile.inc.

       {
              parent::__construct($path, $regex);
       }

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

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 
       }
Returns:
whether the current filename matches the regular expression.

Reimplemented from FindFile.

Definition at line 34 of file regexfindfile.inc.

       {
              return preg_match($this->getSearch(), $this->current());
       }

Here is the call graph for this function:

FilterIterator::current ( ) [inherited]
Returns:
The current value

Implements Iterator.

Reimplemented in RegexIterator, CallbackFilterIterator, and IniGroups.

Definition at line 97 of file filteriterator.inc.

                          {
              return $this->it->current();
       }

Here is the caller graph for this function:

FilterIterator::fetch ( ) [protected, inherited]

Fetch next element and store it.

Returns:
void

Definition at line 61 of file filteriterator.inc.

                                  {
              while ($this->it->valid()) {
                     if ($this->accept()) {
                            return;
                     }
                     $this->it->next();
              };
       }

Here is the call graph for this function:

Here is the caller graph for this function:

Returns:
The inner iterator

Implements OuterIterator.

Definition at line 111 of file filteriterator.inc.

       {
              return $this->it;
       }

Here is the caller graph for this function:

FindFile::getSearch ( ) [inherited]
Returns:
the filename to search for.
Note:
This may be overloaded and contain a regular expression for an extended class that uses regular expressions to search.

Definition at line 59 of file findfile.inc.

       {
              return $this->file;
       }

Here is the caller graph for this function:

FilterIterator::key ( ) [inherited]
Returns:
The current key

Implements Iterator.

Reimplemented in RegexIterator, CallbackFilterIterator, IniGroups, and DirectoryFilterDots.

Definition at line 90 of file filteriterator.inc.

                      {
              return $this->it->key();
       }

Here is the caller graph for this function:

FilterIterator::next ( ) [inherited]

Move to next element.

Returns:
void

Implements Iterator.

Reimplemented in SearchIterator.

Definition at line 75 of file filteriterator.inc.

                       {
              $this->it->next();
              $this->fetch();
       }

Here is the call graph for this function:

FilterIterator::rewind ( ) [inherited]

Rewind the inner iterator.

Implements Iterator.

Reimplemented in SearchIterator.

Definition at line 42 of file filteriterator.inc.

                         {  
              $this->it->rewind();
              $this->fetch();
       }

Here is the call graph for this function:

FilterIterator::valid ( ) [inherited]
Returns:
Whether more elements are available

Implements Iterator.

Reimplemented in SearchIterator.

Definition at line 83 of file filteriterator.inc.

                        {
              return $this->it->valid();
       }
class SearchIterator

Iterator to search for a specific element.

Author:
Marcus Boerger
Version:
1.0

This extended FilterIterator stops after finding the first acceptable value.

Definition at line 20 of file searchiterator.inc.

Inheritance diagram for SearchIterator:
Collaboration diagram for SearchIterator:

Public Member Functions

 rewind ()
 Rewind and reset so that it once again searches.
 valid ()
 next ()
 Do not move forward but instead mark as finished.
 __call ($func, $params)
 Aggregates the inner iterator.
 accept ()
 Accept function to decide whether an element of the inner iterator should be accessible through the Filteriterator.
 key ()
 current ()
 getInnerIterator ()

Protected Member Functions

 fetch ()
 Fetch next element and store it.
 __clone ()
 hidden __clone

Private Attributes

 $done = false

Member Function Documentation

SearchIterator::__call ( func,
params 
)

Aggregates the inner iterator.

Reimplemented from FilterIterator.

Definition at line 52 of file searchiterator.inc.

       {
              return call_user_func_array(array($this->getInnerIterator(), $func), $params);
       }

Here is the call graph for this function:

FilterIterator::__clone ( ) [protected, inherited]

hidden __clone

Reimplemented in KeyFilter.

Definition at line 104 of file filteriterator.inc.

                                    {
              // disallow clone 
       }
FilterIterator::accept ( ) [abstract, inherited]

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.

Reimplemented in RegexIterator, CallbackFilterIterator, FindFile, KeyFilter, NoCvsDirectory, RegexFindFile, DirectoryFilterDots, ParentIterator, and InvertedRegexIterator.

Here is the caller graph for this function:

FilterIterator::current ( ) [inherited]
Returns:
The current value

Implements Iterator.

Reimplemented in RegexIterator, CallbackFilterIterator, and IniGroups.

Definition at line 97 of file filteriterator.inc.

                          {
              return $this->it->current();
       }

Here is the caller graph for this function:

FilterIterator::fetch ( ) [protected, inherited]

Fetch next element and store it.

Returns:
void

Definition at line 61 of file filteriterator.inc.

                                  {
              while ($this->it->valid()) {
                     if ($this->accept()) {
                            return;
                     }
                     $this->it->next();
              };
       }

Here is the call graph for this function:

Here is the caller graph for this function:

Returns:
The inner iterator

Implements OuterIterator.

Definition at line 111 of file filteriterator.inc.

       {
              return $this->it;
       }

Here is the caller graph for this function:

FilterIterator::key ( ) [inherited]
Returns:
The current key

Implements Iterator.

Reimplemented in RegexIterator, CallbackFilterIterator, IniGroups, and DirectoryFilterDots.

Definition at line 90 of file filteriterator.inc.

                      {
              return $this->it->key();
       }

Here is the caller graph for this function:

Do not move forward but instead mark as finished.

Returns:
void

Reimplemented from FilterIterator.

Definition at line 45 of file searchiterator.inc.

       {
              $this->done = true;
       }

Rewind and reset so that it once again searches.

Returns:
void

Reimplemented from FilterIterator.

Definition at line 28 of file searchiterator.inc.

       {
              parent::rewind();
              $this->done = false;
       }
Returns:
whether the current element is valid which can only happen once per iteration.

Reimplemented from FilterIterator.

Definition at line 37 of file searchiterator.inc.

       {
              return !$this->done && parent::valid();
       }

Member Data Documentation

whether an entry was found already

Definition at line 23 of file searchiterator.inc.