1 | <?php |
||
12 | final class Format implements ConstraintInterface |
||
13 | { |
||
14 | const KEYWORD = 'format'; |
||
15 | |||
16 | /** |
||
17 | * @see https://tools.ietf.org/html/rfc3339#section-5.6 |
||
18 | */ |
||
19 | const DATE_TIME_PATTERN = |
||
20 | '/^(?<fullyear>\d{4})-(?<month>0[1-9]|1[0-2])-(?<mday>0[1-9]|[12][0-9]|3[01])' . 'T' . |
||
21 | '(?<hour>[01][0-9]|2[0-3]):(?<minute>[0-5][0-9]):(?<second>[0-5][0-9]|60)(?<secfrac>\.[0-9]+)?' . |
||
22 | '(Z|(\+|-)(?<offset_hour>[01][0-9]|2[0-3]):(?<offset_minute>[0-5][0-9]))$/i'; |
||
23 | |||
24 | /** |
||
25 | * @internal |
||
26 | */ |
||
27 | const HOST_NAME_PATTERN = '/^[_a-z]+\.([_a-z]+\.?)+$/i'; |
||
28 | |||
29 | /** |
||
30 | * @var string[] |
||
31 | */ |
||
32 | private $knownformats = ['date-time', 'uri', 'email', 'ipv4', 'ipv6','hostname']; |
||
33 | |||
34 | /** |
||
35 | * @var \League\JsonGuard\Constraint\DraftFour\Format\FormatExtensionInterface[] |
||
36 | */ |
||
37 | private $extensions = []; |
||
38 | 42 | ||
39 | /** |
||
40 | 42 | * @var boolean |
|
41 | */ |
||
42 | 21 | private $ignoreUnknownFormats = true; |
|
43 | 42 | ||
44 | /** |
||
45 | * Any custom format extensions to use, indexed by the format name. |
||
46 | * |
||
47 | * @param array \League\JsonGuard\Constraint\DraftFour\Format\FormatExtensionInterface[] |
||
48 | */ |
||
49 | public function __construct(array $extensions = [], bool $ignoreUnknownFormats = true) |
||
57 | |||
58 | /** |
||
59 | 42 | * Add a custom format extension. |
|
60 | * |
||
61 | 42 | * @param string $format |
|
62 | * @param \League\JsonGuard\Constraint\DraftFour\Format\FormatExtensionInterface $extension |
||
63 | 40 | */ |
|
64 | 4 | public function addExtension($format, FormatExtensionInterface $extension) |
|
68 | 36 | ||
69 | 32 | /** |
|
70 | 32 | * Define if unknown formats shall be ignored |
|
71 | 32 | * |
|
72 | 16 | * @param bool |
|
73 | 16 | */ |
|
74 | 6 | public function setIgnoreUnknownFormats(bool $ignoreUnknownFormats) |
|
78 | 4 | ||
79 | 2 | /** |
|
80 | 2 | * {@inheritdoc} |
|
81 | 4 | */ |
|
82 | 4 | public function validate($value, $parameter, Validator $validator) |
|
138 | |||
139 | 6 | /** |
|
140 | 6 | * @param mixed $value |
|
141 | * @param string $pattern |
||
142 | * @param \League\JsonGuard\Validator $validator |
||
143 | * |
||
144 | * @return \League\JsonGuard\ValidationError|null |
||
145 | 2 | * |
|
146 | 2 | */ |
|
147 | 2 | private static function validateRegex($value, $pattern, Validator $validator) |
|
155 | |||
156 | /** |
||
157 | * @param mixed $value |
||
158 | * @param int $filter |
||
159 | * @param mixed $options |
||
160 | * @param \League\JsonGuard\Validator $validator |
||
161 | * |
||
162 | * @return \League\JsonGuard\ValidationError|null |
||
163 | * |
||
164 | */ |
||
165 | private static function validateFilter($value, $filter, $options, Validator $validator) |
||
181 | } |
||
182 |