*/ class ConstConstraint extends Constraint { /** * {@inheritdoc} */ public function check(&$element, $schema = null, ?JsonPointer $path = null, $i = null): void { // Only validate const if the attribute exists if ($element instanceof UndefinedConstraint && (!isset($schema->required) || !$schema->required)) { return; } $const = $schema->const; $type = gettype($element); $constType = gettype($const); if ($this->factory->getConfig(self::CHECK_MODE_TYPE_CAST) && $type === 'array' && $constType === 'object') { if (DeepComparer::isEqual((object) $element, $const)) { return; } } if (DeepComparer::isEqual($element, $const)) { return; } $this->addError(ConstraintError::CONSTANT(), $path, ['const' => $schema->const]); } }