1 | <?php |
||
11 | final class Format implements ConstraintInterface |
||
12 | { |
||
13 | const KEYWORD = 'format'; |
||
14 | |||
15 | /** |
||
16 | * @see https://tools.ietf.org/html/rfc3339#section-5.6 |
||
17 | */ |
||
18 | const DATE_TIME_PATTERN = |
||
19 | '/^(?<fullyear>\d{4})-(?<month>0[1-9]|1[0-2])-(?<mday>0[1-9]|[12][0-9]|3[01])' . 'T' . |
||
20 | '(?<hour>[01][0-9]|2[0-3]):(?<minute>[0-5][0-9]):(?<second>[0-5][0-9]|60)(?<secfrac>\.[0-9]+)?' . |
||
21 | '(Z|(\+|-)(?<offset_hour>[01][0-9]|2[0-3]):(?<offset_minute>[0-5][0-9]))$/i'; |
||
22 | |||
23 | /** |
||
24 | * @internal |
||
25 | */ |
||
26 | const HOST_NAME_PATTERN = '/^[_a-z]+\.([_a-z]+\.?)+$/i'; |
||
27 | |||
28 | /** |
||
29 | * @var \League\JsonGuard\Constraint\DraftFour\Format\FormatExtensionInterface[] |
||
30 | */ |
||
31 | private $extensions = []; |
||
32 | |||
33 | /** |
||
34 | * Any custom format extensions to use, indexed by the format name. |
||
35 | * |
||
36 | * @param array \League\JsonGuard\Constraint\DraftFour\Format\FormatExtensionInterface[] |
||
37 | */ |
||
38 | 42 | public function __construct(array $extensions = []) |
|
44 | |||
45 | /** |
||
46 | * Add a custom format extension. |
||
47 | * |
||
48 | * @param string $format |
||
49 | * @param \League\JsonGuard\Constraint\DraftFour\Format\FormatExtensionInterface $extension |
||
50 | */ |
||
51 | 4 | public function addExtension($format, FormatExtensionInterface $extension) |
|
55 | |||
56 | /** |
||
57 | * {@inheritdoc} |
||
58 | */ |
||
59 | 42 | public function validate($value, $parameter, Validator $validator) |
|
110 | |||
111 | /** |
||
112 | * @param mixed $value |
||
113 | * @param string $pattern |
||
114 | * @param \League\JsonGuard\Validator $validator |
||
115 | * |
||
116 | * @return \League\JsonGuard\ValidationError|null |
||
117 | * |
||
118 | */ |
||
119 | 32 | private static function validateRegex($value, $pattern, Validator $validator) |
|
127 | |||
128 | /** |
||
129 | * @param mixed $value |
||
130 | * @param int $filter |
||
131 | * @param mixed $options |
||
132 | * @param \League\JsonGuard\Validator $validator |
||
133 | * |
||
134 | * @return \League\JsonGuard\ValidationError|null |
||
135 | * |
||
136 | */ |
||
137 | 6 | private static function validateFilter($value, $filter, $options, Validator $validator) |
|
153 | } |
||
154 |