Schema
3 years ago
Builder.php
1 year ago
Schema.php
8 months ago
ValidationException.php
4 years ago
Validator.php
3 years ago
index.php
3 years ago
Builder.php
61 lines
| 1 | <?php declare(strict_types = 1); |
| 2 | |
| 3 | namespace MailPoet\Validator; |
| 4 | |
| 5 | if (!defined('ABSPATH')) exit; |
| 6 | |
| 7 | |
| 8 | use MailPoet\Validator\Schema\AnyOfSchema; |
| 9 | use MailPoet\Validator\Schema\ArraySchema; |
| 10 | use MailPoet\Validator\Schema\BooleanSchema; |
| 11 | use MailPoet\Validator\Schema\IntegerSchema; |
| 12 | use MailPoet\Validator\Schema\NullSchema; |
| 13 | use MailPoet\Validator\Schema\NumberSchema; |
| 14 | use MailPoet\Validator\Schema\ObjectSchema; |
| 15 | use MailPoet\Validator\Schema\OneOfSchema; |
| 16 | use MailPoet\Validator\Schema\StringSchema; |
| 17 | |
| 18 | // See: https://developer.wordpress.org/rest-api/extending-the-rest-api/schema/ |
| 19 | class Builder { |
| 20 | public static function string(): StringSchema { |
| 21 | return new StringSchema(); |
| 22 | } |
| 23 | |
| 24 | public static function number(): NumberSchema { |
| 25 | return new NumberSchema(); |
| 26 | } |
| 27 | |
| 28 | public static function integer(): IntegerSchema { |
| 29 | return new IntegerSchema(); |
| 30 | } |
| 31 | |
| 32 | public static function boolean(): BooleanSchema { |
| 33 | return new BooleanSchema(); |
| 34 | } |
| 35 | |
| 36 | public static function null(): NullSchema { |
| 37 | return new NullSchema(); |
| 38 | } |
| 39 | |
| 40 | public static function array(?Schema $items = null): ArraySchema { |
| 41 | $array = new ArraySchema(); |
| 42 | return $items ? $array->items($items) : $array; |
| 43 | } |
| 44 | |
| 45 | /** @param array<string, Schema>|null $properties */ |
| 46 | public static function object(?array $properties = null): ObjectSchema { |
| 47 | $object = new ObjectSchema(); |
| 48 | return $properties === null ? $object : $object->properties($properties); |
| 49 | } |
| 50 | |
| 51 | /** @param Schema[] $schemas */ |
| 52 | public static function oneOf(array $schemas): OneOfSchema { |
| 53 | return new OneOfSchema($schemas); |
| 54 | } |
| 55 | |
| 56 | /** @param Schema[] $schemas */ |
| 57 | public static function anyOf(array $schemas): AnyOfSchema { |
| 58 | return new AnyOfSchema($schemas); |
| 59 | } |
| 60 | } |
| 61 |