class-any-of-schema.php
11 months ago
class-array-schema.php
11 months ago
class-boolean-schema.php
11 months ago
class-integer-schema.php
11 months ago
class-null-schema.php
11 months ago
class-number-schema.php
11 months ago
class-object-schema.php
11 months ago
class-one-of-schema.php
11 months ago
class-string-schema.php
11 months ago
index.php
11 months ago
class-object-schema.php
42 lines
| 1 | <?php |
| 2 | declare( strict_types = 1 ); |
| 3 | namespace Automattic\WooCommerce\EmailEditor\Validator\Schema; |
| 4 | if (!defined('ABSPATH')) exit; |
| 5 | use Automattic\WooCommerce\EmailEditor\Validator\Schema; |
| 6 | class Object_Schema extends Schema { |
| 7 | protected $schema = array( |
| 8 | 'type' => 'object', |
| 9 | ); |
| 10 | public function properties( array $properties ): self { |
| 11 | return $this->update_schema_property( |
| 12 | 'properties', |
| 13 | array_map( |
| 14 | function ( Schema $property ) { |
| 15 | return $property->to_array(); |
| 16 | }, |
| 17 | $properties |
| 18 | ) |
| 19 | ); |
| 20 | } |
| 21 | public function additionalProperties( Schema $schema ): self { |
| 22 | return $this->update_schema_property( 'additionalProperties', $schema->to_array() ); |
| 23 | } |
| 24 | public function disableAdditionalProperties(): self { |
| 25 | return $this->update_schema_property( 'additionalProperties', false ); |
| 26 | } |
| 27 | public function patternProperties( array $properties ): self { |
| 28 | $pattern_properties = array(); |
| 29 | foreach ( $properties as $key => $value ) { |
| 30 | $this->validate_pattern( $key ); |
| 31 | $pattern_properties[ $key ] = $value->to_array(); |
| 32 | } |
| 33 | return $this->update_schema_property( 'patternProperties', $pattern_properties ); |
| 34 | } |
| 35 | public function minProperties( int $value ): self { |
| 36 | return $this->update_schema_property( 'minProperties', $value ); |
| 37 | } |
| 38 | public function maxProperties( int $value ): self { |
| 39 | return $this->update_schema_property( 'maxProperties', $value ); |
| 40 | } |
| 41 | } |
| 42 |