1 | <?php |
||
21 | class Field implements FieldInterface |
||
22 | { |
||
23 | |||
24 | /** |
||
25 | * @var string |
||
26 | */ |
||
27 | protected $name; |
||
28 | |||
29 | /** |
||
30 | * @var string |
||
31 | */ |
||
32 | protected $label; |
||
33 | |||
34 | /** |
||
35 | * @var RuleInterface[] |
||
36 | */ |
||
37 | protected $rules = []; |
||
38 | |||
39 | /** |
||
40 | * @param string $name |
||
41 | * @param string $friendlyName |
||
42 | */ |
||
43 | 26 | public function __construct($name = null, $friendlyName = null) |
|
48 | |||
49 | /** |
||
50 | * Sets the label of this field |
||
51 | * |
||
52 | * @param string $friendlyName |
||
53 | * |
||
54 | * @return $this |
||
55 | * |
||
56 | * @since 2.0 |
||
57 | */ |
||
58 | 26 | public function setLabel($friendlyName) |
|
64 | |||
65 | /** |
||
66 | * Gets the label of this field |
||
67 | * |
||
68 | * @return string |
||
69 | * |
||
70 | * @since 2.0 |
||
71 | */ |
||
72 | 10 | public function getLabel() |
|
73 | { |
||
74 | 10 | if ($this->label === null) |
|
75 | { |
||
76 | 7 | return $this->getName(); |
|
77 | } |
||
78 | |||
79 | 3 | return $this->label; |
|
80 | } |
||
81 | |||
82 | /** |
||
83 | * Sets the machine name of this field |
||
84 | * |
||
85 | * @param string $name |
||
86 | * |
||
87 | * @return $this |
||
88 | * |
||
89 | * @since 2.0 |
||
90 | */ |
||
91 | 26 | public function setName($name) |
|
97 | |||
98 | /** |
||
99 | * Gets the machine name of this field |
||
100 | * |
||
101 | * @return string |
||
102 | * |
||
103 | * @since 2.0 |
||
104 | */ |
||
105 | 24 | public function getName() |
|
109 | |||
110 | /** |
||
111 | * Sets a rule to validate this field with |
||
112 | * |
||
113 | * @param RuleInterface $rule |
||
114 | * |
||
115 | * @return $this |
||
116 | * |
||
117 | * @since 2.0 |
||
118 | */ |
||
119 | 20 | public function addRule(RuleInterface $rule) |
|
125 | |||
126 | /** |
||
127 | * Returns a list of rules that will be used to validate this field |
||
128 | * |
||
129 | * @return RuleInterface[] |
||
130 | * |
||
131 | * @since 2.0 |
||
132 | */ |
||
133 | 19 | public function getRules() |
|
137 | |||
138 | } |
||
139 |