depage-forms
v2.0.0
html forms made easy
Toggle main menu visibility
Loading...
Searching...
No Matches
Validator.php
Go to the documentation of this file.
1
<?php
2
7
8
namespace
Depage\HtmlForm\Validators;
9
15
class
Validator
16
{
20
protected
$log
;
21
30
public
function
__construct
(
$log
=
null
)
31
{
32
$this->
log
=
$log
;
33
}
34
45
public
static
function
factory
($argument,
$log
=
null
)
46
{
47
if
(!is_string($argument) && is_callable($argument,
false
)) {
48
$closureValidator =
new
Closure
(
$log
);
49
$closureValidator->setFunc($argument);
50
51
return
$closureValidator;
52
} elseif (($argument[0] ===
'/'
) && ($argument[strlen($argument) - 1] ===
'/'
)) {
53
$regExValidator =
new
RegEx
(
$log
);
54
$regExValidator->setRegEx($argument);
55
56
return
$regExValidator;
57
}
else
{
58
$type =
'Depage\\HtmlForm\\Validators\\'
. $argument;
59
60
if
(class_exists($type)) {
61
return
new
$type(
$log
);
62
}
else
{
63
return
new
Validator
(
$log
);
64
}
65
}
66
}
67
77
public
function
validate
($value, $parameters = [])
78
{
79
return
true
;
80
}
81
89
protected
function
log
($argument, $type)
90
{
91
if
(is_callable([$this->
log
,
'log'
])) {
92
$this->
log
->log($argument, $type);
93
}
else
{
94
error_log($argument);
95
}
96
}
97
103
public
function
getPatternAttribute
()
104
{
105
if
(isset($this->regEx)) {
106
return
' pattern="'
. htmlspecialchars(substr($this->regEx, 1, -1), ENT_QUOTES) .
'"'
;
107
}
108
}
109
116
public
static
function
isValid
($input)
117
{
118
$el = \get_called_class();
119
$el =
new
$el();
120
121
return
$el->validate($input);
122
}
123
}
Depage\HtmlForm\Validators\Closure
customizable validator for input elements
Definition
Closure.php:14
Depage\HtmlForm\Validators\RegEx
customizable validator for input elements
Definition
RegEx.php:14
Depage\HtmlForm\Validators\Validator
parent validator class
Definition
Validator.php:16
Depage\HtmlForm\Validators\Validator\isValid
static isValid($input)
Returns a bool value indicating whether or not the input passes the given element's validation criter...
Definition
Validator.php:116
Depage\HtmlForm\Validators\Validator\getPatternAttribute
getPatternAttribute()
returns validators' regular expression as HTML5 pattern attribute
Definition
Validator.php:103
Depage\HtmlForm\Validators\Validator\$log
$log
log object
Definition
Validator.php:20
Depage\HtmlForm\Validators\Validator\validate
validate($value, $parameters=[])
default validator.
Definition
Validator.php:77
Depage\HtmlForm\Validators\Validator\__construct
__construct($log=null)
validator constructor
Definition
Validator.php:30
Depage\HtmlForm\Validators\Validator\factory
static factory($argument, $log=null)
valdiator object factory
Definition
Validator.php:45
Depage\HtmlForm\Validators\Validator\log
log($argument, $type)
error logging method
Definition
Validator.php:89
Validators
Validator.php
Generated on
for depage-forms by
doxygen
1.18.0
For an overview of all docs, go to
docs.depage.net