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

FieldValidation::getIdentifier()   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 field validator
7
 */
8
class FieldValidation implements \JsonSerializable{
9
	/**
10
	 * @var string
11
	 */
12
	protected  $identifier;
13
	/**
14
	 * @var array array of Rules
15
	 */
16
	protected $rules;
17
18
	/**
19
	 * @var string
20
	 */
21
	protected $depends;
22
23
	protected $optional;
24
25
	public function __construct($identifier){
26
		$this->identifier=$identifier;
27
		$this->rules=[];
28
	}
29
30
	public function getIdentifier() {
31
		return $this->identifier;
32
	}
33
34
	public function setIdentifier($identifier) {
35
		$this->identifier=$identifier;
36
		return $this;
37
	}
38
39
	public function getRules() {
40
		return $this->rules;
41
	}
42
43
	public function addRule($type,$prompt=NULL,$value=NULL){
44
		if($type instanceof  Rule)
45
			$this->rules[]=$type;
46
		else
47
			$this->rules[]=new Rule($type,$prompt,$value);
48
	}
49
50
	public function jsonSerialize(){
51
		return ["identifier"=>$this->identifier,"rules"=>$this->rules];
52
	}
53
54
	public function setDepends($depends) {
55
		$this->depends=$depends;
56
		return $this;
57
	}
58
59
	public function setOptional($optional) {
60
		$this->optional=$optional;
61
		return $this;
62
	}
63
64
}