class-any-of-schema.php
1 year ago
class-array-schema.php
1 year ago
class-boolean-schema.php
1 year ago
class-integer-schema.php
1 year ago
class-null-schema.php
1 year ago
class-number-schema.php
1 year ago
class-object-schema.php
1 year ago
class-one-of-schema.php
1 year ago
class-string-schema.php
1 year ago
class-array-schema.php
61 lines
| 1 | <?php |
| 2 | /** |
| 3 | * This file is part of the WooCommerce Email Editor package |
| 4 | * |
| 5 | * @package Automattic\WooCommerce\EmailEditor |
| 6 | */ |
| 7 | |
| 8 | declare( strict_types = 1 ); |
| 9 | namespace Automattic\WooCommerce\EmailEditor\Validator\Schema; |
| 10 | |
| 11 | use Automattic\WooCommerce\EmailEditor\Validator\Schema; |
| 12 | |
| 13 | /** |
| 14 | * Represents a schema for an array. |
| 15 | * See: https://developer.wordpress.org/rest-api/extending-the-rest-api/schema/#arrays |
| 16 | */ |
| 17 | class Array_Schema extends Schema { |
| 18 | /** |
| 19 | * Schema definition. |
| 20 | * |
| 21 | * @var array |
| 22 | */ |
| 23 | protected $schema = array( |
| 24 | 'type' => 'array', |
| 25 | ); |
| 26 | |
| 27 | /** |
| 28 | * Sets the schema for the items in the array. |
| 29 | * |
| 30 | * @param Schema $schema Schema for the items in the array. |
| 31 | */ |
| 32 | public function items( Schema $schema ): self { |
| 33 | return $this->update_schema_property( 'items', $schema->to_array() ); |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * Sets the minimum number of items in the array. |
| 38 | * |
| 39 | * @param int $value Minimum number of items in the array. |
| 40 | */ |
| 41 | public function minItems( int $value ): self { |
| 42 | return $this->update_schema_property( 'minItems', $value ); |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * Sets the maximum number of items in the array. |
| 47 | * |
| 48 | * @param int $value Maximum number of items in the array. |
| 49 | */ |
| 50 | public function maxItems( int $value ): self { |
| 51 | return $this->update_schema_property( 'maxItems', $value ); |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * Sets the uniqueItems property to true. |
| 56 | */ |
| 57 | public function uniqueItems(): self { |
| 58 | return $this->update_schema_property( 'uniqueItems', true ); |
| 59 | } |
| 60 | } |
| 61 |