RecursiveCachingIterator Class Reference

Cached recursive iteration over another Iterator. More...

Inheritance diagram for RecursiveCachingIterator:

Inheritance graph
{CachingRecursiveIterator\n||}{CachingIterator\n|+ CALL_TOSTRING\l+ CATCH_GET_CHILD\l+ TOSTRING_USE_CURRENT\l+ TOSTRING_USE_KEY\l- $current\l- $it\l- $key\l- $strValue\l- $valid\l|+ __call()\l+ __construct()\l+ __toString()\l+ current()\l+ getInnerIterator()\l+ hasNext()\l+ key()\l+ next()\l+ rewind()\l+ valid()\l}{OuterIterator\n||+ getInnerIterator()\l}{Iterator\n||+ current()\l+ key()\l+ next()\l+ rewind()\l+ valid()\l}{RecursiveIterator\n||+ getChildren()\l+ hasChildren()\l}{Traversable\n||}
[legend]
Collaboration diagram for RecursiveCachingIterator:

Collaboration graph
{CachingIterator\n|+ CALL_TOSTRING\l+ CATCH_GET_CHILD\l+ TOSTRING_USE_CURRENT\l+ TOSTRING_USE_KEY\l- $current\l- $it\l- $key\l- $strValue\l- $valid\l|+ __call()\l+ __construct()\l+ __toString()\l+ current()\l+ getInnerIterator()\l+ hasNext()\l+ key()\l+ next()\l+ rewind()\l+ valid()\l}{OuterIterator\n||+ getInnerIterator()\l}{Iterator\n||+ current()\l+ key()\l+ next()\l+ rewind()\l+ valid()\l}{RecursiveIterator\n||+ getChildren()\l+ hasChildren()\l}{Traversable\n||}
[legend]
List of all members.

Public Member Functions

 __call ($func, $params)
 __construct (RecursiveIterator $it, $flags=self::CALL_TOSTRING)
 __toString ()
 current ()
 getChildren ()
 getInnerIterator ()
 hasChildren ()
 hasNext ()
 key ()
 next ()
 rewind ()
 valid ()

Public Attributes

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

Private Attributes

 $getChildren
 $hasChildren

Detailed Description

Cached recursive iteration over another Iterator.

Author:
Marcus Boerger
Version:
1.2
Since:
PHP 5.1
See also:
CachingIterator

Definition at line 20 of file recursivecachingiterator.inc.


Constructor & Destructor Documentation

RecursiveCachingIterator::__construct ( RecursiveIterator it,
flags = self::CALL_TOSTRING 
)

Construct from another iterator.

Parameters:
it Iterator to cache
flags Bitmask:
  • CALL_TOSTRING (whether to call __toString() for every element)
  • CATCH_GET_CHILD (whether to catch exceptions when trying to get childs)

Definition at line 32 of file recursivecachingiterator.inc.

References CachingIterator::$it.

00033     {
00034         parent::__construct($it, $flags);
00035     }


Member Function Documentation

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

Aggregate the inner iterator.

Parameters:
func Name of method to invoke
params Array of parameters to pass to method

Definition at line 122 of file cachingiterator.inc.

00123     {
00124         return call_user_func_array(array($this->it, $func), $params);
00125     }

CachingIterator::__toString (  )  [inherited]

Returns:
the string represenatation that was generated for the current element

Exceptions:
exception when CALL_TOSTRING was not specified in constructor

Definition at line 131 of file cachingiterator.inc.

References CachingIterator::__construct(), CachingIterator::current(), and CachingIterator::key().

00132     {
00133         if ($this->flags & self::TOSTRING_USE_KEY)
00134         {
00135             return $this->key;
00136         }
00137         else if ($this->flags & self::TOSTRING_USE_CURRENT)
00138         {
00139             return $this->current;
00140         }
00141         if (!$this->flags & self::CALL_TOSTRING)
00142         {
00143             throw new exception('CachingIterator does not fetch string value (see CachingIterator::__construct)');
00144         }
00145         return $this->strValue;
00146     }

Here is the call graph for this function:

CachingIterator::__constructCachingIterator::currentCachingIterator::keyCachingIterator::nextCachingIterator::valid

CachingIterator::current (  )  [inherited]

Returns:
the current element

Implements Iterator.

Definition at line 105 of file cachingiterator.inc.

Referenced by CachingIterator::__toString(), and CachingIterator::next().

00106     {
00107         return $this->current;
00108     }

RecursiveCachingIterator::getChildren (  ) 

Returns:
An Iterator for the children

Implements RecursiveIterator.

Definition at line 93 of file recursivecachingiterator.inc.

00094     {
00095         return $this->getChildren;
00096     }

CachingIterator::getInnerIterator (  )  [inherited]

Returns:
The inner iterator

Implements OuterIterator.

Definition at line 151 of file cachingiterator.inc.

00152     {
00153         return $this->it;
00154     }

RecursiveCachingIterator::hasChildren (  ) 

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.

00087     {
00088         return $this->hasChildren;
00089     }

CachingIterator::hasNext (  )  [inherited]

Returns:
whether there is one more element

Definition at line 98 of file cachingiterator.inc.

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

CachingIterator::key (  )  [inherited]

Returns:
the current key

Implements Iterator.

Definition at line 112 of file cachingiterator.inc.

Referenced by CachingIterator::__toString(), and CachingIterator::next().

00113     {
00114         return $this->key;
00115     }

CachingIterator::next (  )  [inherited]

Forward to the next element.

Implements Iterator.

Definition at line 69 of file cachingiterator.inc.

References CachingIterator::current(), CachingIterator::key(), and CachingIterator::valid().

Referenced by CachingIterator::__construct(), and CachingIterator::rewind().

00070     {
00071         if ($this->valid = $this->it->valid()) {
00072             $this->current = $this->it->current();
00073             $this->key = $this->it->key();
00074             if ($this->flags & self::CALL_TOSTRING) {
00075                 if (is_object($this->current)) {
00076                     $this->strValue = $this->current->__toString();
00077                 } else {
00078                     $this->strValue = (string)$this->current;
00079                 }
00080             }
00081         } else {
00082             $this->current = NULL;
00083             $this->key = NULL;
00084             $this->strValue = NULL;
00085         }
00086         $this->it->next();
00087     }

Here is the call graph for this function:

CachingIterator::currentCachingIterator::keyCachingIterator::valid

RecursiveCachingIterator::rewind (  ) 

Rewind Iterator.

Reimplemented from CachingIterator.

CachingIterator::valid (  )  [inherited]

Returns:
whether teh iterator is valid

Implements Iterator.

Definition at line 91 of file cachingiterator.inc.

Referenced by CachingIterator::next().

00092     {
00093         return $this->valid;
00094     }


Member Data Documentation

RecursiveCachingIterator::$getChildren [private]

Definition at line 23 of file recursivecachingiterator.inc.

RecursiveCachingIterator::$hasChildren [private]

Definition at line 22 of file recursivecachingiterator.inc.

const CachingIterator::CALL_TOSTRING = 0x00000001 [inherited]

Definition at line 30 of file cachingiterator.inc.

Referenced by DirectoryTreeIterator::__construct(), and DirectoryGraphIterator::__construct().

const CachingIterator::CATCH_GET_CHILD = 0x00000002 [inherited]

Definition at line 31 of file cachingiterator.inc.

Referenced by DirectoryTreeIterator::__construct(), and DirectoryGraphIterator::__construct().

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.


The documentation for this class was generated from the following file:
Generated on Thu Apr 26 01:06:46 2007 for SPL-StandardPHPLibrary by  doxygen 1.5.2