Ubiquity 2.5.2
php rapid development framework
Loading...
Searching...
No Matches
Validator.php
Go to the documentation of this file.
1<?php
2
4
7use Ubiquity\utils\base\UArray;
8use Attribute;
9
23#[Attribute(Attribute::TARGET_PROPERTY | Attribute::IS_REPEATABLE)]
25
26 public string $type;
27 public ?string $message;
28 public ?string $severity;
29 public ?string $group;
30 public ?array $constraints;
31
41 public function __construct(string $type, null|string|array $constraints = ['ref' => false], ?string $message = null, ?string $severity = null, ?string $group = null) {
42 if (!isset (ValidatorsManager::$validatorTypes [$type])) {
43 throw new \Exception ('This type does not exists : ' . $type);
44 }
45 $this->type = $type;
46 $this->message = $message;
47 $this->severity = $severity;
48 $this->group = $group;
49 if ($constraints && !\is_array($constraints)) {
50 $this->constraints['ref'] = $constraints;
51 } else {
52 $this->constraints = $constraints;
53 }
54 }
55
56 public function asAnnotation(): string {
57 $fields = $this->getPropertiesAndValues();
58 $result = [];
59 $result [] = $fields ["type"];
60 unset ($fields ["type"]);
61 if (isset ($fields ["constraints"]) && isset ($fields ["constraints"] ["ref"])) {
62 $result [] = $fields ["constraints"] ["ref"];
63 unset ($fields ["constraints"] ["ref"]);
64 }
65 if (sizeof($fields) > 0) {
66 foreach ($fields as $field => $value) {
67 if ((is_array($value) && sizeof($value) > 0) || !is_array($value)) {
68 $result [$field] = $value;
69 }
70 }
71 }
72 return UArray::asPhpArray($result);
73 }
74}
Ubiquity\annotations$BaseAnnotationTrait This class is part of Ubiquity.
Ubiquity\attributes$BaseAttribute This class is part of Ubiquity.
__construct(string $type, null|string|array $constraints=['ref'=> false], ?string $message=null, ?string $severity=null, ?string $group=null)
Validator constructor.
Definition Validator.php:41