Ejemplo n.º 1
0
 /**
  * Compare two iterators.
  *
  * @param \Iterator $lhs       Left  Hand Side Iterator
  * @param \Iterator $rhs       Right Hand Side Iterator
  * @param boolean   $identical Whether to use areEqual() or areIdentical()
  *
  * @return boolean 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.
  */
 public static function compareIterators(\Iterator $lhs, \Iterator $rhs, $identical = false)
 {
     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();
 }
function test($a, $b, $identical = false)
{
    var_dump(DualIterator::compareIterators(new RecursiveArrayIterator($a), new RecursiveArrayIterator($b), $identical));
}