Ubiquity
2.5.2
php rapid development framework
Loading...
Searching...
No Matches
ValidatorMultiple.php
Go to the documentation of this file.
1
<?php
2
3
namespace
Ubiquity\contents\validation\validators\multiples
;
4
5
use
Ubiquity\contents\validation\validators\Validator
;
6
use
Ubiquity\utils\base\UString
;
7
use
Ubiquity\exceptions\ValidatorException
;
8
use
Ubiquity\contents\validation\validators\HasNotNullInterface
;
9
10
abstract
class
ValidatorMultiple
extends
Validator
implements
HasNotNullInterface
{
11
protected
$violation
;
12
protected
$notNull
;
13
14
public
function
__construct
() {
15
$this->message = [
'notNull'
=>
'This value should not be null'
];
16
$this->notNull =
false
;
17
}
18
19
public
function
validate
(
$value
) {
20
if
(
null
==
$value
) {
21
if
($this->notNull ===
true
) {
22
$this->violation =
'notNull'
;
23
return
false
;
24
}
else
{
25
return
;
26
}
27
}
28
if
(! UString::isValid (
$value
)) {
29
throw
new
ValidatorException
(
'This value can not be converted to string'
);
30
}
31
return
true
;
32
}
33
38
protected
function
mergeMessages
() {
39
if
(! isset ( $this->modifiedMessage )) {
40
return
$this->message
;
41
}
else
{
42
if
(\is_array ( $this->modifiedMessage ) && \is_array ( $this->message )) {
43
return \array_merge ( $this->message, $this->modifiedMessage );
44
}
else
{
45
return
$this->modifiedMessage
;
46
}
47
}
48
}
49
50
protected
function
_getMessage
() {
51
$parameters = $this->
getParameters
();
52
$message
= $this->
mergeMessages
();
53
if
(isset ( $this->violation ) && \is_array (
$message
)) {
54
$message
= $this->
_getMessageViolation
(
$message
);
55
}
56
foreach
( $parameters as $param ) {
57
$message
= \str_replace (
'{'
. $param .
'}'
, $this->$param??
''
,
$message
);
58
}
59
return
$message
;
60
}
61
62
protected
function
_getMessageViolation
($messages) {
63
if
(isset ( $messages [$this->violation] )) {
64
return
$messages [
$this->violation
];
65
}
66
return \current ( $messages );
67
}
68
69
public
function
asUI
(): array {
70
if ($this->notNull) {
71
return
[
'rules'
=> [[
'type'
=>
'empty'
,
'prompt'
=>$this->
mergeMessages
()[
'notNull'
]??
''
]] ];
72
}
73
return
[ ];
74
}
75
}
76
Ubiquity\contents\validation\validators\Validator
Abstract class for validators.
Definition
Validator.php:11
Ubiquity\contents\validation\validators\Validator\getParameters
getParameters()
{}
Definition
Validator.php:65
Ubiquity\contents\validation\validators\Validator\$value
$value
Definition
Validator.php:15
Ubiquity\contents\validation\validators\Validator\$message
$message
Definition
Validator.php:13
Ubiquity\contents\validation\validators\Validator\$modifiedMessage
$modifiedMessage
Definition
Validator.php:12
Ubiquity\contents\validation\validators\multiples\ValidatorMultiple
Definition
ValidatorMultiple.php:10
Ubiquity\contents\validation\validators\multiples\ValidatorMultiple\__construct
__construct()
Definition
ValidatorMultiple.php:14
Ubiquity\contents\validation\validators\multiples\ValidatorMultiple\$notNull
$notNull
Definition
ValidatorMultiple.php:12
Ubiquity\contents\validation\validators\multiples\ValidatorMultiple\validate
validate($value)
Definition
ValidatorMultiple.php:19
Ubiquity\contents\validation\validators\multiples\ValidatorMultiple\mergeMessages
mergeMessages()
Definition
ValidatorMultiple.php:38
Ubiquity\contents\validation\validators\multiples\ValidatorMultiple\$violation
$violation
Definition
ValidatorMultiple.php:11
Ubiquity\contents\validation\validators\multiples\ValidatorMultiple\_getMessage
_getMessage()
Definition
ValidatorMultiple.php:50
Ubiquity\contents\validation\validators\multiples\ValidatorMultiple\asUI
asUI()
Definition
ValidatorMultiple.php:69
Ubiquity\contents\validation\validators\multiples\ValidatorMultiple\_getMessageViolation
_getMessageViolation($messages)
Definition
ValidatorMultiple.php:62
Ubiquity\exceptions\ValidatorException
Validator Exceptions.
Definition
ValidatorException.php:11
Ubiquity\utils\base\UString
String utilities.
Definition
UString.php:15
Ubiquity\contents\validation\validators\HasNotNullInterface
Definition
HasNotNullInterface.php:5
Ubiquity\contents\validation\validators\multiples
Definition
IdValidator.php:3
C:
Users
myadd
Documents
GitHub
ubiquity-doc-api
vendor
phpmv
ubiquity
src
Ubiquity
contents
validation
validators
multiples
ValidatorMultiple.php
Generated on Sun Dec 10 2023 15:04:15 for
Ubiquity
by
doxygen
1.9.8