@@ 8-29 (lines=22) @@ | ||
5 | use League\JsonGuard; |
|
6 | use League\JsonGuard\ValidationError; |
|
7 | ||
8 | class MaxLength implements PropertyConstraint |
|
9 | { |
|
10 | const KEYWORD = 'maxLength'; |
|
11 | ||
12 | /** |
|
13 | * {@inheritdoc} |
|
14 | */ |
|
15 | public static function validate($value, $parameter, $pointer = null) |
|
16 | { |
|
17 | if (!is_string($value) || JsonGuard\strlen($value) <= $parameter) { |
|
18 | return null; |
|
19 | } |
|
20 | ||
21 | return new ValidationError( |
|
22 | 'String is not at most {max_length} characters long', |
|
23 | self::KEYWORD, |
|
24 | $value, |
|
25 | $pointer, |
|
26 | ['max_length' => $parameter] |
|
27 | ); |
|
28 | } |
|
29 | } |
|
30 |
@@ 8-29 (lines=22) @@ | ||
5 | use League\JsonGuard; |
|
6 | use League\JsonGuard\ValidationError; |
|
7 | ||
8 | class MaxProperties implements PropertyConstraint |
|
9 | { |
|
10 | const KEYWORD = 'maxProperties'; |
|
11 | ||
12 | /** |
|
13 | * {@inheritdoc} |
|
14 | */ |
|
15 | public static function validate($value, $parameter, $pointer = null) |
|
16 | { |
|
17 | if (!is_object($value) || count(get_object_vars($value)) <= $parameter) { |
|
18 | return null; |
|
19 | } |
|
20 | ||
21 | return new ValidationError( |
|
22 | 'Object does not contain less than {max_properties} properties', |
|
23 | self::KEYWORD, |
|
24 | $value, |
|
25 | $pointer, |
|
26 | ['max_properties' => $parameter] |
|
27 | ); |
|
28 | } |
|
29 | } |
|
30 |
@@ 8-29 (lines=22) @@ | ||
5 | use League\JsonGuard; |
|
6 | use League\JsonGuard\ValidationError; |
|
7 | ||
8 | class MinLength implements PropertyConstraint |
|
9 | { |
|
10 | const KEYWORD = 'minLength'; |
|
11 | ||
12 | /** |
|
13 | * {@inheritdoc} |
|
14 | */ |
|
15 | public static function validate($value, $parameter, $pointer = null) |
|
16 | { |
|
17 | if (!is_string($value) || JsonGuard\strlen($value) >= $parameter) { |
|
18 | return null; |
|
19 | } |
|
20 | ||
21 | return new ValidationError( |
|
22 | 'String is not at least {min_length} characters long', |
|
23 | self::KEYWORD, |
|
24 | $value, |
|
25 | $pointer, |
|
26 | ['min_length' => $parameter] |
|
27 | ); |
|
28 | } |
|
29 | } |
|
30 |
@@ 8-29 (lines=22) @@ | ||
5 | use League\JsonGuard; |
|
6 | use League\JsonGuard\ValidationError; |
|
7 | ||
8 | class MinProperties implements PropertyConstraint |
|
9 | { |
|
10 | const KEYWORD = 'minProperties'; |
|
11 | ||
12 | /** |
|
13 | * {@inheritdoc} |
|
14 | */ |
|
15 | public static function validate($value, $min, $pointer = null) |
|
16 | { |
|
17 | if (!is_object($value) || count(get_object_vars($value)) >= $min) { |
|
18 | return null; |
|
19 | } |
|
20 | ||
21 | return new ValidationError( |
|
22 | 'Object does not contain at least {min_properties} properties', |
|
23 | self::KEYWORD, |
|
24 | $value, |
|
25 | $pointer, |
|
26 | ['min_properties' => $min] |
|
27 | ); |
|
28 | } |
|
29 | } |
|
30 |