AnyOfSchema.php
4 years ago
ArraySchema.php
4 years ago
BooleanSchema.php
4 years ago
IntegerSchema.php
4 years ago
NullSchema.php
4 years ago
NumberSchema.php
4 years ago
ObjectSchema.php
4 years ago
OneOfSchema.php
4 years ago
StringSchema.php
4 years ago
index.php
3 years ago
ObjectSchema.php
57 lines
| 1 | <?php declare(strict_types = 1); |
| 2 | |
| 3 | namespace MailPoet\Validator\Schema; |
| 4 | |
| 5 | if (!defined('ABSPATH')) exit; |
| 6 | |
| 7 | |
| 8 | use MailPoet\Validator\Schema; |
| 9 | |
| 10 | // See: https://developer.wordpress.org/rest-api/extending-the-rest-api/schema/#objects |
| 11 | class ObjectSchema extends Schema { |
| 12 | protected $schema = [ |
| 13 | 'type' => 'object', |
| 14 | ]; |
| 15 | |
| 16 | /** @param array<string, Schema> $properties */ |
| 17 | public function properties(array $properties): self { |
| 18 | return $this->updateSchemaProperty('properties', array_map( |
| 19 | function (Schema $property) { |
| 20 | return $property->toArray(); |
| 21 | }, |
| 22 | $properties |
| 23 | )); |
| 24 | } |
| 25 | |
| 26 | public function additionalProperties(Schema $schema): self { |
| 27 | return $this->updateSchemaProperty('additionalProperties', $schema->toArray()); |
| 28 | } |
| 29 | |
| 30 | public function disableAdditionalProperties(): self { |
| 31 | return $this->updateSchemaProperty('additionalProperties', false); |
| 32 | } |
| 33 | |
| 34 | /** |
| 35 | * Keys of $properties are regular expressions without leading/trailing delimiters. |
| 36 | * See: https://developer.wordpress.org/rest-api/extending-the-rest-api/schema/#patternproperties |
| 37 | * |
| 38 | * @param array<string, Schema> $properties |
| 39 | */ |
| 40 | public function patternProperties(array $properties): self { |
| 41 | $patternProperties = []; |
| 42 | foreach ($properties as $key => $value) { |
| 43 | $this->validatePattern($key); |
| 44 | $patternProperties[$key] = $value->toArray(); |
| 45 | } |
| 46 | return $this->updateSchemaProperty('patternProperties', $patternProperties); |
| 47 | } |
| 48 | |
| 49 | public function minProperties(int $value): self { |
| 50 | return $this->updateSchemaProperty('minProperties', $value); |
| 51 | } |
| 52 | |
| 53 | public function maxProperties(int $value): self { |
| 54 | return $this->updateSchemaProperty('maxProperties', $value); |
| 55 | } |
| 56 | } |
| 57 |