Schema
11 months ago
class-builder.php
11 months ago
class-schema.php
11 months ago
class-validation-exception.php
11 months ago
class-validator.php
11 months ago
index.php
11 months ago
class-builder.php
45 lines
| 1 | <?php |
| 2 | declare( strict_types = 1 ); |
| 3 | namespace Automattic\WooCommerce\EmailEditor\Validator; |
| 4 | if (!defined('ABSPATH')) exit; |
| 5 | use Automattic\WooCommerce\EmailEditor\Validator\Schema\Any_Of_Schema; |
| 6 | use Automattic\WooCommerce\EmailEditor\Validator\Schema\Array_Schema; |
| 7 | use Automattic\WooCommerce\EmailEditor\Validator\Schema\Boolean_Schema; |
| 8 | use Automattic\WooCommerce\EmailEditor\Validator\Schema\Integer_Schema; |
| 9 | use Automattic\WooCommerce\EmailEditor\Validator\Schema\Null_Schema; |
| 10 | use Automattic\WooCommerce\EmailEditor\Validator\Schema\Number_Schema; |
| 11 | use Automattic\WooCommerce\EmailEditor\Validator\Schema\Object_Schema; |
| 12 | use Automattic\WooCommerce\EmailEditor\Validator\Schema\One_Of_Schema; |
| 13 | use Automattic\WooCommerce\EmailEditor\Validator\Schema\String_Schema; |
| 14 | class Builder { |
| 15 | public static function string(): String_Schema { |
| 16 | return new String_Schema(); |
| 17 | } |
| 18 | public static function number(): Number_Schema { |
| 19 | return new Number_Schema(); |
| 20 | } |
| 21 | public static function integer(): Integer_Schema { |
| 22 | return new Integer_Schema(); |
| 23 | } |
| 24 | public static function boolean(): Boolean_Schema { |
| 25 | return new Boolean_Schema(); |
| 26 | } |
| 27 | public static function null(): Null_Schema { |
| 28 | return new Null_Schema(); |
| 29 | } |
| 30 | public static function array( ?Schema $items = null ): Array_Schema { |
| 31 | $array = new Array_Schema(); |
| 32 | return $items ? $array->items( $items ) : $array; |
| 33 | } |
| 34 | public static function object( ?array $properties = null ): Object_Schema { |
| 35 | $object = new Object_Schema(); |
| 36 | return null === $properties ? $object : $object->properties( $properties ); |
| 37 | } |
| 38 | public static function one_of( array $schemas ): One_Of_Schema { |
| 39 | return new One_Of_Schema( $schemas ); |
| 40 | } |
| 41 | public static function any_of( array $schemas ): Any_Of_Schema { |
| 42 | return new Any_Of_Schema( $schemas ); |
| 43 | } |
| 44 | } |
| 45 |