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

Validator.php
Go to the documentation of this file.
1 <?php
2
7 namespace eZ\Publish\Core\FieldType;
8
9 use eZ\Publish\API\Repository\Exceptions\PropertyNotFoundException as PropertyNotFound;
10
14 abstract class Validator
15 {
21 protected $errors = [];
22
44 protected $constraints = [];
45
51 protected $constraintsSchema = [];
52
76 public function getConstraintsSchema()
77 {
78 return $this->constraintsSchema;
79 }
80
86 abstract public function validateConstraints($constraints);
87
101 abstract public function validate(Value $value);
102
110 public function getMessage()
111 {
112 return $this->errors;
113 }
114
124 public function initializeWithConstraints(array $constraints)
125 {
126 // Reset errors
127 $this->errors = [];
128 // Set existing constraint values to false
129 foreach ($this->constraints as $constraint => $value) {
130 $this->constraints[$constraint] = false;
131 }
132 // Initialize constraints with new values
133 foreach ($constraints as $constraint => $value) {
134 if (!isset($this->constraints[$constraint])) {
135 throw new PropertyNotFound("The constraint '{$constraint}' is not valid for this validator.");
136 }
137
138 $this->constraints[$constraint] = $value;
139 }
140 }
141
152 public function __get($name)
153 {
154 if (!isset($this->constraints[$name])) {
155 throw new PropertyNotFound("The constraint '{$name}' is not valid for this validator.");
156 }
157
158 return $this->constraints[$name];
159 }
160
170 public function __set($name, $value)
171 {
172 if (!array_key_exists($name, $this->constraints)) {
173 throw new PropertyNotFound("The constraint '{$name}' is not valid for this validator.");
174 }
175
176 $this->constraints[$name] = $value;
177 }
178 }
eZ\Publish\API\Repository\Exceptions\PropertyNotFoundException
This Exception is thrown if an accessed property in a value object was not found.
Definition: PropertyNotFoundException.php:15
eZ\Publish\Core\FieldType\Validator
Base field type validator validator.
Definition: Validator.php:15
eZ\Publish\Core\FieldType\Validator\getConstraintsSchema
getConstraintsSchema()
Returns a schema for supported validator configurations.
Definition: Validator.php:76
eZ\Publish\Core\FieldType\Validator\__set
__set($name, $value)
Magic setter.
Definition: Validator.php:170
eZ\Publish\Core\FieldType\Validator\$constraintsSchema
$constraintsSchema
Definition: Validator.php:51
eZ\Publish\Core\FieldType\Validator\validate
validate(Value $value)
Perform validation on $value.
eZ\Publish\Core\FieldType\Validator\initializeWithConstraints
initializeWithConstraints(array $constraints)
Initialized an instance of Validator, with earlier configured constraints.
Definition: Validator.php:124
eZ\Publish\Core\FieldType\Validator\__get
__get($name)
Magic getter.
Definition: Validator.php:152
eZ\Publish\Core\FieldType\Validator\$errors
$errors
Definition: Validator.php:21
eZ\Publish\Core\FieldType\Validator\$constraints
$constraints
Definition: Validator.php:44
eZ\Publish\Core\FieldType\Validator\getMessage
getMessage()
Returns array of messages on performed validations.
Definition: Validator.php:110
eZ\Publish\Core\FieldType\Validator\validateConstraints
validateConstraints($constraints)
eZ\Publish\Core\FieldType\Value
Abstract class for all field value classes.
Definition: Core/FieldType/Value.php:17
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.