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

Public Member Functions

 __construct (RecursiveDualIterator $it, $mode=self::LEAVES_ONLY, $flags=0)
 
 areEqual ()
 
 areIdentical ()
 
 beginChildren ()
 
 callGetChildren ()
 
 callHasChildren ()
 
 current ()
 
 endChildren ()
 
 getDepth ()
 
 getInnerIterator ()
 
 getSubIterator ($level=NULL)
 
 key ()
 
 next ()
 
 nextElement ()
 
 rewind ()
 
 valid ()
 

Public Attributes

const CATCH_GET_CHILD = 0x00000002
 
const CHILD_FIRST = 2
 
const LEAVES_ONLY = 0
 
const SELF_FIRST = 1
 

Protected Attributes

 $equal = false
 

Detailed Description

Recursive comparison iterator for a RecursiveDualIterator.

Author
Marcus Boerger
Version
1.0

Definition at line 17 of file recursivecomparedualiterator.inc.

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.

31  {
32  parent::__construct($it);
33  }

Member Function Documentation

RecursiveCompareDualIterator::areEqual ( )
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.

References RecursiveIteratorIterator\getInnerIterator().

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

Here is the call graph for this function:

RecursiveCompareDualIterator::areIdentical ( )
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.

References RecursiveIteratorIterator\getInnerIterator().

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

Here is the call graph for this function:

RecursiveIteratorIterator::beginChildren ( )
inherited

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

Since
PHP 5.1

Definition at line 201 of file recursiveiteratoriterator.inc.

Referenced by RecursiveIteratorIterator\next().

202  {
203  }
RecursiveIteratorIterator::callGetChildren ( )
inherited
Returns
current sub iterators current children
Since
PHP 5.1

Definition at line 193 of file recursiveiteratoriterator.inc.

References RecursiveIteratorIterator\$count.

Referenced by RecursiveIteratorIterator\next().

194  {
195  return $this->ait[$this->count]->getChildren();
196  }
RecursiveIteratorIterator::callHasChildren ( )
inherited
Returns
whether current sub iterators current element has children
Since
PHP 5.1

Definition at line 185 of file recursiveiteratoriterator.inc.

References RecursiveIteratorIterator\$count.

Referenced by RecursiveIteratorIterator\callNextElement(), and RecursiveIteratorIterator\next().

186  {
187  return $this->ait[$this->count]->hasChildren();
188  }
RecursiveIteratorIterator::current ( )
inherited
Returns
current element

Implements Iterator.

Definition at line 99 of file recursiveiteratoriterator.inc.

References RecursiveIteratorIterator\$count, and $it.

100  {
101  $it = $this->ait[$this->count];
102  return $it->current();
103  }
$it
Definition: class_tree.php:105
RecursiveCompareDualIterator::endChildren ( )

Calculate $equal.

See Also
$equal

Definition at line 46 of file recursivecomparedualiterator.inc.

References RecursiveIteratorIterator\getInnerIterator().

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

Here is the call graph for this function:

RecursiveIteratorIterator::getDepth ( )
inherited
Returns
Current Depth (Number of parents)

Definition at line 177 of file recursiveiteratoriterator.inc.

Referenced by DirectoryTreeIterator\current(), and RecursiveTreeIterator\getPrefix().

178  {
179  return $this->level;
180  }
RecursiveIteratorIterator::getInnerIterator ( )
inherited
Returns
The inner iterator

Implements OuterIterator.

Definition at line 170 of file recursiveiteratoriterator.inc.

References $it.

Referenced by areEqual(), areIdentical(), and endChildren().

171  {
172  return $this->it;
173  }
$it
Definition: class_tree.php:105
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.

References RecursiveIteratorIterator\$count.

Referenced by DirectoryTreeIterator\__call(), RecursiveTreeIterator\__call(), DirectoryTreeIterator\current(), and RecursiveTreeIterator\getPrefix().

160  {
161  if (is_null($level)) {
162  $level = $this->count;
163  }
164  return @$this->ait[$level];
165  }
RecursiveIteratorIterator::key ( )
inherited
Returns
current key

Implements Iterator.

