1 | <?php |
||
11 | final class Format implements ConstraintInterface |
||
12 | { |
||
13 | const KEYWORD = 'format'; |
||
14 | |||
15 | // @codingStandardsIgnoreStart |
||
16 | // @see https://www.w3.org/TR/2012/REC-xmlschema11-2-20120405/datatypes.html#dateTime-lexical-mapping |
||
17 | const DATE_TIME_PATTERN = '/^-?([1-9][0-9]{3,}|0[0-9]{3})-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])T(([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9](\.[0-9]+)?|(24:00:00(\.0+)?))(Z|(\+|-)((0[0-9]|1[0-3]):[0-5][0-9]|14:00))?$/'; |
||
18 | // @codingStandardsIgnoreEnd |
||
19 | |||
20 | const HOST_NAME_PATTERN = '/^[_a-z]+\.([_a-z]+\.?)+$/i'; |
||
21 | |||
22 | /** |
||
23 | * @var \League\JsonGuard\Constraint\DraftFour\Format\FormatExtensionInterface[] |
||
24 | */ |
||
25 | private $extensions = []; |
||
26 | |||
27 | /** |
||
28 | * Any custom format extensions to use, indexed by the format name. |
||
29 | * |
||
30 | * @param array \League\JsonGuard\Constraint\DraftFour\Format\FormatExtensionInterface[] |
||
31 | */ |
||
32 | 24 | public function __construct(array $extensions = []) |
|
38 | |||
39 | /** |
||
40 | * Add a custom format extension. |
||
41 | * |
||
42 | * @param string $format |
||
43 | * @param \League\JsonGuard\Constraint\DraftFour\Format\FormatExtensionInterface $extension |
||
44 | */ |
||
45 | 4 | public function addExtension($format, FormatExtensionInterface $extension) |
|
49 | |||
50 | /** |
||
51 | * {@inheritdoc} |
||
52 | */ |
||
53 | 24 | public function validate($value, $parameter, Validator $validator) |
|
104 | |||
105 | /** |
||
106 | * @param mixed $value |
||
107 | * @param string $pattern |
||
108 | * @param \League\JsonGuard\Validator $validator |
||
109 | * |
||
110 | * @return \League\JsonGuard\ValidationError|null |
||
111 | * |
||
112 | */ |
||
113 | 14 | private static function validateRegex($value, $pattern, Validator $validator) |
|
121 | |||
122 | /** |
||
123 | * @param mixed $value |
||
124 | * @param int $filter |
||
125 | * @param mixed $options |
||
126 | * @param \League\JsonGuard\Validator $validator |
||
127 | * |
||
128 | * @return \League\JsonGuard\ValidationError|null |
||
129 | * |
||
130 | */ |
||
131 | 6 | private static function validateFilter($value, $filter, $options, Validator $validator) |
|
147 | } |
||
148 |