Validator.php
Go to the documentation of this file.
1<?php
8
15 {
19 protected $log;
20
29 public function __construct($log = null)
30 {
31 $this->log = $log;
32 }
33
44 public static function factory($argument, $log = null)
45 {
46 if (!is_string($argument) && is_callable($argument, false)) {
47 $closureValidator = new Closure($log);
48 $closureValidator->setFunc($argument);
49
50 return $closureValidator;
51 } elseif (($argument[0] === '/') && ($argument[strlen($argument)-1] === '/')) {
52 $regExValidator = new RegEx($log);
53 $regExValidator->setRegEx($argument);
54
55 return $regExValidator;
56 } else {
57 $type = 'Depage\\HtmlForm\\Validators\\' . $argument;
58
59 if (class_exists($type)) {
60 return new $type($log);
61 } else {
62 return new Validator($log);
63 }
64 }
65 }
66
76 public function validate($value, $parameters = array())
77 {
78 return true;
79 }
80
88 protected function log($argument, $type)
89 {
90 if (is_callable(array($this->log, 'log'))) {
91 $this->log->log($argument, $type);
92 } else {
93 error_log($argument);
94 }
95 }
96
102 public function getPatternAttribute()
103 {
104 if (isset($this->regEx)) {
105 return ' pattern="' . htmlspecialchars(substr($this->regEx, 1,-1), ENT_QUOTES) . '"';
106 }
107 }
108
115 public static function isValid($input)
116 {
117 $el = \get_called_class();
118 $el = new $el();
119
120 return $el->validate($input);
121 }
122}
customizable validator for input elements
Definition Closure.php:12
customizable validator for input elements
Definition RegEx.php:12
static isValid($input)
Returns a bool value indicating whether or not the input passes the given element's validation criter...
getPatternAttribute()
returns validators' regular expression as HTML5 pattern attribute
__construct($log=null)
validator constructor
Definition Validator.php:29
static factory($argument, $log=null)
valdiator object factory
Definition Validator.php:44
log($argument, $type)
error logging method
Definition Validator.php:88
validate($value, $parameters=array())
default validator.
Definition Validator.php:76
Validators for HTML input-elements.