function compare($a, $b, $negate = false) { $schema = new \Fulfil\Schema(['props' => ['a' => true, 'b' => true], 'rules' => [$rule = new Equal(['left' => 'a', 'right' => 'b'])]]); if ($negate) { $rule->negate = $negate; } $ctx = new \Fulfil\Context(['allowIncomplete' => true]); $rule->validate(['left' => $a, 'right' => $b], $ctx); $flat = $ctx->flatten(); return $flat; }
} cmp_bool: if (is_bool($left) && is_bool($right)) { if ($this->test($left != $right)) { $ctx->addReason($this, ['id' => 'equal.boolNotEqual', 'params' => $properties]); } return; } } private function test($result) { return !$this->negate ? $result : !$result; } private function compareString(Context $ctx, $left, $right) { if (is_string($left) && is_string($right)) { if (static::$intlAvailable) { if ($this->test(\Normalizer::normalize($left) != \Normalizer::normalize($right))) { $ctx->addReason($this, ['id' => 'equal.stringNotEqual', 'params' => $properties]); } } else { $ctx->setIncomplete($this); } } else { $ctx->addReason($this, ['id' => 'equal.incomparable', 'params' => ['leftProp' => $this->left, 'rightProp' => $this->right]]); } return; } } Equal::$intlAvailable = extension_loaded('intl');