Definition at line 91 of file recursiveiteratoriterator.inc.

References RecursiveIteratorIterator\$count, and $it.

92  {
93  $it = $this->ait[$this->count];
94  return $it->key();
95  }
$it
Definition: class_tree.php:105
RecursiveIteratorIterator::next ( )
inherited

Forward to next element.

Implements Iterator.

Definition at line 107 of file recursiveiteratoriterator.inc.

References RecursiveIteratorIterator\$count, $it, RecursiveIteratorIterator\beginChildren(), RecursiveIteratorIterator\callGetChildren(), RecursiveIteratorIterator\callHasChildren(), RecursiveIteratorIterator\callNextElement(), and RecursiveIteratorIterator\endChildren().

108  {
109  while ($this->count) {
110  $it = $this->ait[$this->count];
111  if ($it->valid()) {
112  if (!$it->recursed && callHasChildren()) {
113  $it->recursed = true;
114  try
115  {
116  $sub = callGetChildren();
117  }
118  catch (Exception $e)
119  {
120  if (!($this->flags & self::CATCH_GET_CHILD))
121  {
122  throw $e;
123  }
124  $it->next();
125  continue;
126  }
127  $sub->recursed = false;
128  $sub->rewind();
129  if ($sub->valid()) {
130  $this->ait[++$this->count] = $sub;
131  if (!$sub instanceof RecursiveIterator) {
132  throw new Exception(get_class($sub).'::getChildren() must return an object that implements RecursiveIterator');
133  }
134  $this->beginChildren();
135  return;
136  }
137  unset($sub);
138  }
139  $it->next();
140  $it->recursed = false;
141  if ($it->valid()) {
142  return;
143  }
144  $it->recursed = false;
145  }
146  if ($this->count) {
147  unset($this->ait[$this->count--]);
148  $it = $this->ait[$this->count];
149  $this->endChildren();
150  callNextElement(false);
151  }
152  }
153  callNextElement(true);
154  }
$it
Definition: class_tree.php:105
Interface for recursive iteration with RecursiveIteratorIterator.
beginChildren()
Called right after calling getChildren() and its rewind().
Basic Exception class.
Definition: spl.php:258
endChildren()
Called after current child iterator is invalid and right before it gets destructed.

Here is the call graph for this function:

RecursiveIteratorIterator::nextElement ( )
inherited

Called when the next element is available.

Definition at line 232 of file recursiveiteratoriterator.inc.

Referenced by RecursiveIteratorIterator\callNextElement().

233  {
234  }
RecursiveCompareDualIterator::rewind ( )

Rewind iteration andcomparison process.

Starting with $equal = true.

Implements Iterator.

Definition at line 37 of file recursivecomparedualiterator.inc.

38  {
39  $this->equal = true;
40  parent::rewind();
41  }
RecursiveIteratorIterator::valid ( )
inherited
Returns
whether iterator is valid

Implements Iterator.

Definition at line 75 of file recursiveiteratoriterator.inc.

References RecursiveIteratorIterator\$count, $it, and RecursiveIteratorIterator\endChildren().

Referenced by RecursiveIteratorIterator\callNextElement().

76  {
78  while ($count) {
79  $it = $this->ait[$count];
80  if ($it->valid()) {
81  return true;
82  }
83  $count--;
84  $this->endChildren();
85  }
86  return false;
87  }
$it
Definition: class_tree.php:105
endChildren()
Called after current child iterator is invalid and right before it gets destructed.

Here is the call graph for this function:

Member Data Documentation

RecursiveCompareDualIterator::$equal = false
protected

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.

const RecursiveIteratorIterator::CHILD_FIRST = 2
inherited

Mode: Show all children prior to their parent.

Definition at line 29 of file recursiveiteratoriterator.inc.

const RecursiveIteratorIterator::LEAVES_ONLY = 0
inherited

Mode: Only show leaves.

Definition at line 25 of file recursiveiteratoriterator.inc.

const RecursiveIteratorIterator::SELF_FIRST = 1
inherited

Mode: Show parents prior to their children.

Definition at line 27 of file recursiveiteratoriterator.inc.


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