Webmozart\Expression\Logic\OrX::equivalentTo PHP Метод

equivalentTo() публичный метод

public equivalentTo ( Webmozart\Expression\Expression $other )
$other Webmozart\Expression\Expression
    public function equivalentTo(Expression $other)
    {
        if (get_class($this) !== get_class($other)) {
            return false;
        }
        /* @var static $other */
        $leftDisjuncts = $this->disjuncts;
        $rightDisjuncts = $other->disjuncts;
        foreach ($leftDisjuncts as $leftDisjunct) {
            foreach ($rightDisjuncts as $j => $rightDisjunct) {
                if ($leftDisjunct->equivalentTo($rightDisjunct)) {
                    unset($rightDisjuncts[$j]);
                    continue 2;
                }
            }
            // $leftDisjunct was not found in $rightDisjuncts
            return false;
        }
        // All $leftDisjuncts were found. Check if any $rightDisjuncts are left
        return 0 === count($rightDisjuncts);
    }

Usage Example

Пример #1
0
 public function testEquivalentTo()
 {
     $disjunction1 = new OrX(array(new Key('name', new Same('10')), new Key('age', new GreaterThan(0))));
     // disjunctions match independent of the order of the conjuncts
     $disjunction2 = new OrX(array(new Key('age', new GreaterThan(0)), new Key('name', new Same('10'))));
     $disjunction3 = new OrX(array(new Key('age', new GreaterThan(0))));
     $this->assertTrue($disjunction1->equivalentTo($disjunction2));
     $this->assertTrue($disjunction2->equivalentTo($disjunction1));
     $this->assertFalse($disjunction2->equivalentTo($disjunction3));
     $this->assertFalse($disjunction3->equivalentTo($disjunction2));
     $this->assertFalse($disjunction1->equivalentTo($disjunction3));
     $this->assertFalse($disjunction3->equivalentTo($disjunction1));
 }