Ubiquity
2.5.2
php rapid development framework
Loading...
Searching...
No Matches
TypeValidator.php
Go to the documentation of this file.
1
<?php
2
3
namespace
Ubiquity\contents\validation\validators\basic
;
4
5
use
Ubiquity\contents\validation\validators\ValidatorHasNotNull
;
6
7
class
TypeValidator
extends
ValidatorHasNotNull
{
8
protected
$ref
;
9
10
public
function
__construct
() {
11
$this->message =
"The value {value} is not a valid {ref}."
;
12
}
13
14
public
function
validate
(
$value
) {
15
parent::validate (
$value
);
16
if
($this->notNull !==
false
) {
17
$type = strtolower ( $this->ref );
18
$type =
'boolean'
== $type ?
'bool'
: $type;
19
$isFunction =
'is_'
. $type;
20
$ctypeFunction =
'ctype_'
. $type;
21
if
(\function_exists ( $isFunction ) && $isFunction (
$value
)) {
22
return
true
;
23
} elseif (\function_exists ( $ctypeFunction ) && $ctypeFunction (
$value
)) {
24
return
true
;
25
} elseif (
$value
instanceof $this->ref) {
26
return
true
;
27
}
28
return
false
;
29
}
30
return
true
;
31
}
32
38
public
function
getParameters
(): array {
39
return [
"ref"
,
"value"
];
40
}
41
}
42
Ubiquity\contents\validation\validators\ValidatorHasNotNull
Definition
ValidatorHasNotNull.php:8
Ubiquity\contents\validation\validators\Validator\$value
$value
Definition
Validator.php:15
Ubiquity\contents\validation\validators\basic\TypeValidator
Definition
TypeValidator.php:7
Ubiquity\contents\validation\validators\basic\TypeValidator\getParameters
getParameters()
{{}\Ubiquity\contents\validation\validators\ValidatorInterfacegetParameters()}
Definition
TypeValidator.php:38
Ubiquity\contents\validation\validators\basic\TypeValidator\__construct
__construct()
Definition
TypeValidator.php:10
Ubiquity\contents\validation\validators\basic\TypeValidator\validate
validate($value)
Definition
TypeValidator.php:14
Ubiquity\contents\validation\validators\basic\TypeValidator\$ref
$ref
Definition
TypeValidator.php:8
Ubiquity\contents\validation\validators\basic
Basic validators.
Definition
IsBooleanValidator.php:6
C:
Users
myadd
Documents
GitHub
ubiquity-doc-api
vendor
phpmv
ubiquity
src
Ubiquity
contents
validation
validators
basic
TypeValidator.php
Generated on Sun Dec 10 2023 15:04:14 for
Ubiquity
by
doxygen
1.9.8