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
11abstract class Validator implements ValidatorInterface {
13 protected $message;
14 protected $member;
15 protected $value;
16 protected $severity;
17
23 public function validate_($value) {
24 $this->value = $value;
25 if (! $this->validate ( $value )) {
26 return new ConstraintViolation ( $this->_getMessage (), $value, $this->member, \get_class ( $this ), $this->severity );
27 }
28 return true;
29 }
30
31 public function setValidationParameters($member, $params, $severity = 'warning', $message = null) {
32 $this->setParams ( $params );
33 $this->member = $member;
34 $this->modifiedMessage = $message;
35 $this->severity = $severity;
36 }
37
38 protected function setParams(array $params) {
39 foreach ( $params as $member => $value ) {
40 $this->$member = $value;
41 }
42 }
43
48 public function getMember() {
49 return $this->member;
50 }
51
56 public function setMember($member) {
57 $this->member = $member;
58 }
59
65 public function getParameters(): array {
66 return [ ];
67 }
68
73 protected function mergeMessages() {
74 if (! isset ( $this->modifiedMessage )) {
75 return $this->message;
76 } else {
77 return $this->modifiedMessage;
78 }
79 }
80
81 protected function _getMessage() {
82 $parameters = $this->getParameters ();
83 $message = $this->mergeMessages ();
84 foreach ( $parameters as $param ) {
85 $message = \str_replace ( "{" . $param . "}", $this->$param??'', $message );
86 }
87 return $message;
88 }
89
90 public function asUI(): array {
91 return [ ];
92 }
93}
94
Constraint Violation Generated During Validation with the ValidatorsManager.
setValidationParameters($member, $params, $severity='warning', $message=null)
Definition Validator.php:31