/** * {@inheritdoc} */ public function apply($instance, stdClass $schema, Context $context, Walker $walker) { // implementation of the algorithms described in 5.4.4.4 and in 8.3 foreach ($instance as $property => $value) { $schemas = []; if (isset($schema->properties->{$property})) { $schemas[] = $schema->properties->{$property}; } foreach ($schema->patternProperties as $regex => $propertySchema) { if (Utils::matchesRegex($property, $regex)) { $schemas[] = $propertySchema; } } if (empty($schemas)) { if (is_object($schema->additionalProperties)) { $schemas[] = $schema->additionalProperties; } elseif ($schema->additionalProperties === false) { $context->addViolation('additional property "%s" is not allowed', [$property]); } } $context->enterNode($property); foreach ($schemas as $childSchema) { $walker->applyConstraints($value, $childSchema, $context); } $context->leaveNode(); } }
/** * {@inheritdoc} */ public function apply($instance, stdClass $schema, Context $context, Walker $walker) { if (!Utils::matchesRegex($instance, $schema->pattern)) { $context->addViolation('should match regex "%s"', [$schema->pattern]); } }