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
StringSchema.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/#strings |
| 11 | class StringSchema extends Schema { |
| 12 | protected $schema = [ |
| 13 | 'type' => 'string', |
| 14 | ]; |
| 15 | |
| 16 | public function minLength(int $value): self { |
| 17 | return $this->updateSchemaProperty('minLength', $value); |
| 18 | } |
| 19 | |
| 20 | public function maxLength(int $value): self { |
| 21 | return $this->updateSchemaProperty('maxLength', $value); |
| 22 | } |
| 23 | |
| 24 | /** |
| 25 | * Parameter $pattern is a regular expression without leading/trailing delimiters. |
| 26 | * See: https://developer.wordpress.org/rest-api/extending-the-rest-api/schema/#pattern |
| 27 | */ |
| 28 | public function pattern(string $pattern): self { |
| 29 | $this->validatePattern($pattern); |
| 30 | return $this->updateSchemaProperty('pattern', $pattern); |
| 31 | } |
| 32 | |
| 33 | public function formatDateTime(): self { |
| 34 | return $this->updateSchemaProperty('format', 'date-time'); |
| 35 | } |
| 36 | |
| 37 | public function formatEmail(): self { |
| 38 | return $this->updateSchemaProperty('format', 'email'); |
| 39 | } |
| 40 | |
| 41 | public function formatHexColor(): self { |
| 42 | return $this->updateSchemaProperty('format', 'hex-color'); |
| 43 | } |
| 44 | |
| 45 | public function formatIp(): self { |
| 46 | return $this->updateSchemaProperty('format', 'ip'); |
| 47 | } |
| 48 | |
| 49 | public function formatUri(): self { |
| 50 | return $this->updateSchemaProperty('format', 'uri'); |
| 51 | } |
| 52 | |
| 53 | public function formatUuid(): self { |
| 54 | return $this->updateSchemaProperty('format', 'uuid'); |
| 55 | } |
| 56 | } |
| 57 |