Completed
Push — master ( 141d55...411df4 )
by Jean-Christophe
02:55
created

Rule::getType()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
namespace Ajax\semantic\components\validation;
3
/**
4
 * @author jc
5
 * @version 1.001
6
 * Generates a JSON Rule for the validation of a field
7
 */
8
class Rule implements \JsonSerializable{
9
	/**
10
	 * @var string
11
	 */
12
	private $type;
13
	/**
14
	 * @var string
15
	 */
16
	private $prompt;
17
18
	/**
19
	 * @var string
20
	 */
21
	private $value;
22
23
	public function __construct($type,$prompt=NULL,$value=NULL){
24
		$this->type=$type;
25
		$this->prompt=$prompt;
26
		$this->value=$value;
27
	}
28
29
	public function getType() {
30
		return $this->type;
31
	}
32
33
	public function setType($type) {
34
		$this->type=$type;
35
		return $this;
36
	}
37
38
	public function getPrompt() {
39
		return $this->prompt;
40
	}
41
42
	public function setPrompt($prompt) {
43
		$this->prompt=$prompt;
44
		return $this;
45
	}
46
47
	public function getValue() {
48
		return $this->value;
49
	}
50
51
	public function setValue($value) {
52
		$this->value=$value;
53
		return $this;
54
	}
55
56
	public function jsonSerialize() {
57
		$result= ["type"=>$this->type];
58
		if(isset($this->prompt))
59
			$result["prompt"]=$this->prompt;
60
		if(isset($this->value))
61
			$result["value"]=$this->value;
62
		return $result;
63
	}
64
65
	public static function match($name,$prompt=null){
66
		return new Rule("match[".$name."]",$prompt);
67
	}
68
69
	public static function integer($min=0,$max=100,$prompt=null){
70
		return new Rule("integer[{$min}..{$max}]",$prompt);
71
	}
72
73
	public static function decimal($prompt=null){
74
		return new Rule("decimal]",$prompt);
75
	}
76
77
	public static function number($prompt=null){
78
		return new Rule("number",$prompt);
79
	}
80
81
}