function ObjectConstraint::validateElement
Validates the element properties
Parameters
\StdClass $element Element to validate:
array $matches Matches from patternProperties (if any):
\StdClass $schema ObjectConstraint definition:
JsonPointer|null $path Current test path:
\StdClass $properties Properties:
mixed $additionalProp Additional properties:
1 call to ObjectConstraint::validateElement()
- ObjectConstraint::check in vendor/
justinrainbow/ json-schema/ src/ JsonSchema/ Constraints/ ObjectConstraint.php - invokes the validation of an element
File
-
vendor/
justinrainbow/ json-schema/ src/ JsonSchema/ Constraints/ ObjectConstraint.php, line 93
Class
- ObjectConstraint
- The ObjectConstraint Constraints, validates an object against a given schema
Namespace
JsonSchema\ConstraintsCode
public function validateElement($element, $matches, $schema = null, ?JsonPointer $path = null, $properties = null, $additionalProp = null) {
$this->validateMinMaxConstraint($element, $schema, $path);
foreach ($element as $i => $value) {
$definition = $this->getProperty($properties, $i);
// no additional properties allowed
if (!in_array($i, $matches) && $additionalProp === false && $this->inlineSchemaProperty !== $i && !$definition) {
$this->addError($path, 'The property ' . $i . ' is not defined and the definition does not allow additional properties', 'additionalProp');
}
// additional properties defined
if (!in_array($i, $matches) && $additionalProp && !$definition) {
if ($additionalProp === true) {
$this->checkUndefined($value, null, $path, $i, in_array($i, $this->appliedDefaults));
}
else {
$this->checkUndefined($value, $additionalProp, $path, $i, in_array($i, $this->appliedDefaults));
}
}
// property requires presence of another
$require = $this->getProperty($definition, 'requires');
if ($require && !$this->getProperty($element, $require)) {
$this->addError($path, 'The presence of the property ' . $i . ' requires that ' . $require . ' also be present', 'requires');
}
$property = $this->getProperty($element, $i, $this->factory
->createInstanceFor('undefined'));
if (is_object($property)) {
$this->validateMinMaxConstraint(!$property instanceof UndefinedConstraint ? $property : $element, $definition, $path);
}
}
}