Ubiquity
2.5.2
php rapid development framework
Loading...
Searching...
No Matches
Validator.php
Go to the documentation of this file.
1
<?php
2
3
namespace
Ubiquity\attributes\items
;
4
5
use
Ubiquity\annotations\BaseAnnotationTrait
;
6
use
Ubiquity\contents\validation\ValidatorsManager
;
7
use Ubiquity\utils\base\UArray;
8
use Attribute;
9
23
#[Attribute(Attribute::TARGET_PROPERTY | Attribute::IS_REPEATABLE)]
24
class
Validator
extends
BaseAttribute
,
BaseAnnotationTrait
{
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
Ubiquity\annotations$BaseAnnotationTrait This class is part of Ubiquity.
Definition
BaseAnnotationTrait.php:13
Ubiquity\annotations\BaseAnnotationTrait\getPropertiesAndValues
getPropertiesAndValues($props=NULL)
Definition
BaseAnnotationTrait.php:22
Ubiquity\attributes\items\BaseAttribute
Ubiquity\attributes$BaseAttribute This class is part of Ubiquity.
Definition
BaseAttribute.php:15
Ubiquity\attributes\items\Validator
Definition
Validator.php:24
Ubiquity\attributes\items\Validator\$message
string $message
Definition
Validator.php:27
Ubiquity\attributes\items\Validator\$constraints
array $constraints
Definition
Validator.php:30
Ubiquity\attributes\items\Validator\asAnnotation
asAnnotation()
Definition
Validator.php:56
Ubiquity\attributes\items\Validator\__construct
__construct(string $type, null|string|array $constraints=['ref'=> false], ?string $message=null, ?string $severity=null, ?string $group=null)
Validator constructor.
Definition
Validator.php:41
Ubiquity\attributes\items\Validator\$group
string $group
Definition
Validator.php:29
Ubiquity\attributes\items\Validator\$type
string $type
Definition
Validator.php:26
Ubiquity\attributes\items\Validator\$severity
string $severity
Definition
Validator.php:28
Ubiquity\contents\validation\ValidatorsManager
Validators manager.
Definition
ValidatorsManager.php:45
Ubiquity\attributes\items
C:
Users
myadd
Documents
GitHub
ubiquity-doc-api
vendor
phpmv
ubiquity-attributes
src
Ubiquity
attributes
items
Validator.php
Generated on Sun Dec 10 2023 15:04:16 for
Ubiquity
by
doxygen
1.9.8