-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rule.php
87 lines (75 loc) · 2.04 KB
/
Rule.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
/*
* Rule for validating a piece of data
*/
namespace Validator;
class Rule {
private $validator;
private $message;
private $required;
private $options;
/**
* Initialize a new Rule for the AbstractValidator to parse
* @param type $validator String
* @param type $message String
* @param type $required Boolean
* @param type $options Array
*/
public function __construct($validator, $message='', $options=array()) {
$this->validator = $validator;
$this->message = $message;
$this->options = $options;
}
/**
* Adds an option to this rule as a key value pair. Options are passed to the AbstractValidator as needed.
* @param type $key String
* @param type $val Object
*/
public function addOption($key, $val) {
$this->options[$key] = $val;
}
/**
* Return an option or false if option is not found.
* @param type $key
* @return boolean
*/
public function getOption($key) {
if (isset($this->options[$key])) {
return $this->options[$key];
}
return false;
}
/**
* Return the options for this Rule
* @return type Array
*/
public function getOptions() {
return $this->options;
}
/**
* Return the Validator name of this Rule
* @return type String
*/
public function getValidator() {
return trim($this->validator);
}
/**
* Return the message for this Rule
* @return type String
*/
public function getMessage() {
return $this->message;
}
/**
* Return true if this Rule is required, false otherwise
* @return type
*/
public function isRequired() {
if(isset($this->options['required'])) {
return filter_var($this->options['required'], FILTER_VALIDATE_BOOLEAN);
}else{
return false;
}
}
}
?>