1 | <?php |
||
37 | class FieldCollection implements IteratorAggregate, JsonSerializable |
||
38 | { |
||
39 | /** |
||
40 | * Fields |
||
41 | * |
||
42 | * @var array |
||
43 | * |
||
44 | * @access protected |
||
45 | */ |
||
46 | protected $fields = []; |
||
47 | |||
48 | /** |
||
49 | * Factory |
||
50 | * |
||
51 | * @var FieldFactory |
||
52 | * |
||
53 | * @access protected |
||
54 | */ |
||
55 | protected $factory; |
||
56 | |||
57 | /** |
||
58 | * Create a collection of fields |
||
59 | * |
||
60 | * @param FieldFactory $factory Field Factory |
||
61 | * |
||
62 | * @access public |
||
63 | */ |
||
64 | 9 | public function __construct(FieldFactory $factory = null) |
|
69 | |||
70 | /** |
||
71 | * Initialize turn-key |
||
72 | * |
||
73 | * @return void |
||
74 | * |
||
75 | * @access protected |
||
76 | */ |
||
77 | 9 | protected function init() |
|
80 | |||
81 | /** |
||
82 | * Get Iterator of fields |
||
83 | * |
||
84 | * @return ArrayIterator |
||
85 | * |
||
86 | * @access public |
||
87 | */ |
||
88 | 1 | public function getIterator() |
|
92 | |||
93 | /** |
||
94 | * Add a field |
||
95 | * |
||
96 | * @param string $name name of field |
||
97 | * @param string $class Field class |
||
98 | * |
||
99 | * @return Field |
||
100 | * |
||
101 | * @throws Exception if field already exists |
||
102 | * |
||
103 | * @access public |
||
104 | */ |
||
105 | 6 | public function add($name, $class = 'Jnjxp\Form\Field') |
|
113 | |||
114 | /** |
||
115 | * Remove a field |
||
116 | * |
||
117 | * @param string $name name of field |
||
118 | * |
||
119 | * @return $this |
||
120 | * |
||
121 | * @access public |
||
122 | */ |
||
123 | 1 | public function remove($name) |
|
130 | |||
131 | /** |
||
132 | * Does the collection have a field? |
||
133 | * |
||
134 | * @param string $name name of the field for which to check |
||
135 | * |
||
136 | * @return bool |
||
137 | * |
||
138 | * @access public |
||
139 | */ |
||
140 | 7 | public function has($name) |
|
144 | |||
145 | /** |
||
146 | * Get a field |
||
147 | * |
||
148 | * @param string $name name of field to get |
||
149 | * |
||
150 | * @return Field |
||
151 | * |
||
152 | * @throws Exception if field does not exist |
||
153 | * |
||
154 | * @access public |
||
155 | */ |
||
156 | 4 | public function get($name) |
|
163 | |||
164 | /** |
||
165 | * Fill fields with values |
||
166 | * |
||
167 | * @param array $values values to fill |
||
168 | * |
||
169 | * @return $this |
||
170 | * |
||
171 | * @access public |
||
172 | */ |
||
173 | 1 | public function fill(array $values) |
|
182 | |||
183 | /** |
||
184 | * Set error messages |
||
185 | * |
||
186 | * @param array $errors error messages |
||
187 | * |
||
188 | * @return $this |
||
189 | * |
||
190 | * @access public |
||
191 | */ |
||
192 | 1 | public function errors(array $errors) |
|
201 | |||
202 | /** |
||
203 | * JsonSerialize |
||
204 | * |
||
205 | * @return array |
||
206 | * |
||
207 | * @access public |
||
208 | */ |
||
209 | public function jsonSerialize() |
||
213 | } |
||
214 |