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

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
 
$this getChildren = NULL
 
const TOSTRING_USE_CURRENT = 0x00000020
 
const TOSTRING_USE_KEY = 0x00000010
 

Private Attributes

 $getChildren
 
 $hasChildren
 
 $ref
 

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
itIterator to cache
flagsBitmask:
  • 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.

33  {
34  parent::__construct($it, $flags);
35  }

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.

123  {
124  return call_user_func_array(array($this->it, $func), $params);
125  }
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.

References CachingIterator\$current, CachingIterator\$key, and CachingIterator\$strValue.

132  {
133  if ($this->flags & self::TOSTRING_USE_KEY)
134  {
135  return $this->key;
136  }
137  else if ($this->flags & self::TOSTRING_USE_CURRENT)
138  {
139  return $this->current;
140  }
141  if (!$this->flags & self::CALL_TOSTRING)
142  {
143  throw new exception('CachingIterator does not fetch string value (see CachingIterator::__construct)');
144  }
145  return $this->strValue;
146  }
CachingIterator::current ( )
inherited
Returns
the current element

Implements Iterator.

Definition at line 105 of file cachingiterator.inc.

References CachingIterator\$current.

Referenced by CachingIterator\next().

106  {
107  return $this->current;
108  }
RecursiveCachingIterator::getChildren ( )
Returns
An Iterator for the children

Implements RecursiveIterator.

Definition at line 93 of file recursivecachingiterator.inc.

References $getChildren.

Referenced by next().

CachingIterator::getInnerIterator ( )
inherited
Returns
The inner iterator

Implements OuterIterator.

Definition at line 151 of file cachingiterator.inc.

References CachingIterator\$it.

152  {
153  return $this->it;
154  }
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.

References $hasChildren.

Referenced by next().

CachingIterator::hasNext ( )
inherited
Returns
whether there is one more element

Definition at line 98 of file cachingiterator.inc.

99  {
100  return $this->it->valid();
101  }
CachingIterator::key ( )
inherited
Returns
the current key

Implements Iterator.

Definition at line 112 of file cachingiterator.inc.

References CachingIterator\$key.

Referenced by CachingIterator\next().

113  {
114  return $this->key;
115  }
RecursiveCachingIterator::next ( )

Forward to next element if necessary then an Iterator for the Children will be created.

Implements Iterator.

Definition at line 49 of file recursivecachingiterator.inc.

References $ref, getChildren(), and hasChildren().

50  {
51  if ($this->hasChildren = $this->it->hasChildren())
52  {
53  try
54  {
55  $child = $this->it->getChildren();
56  if (!$this->ref)
57  {
58  $this->ref = new ReflectionClass($this);
59  }
60  $this->getChildren = $ref->newInstance($child, $this->flags);
61  }
62  catch(Exception $e)
63  {
64  if (!$this->flags & self::CATCH_GET_CHILD)
65  {
66  throw $e;
67  }
68  $this->hasChildren = false;
69  $this->getChildren = NULL;
70  }
71  } else
72  {
73  $this->getChildren = NULL;
74  }
75  parent::next();
76  }
Basic Exception class.
Definition: spl.php:258

Here is the call graph for this function:

RecursiveCachingIterator::rewind ( )

Rewind Iterator.

Implements Iterator.

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

Implements Iterator.

Definition at line 91 of file cachingiterator.inc.

References CachingIterator\$valid.

Referenced by CachingIterator\next().

92  {
93  return $this->valid;
94  }

Member Data Documentation

RecursiveCachingIterator::$getChildren
private

Definition at line 23 of file recursivecachingiterator.inc.

Referenced by getChildren().

RecursiveCachingIterator::$hasChildren
private

Definition at line 22 of file recursivecachingiterator.inc.

Referenced by hasChildren().

RecursiveCachingIterator::$ref
private

Definition at line 78 of file recursivecachingiterator.inc.

Referenced by next().

const CachingIterator::CALL_TOSTRING = 0x00000001
inherited
const CachingIterator::CATCH_GET_CHILD = 0x00000002
inherited
$this RecursiveCachingIterator::getChildren = NULL

Definition at line 42 of file recursivecachingiterator.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.


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