/** * {@inheritdoc} */ public function normalize(stdClass $schema, Context $context, Walker $walker) { $context->enterNode('type'); if (is_string($schema->type)) { if (!Types::isPrimitive($schema->type)) { throw new NotPrimitiveTypeException($context); } } elseif (is_array($schema->type)) { foreach ($schema->type as $index => $type) { $context->enterNode($index); if (!is_string($type)) { throw new InvalidTypeException($context, Types::TYPE_STRING); } if (!Types::isPrimitive($type)) { throw new NotPrimitiveTypeException($context); } $context->leaveNode(); } if (count(array_unique($schema->type)) !== count($schema->type)) { throw new NotUniqueException($context); } } else { throw new InvalidTypeException($context, [Types::TYPE_STRING, Types::TYPE_ARRAY]); } $context->leaveNode(); }
/** * {@inheritdoc} */ public function normalize(stdClass $schema, Context $context, Walker $walker) { $context->enterNode('pattern'); if (!is_string($schema->pattern)) { throw new InvalidTypeException($context, Types::TYPE_STRING); } if (!Utils::isValidRegex($schema->pattern)) { throw new InvalidRegexException($context); } $context->leaveNode(); }
/** * {@inheritdoc} */ public function normalize(stdClass $schema, Context $context, Walker $walker) { $context->enterNode('multipleOf'); if (!Types::isA($schema->multipleOf, Types::TYPE_NUMBER)) { throw new InvalidTypeException($context, Types::TYPE_NUMBER); } if ($schema->multipleOf <= 0) { throw new NotStrictlyPositiveException($context); } $context->leaveNode(); }
/** * {@inheritdoc} */ public function normalize(stdClass $schema, Context $context, Walker $walker) { $keyword = $this->keywords()[0]; $context->enterNode($keyword); if (!is_int($schema->{$keyword})) { throw new InvalidTypeException($context, Types::TYPE_INTEGER); } if ($schema->{$keyword} < 0) { throw new LessThanZeroException($context); } $context->leaveNode(); }
/** * {@inheritdoc} */ public function normalize(stdClass $schema, Context $context, Walker $walker) { $context->enterNode('enum'); if (!is_array($schema->enum)) { throw new InvalidTypeException($context, Types::TYPE_ARRAY); } if (count($schema->enum) === 0) { throw new EmptyArrayException($context); } foreach ($schema->enum as $i => $aItem) { foreach ($schema->enum as $j => $bItem) { if ($i !== $j && Utils::areEqual($aItem, $bItem)) { throw new NotUniqueException($context); } } } $context->leaveNode(); }
/** * {@inheritdoc} */ public function normalize(stdClass $schema, Context $context, Walker $walker) { $context->enterNode('required'); if (!is_array($schema->required)) { throw new InvalidTypeException($context, Types::TYPE_ARRAY); } if (0 === ($requiredCount = count($schema->required))) { throw new EmptyArrayException($context); } foreach ($schema->required as $index => $property) { if (!is_string($property)) { $context->enterNode($index); throw new InvalidTypeException($context, Types::TYPE_STRING); } } if ($requiredCount !== count(array_unique($schema->required))) { throw new NotUniqueException($context); } $context->leaveNode(); }