Exponential 5.x Kernel 7.5.40 Exponential New Stack (Symfony-based) Kernel — PHP Class Reference

IntegerValueValidator.php
Go to the documentation of this file.
1 <?php
2
7 namespace eZ\Publish\Core\FieldType\Validator;
8
9 use eZ\Publish\Core\FieldType\Validator;
10 use eZ\Publish\Core\FieldType\ValidationError;
11 use eZ\Publish\Core\FieldType\Value as BaseValue;
12
19 class IntegerValueValidator extends Validator
20 {
21 protected $constraints = [
22 'minIntegerValue' => null,
23 'maxIntegerValue' => null,
24 ];
25
26 protected $constraintsSchema = [
27 'minIntegerValue' => [
28 'type' => 'int',
29 'default' => 0,
30 ],
31 'maxIntegerValue' => [
32 'type' => 'int',
33 'default' => null,
34 ],
35 ];
36
37 public function validateConstraints($constraints)
38 {
39 $validationErrors = [];
40 foreach ($constraints as $name => $value) {
41 switch ($name) {
42 case 'minIntegerValue':
43 case 'maxIntegerValue':
44 if ($value === false) {
45 @trigger_error(
46 "The IntegerValueValidator constraint value 'false' is deprecated, and will be removed in 7.0. Use 'null' instead.",
47 E_USER_DEPRECATED
48 );
49 $value = null;
50 }
51 if ($value !== null && !is_int($value)) {
52 $validationErrors[] = new ValidationError(
53 "Validator parameter '%parameter%' value must be of integer type",
54 null,
55 [
56 '%parameter%' => $name,
57 ]
58 );
59 }
60 break;
61 default:
62 $validationErrors[] = new ValidationError(
63 "Validator parameter '%parameter%' is unknown",
64 null,
65 [
66 '%parameter%' => $name,
67 ]
68 );
69 }
70 }
71
72 return $validationErrors;
73 }
74
88 public function validate(BaseValue $value)
89 {
90 $isValid = true;
91
92 if ($this->constraints['maxIntegerValue'] !== null && $value->value > $this->constraints['maxIntegerValue']) {
93 $this->errors[] = new ValidationError(
94 'The value can not be higher than %size%.',
95 null,
96 [
97 '%size%' => $this->constraints['maxIntegerValue'],
98 ]
99 );
100 $isValid = false;
101 }
102
103 if ($this->constraints['minIntegerValue'] !== null && $value->value < $this->constraints['minIntegerValue']) {
104 $this->errors[] = new ValidationError(
105 'The value can not be lower than %size%.',
106 null,
107 [
108 '%size%' => $this->constraints['minIntegerValue'],
109 ]
110 );
111 $isValid = false;
112 }
113
114 return $isValid;
115 }
116 }
eZ\Publish\Core\FieldType\ValidationError
Class for validation errors.
Definition: Core/FieldType/ValidationError.php:17
eZ\Publish\Core\FieldType\Validator\IntegerValueValidator
Definition: IntegerValueValidator.php:20
eZ\Publish\Core\FieldType\Validator\IntegerValueValidator\validate
validate(BaseValue $value)
Perform validation on $value.
Definition: IntegerValueValidator.php:88
eZ\Publish\Core\FieldType\Validator\IntegerValueValidator\$constraints
$constraints
Definition: IntegerValueValidator.php:21
eZ\Publish\Core\FieldType\Validator\IntegerValueValidator\validateConstraints
validateConstraints($constraints)
Definition: IntegerValueValidator.php:37
eZ\Publish\Core\FieldType\Validator\IntegerValueValidator\$constraintsSchema
$constraintsSchema
Definition: IntegerValueValidator.php:26
eZ\Publish\Core\FieldType\Validator
Base field type validator validator.
Definition: Validator.php:15
eZ\Publish\Core\FieldType\Value
Abstract class for all field value classes.
Definition: Core/FieldType/Value.php:17
eZ\Publish\Core\FieldType\Validator
Definition: EmailAddressValidator.php:7
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.