Conditions | 7 |
Paths | 24 |
Total Lines | 28 |
Code Lines | 18 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
9 | public function select(array $data, array $attributes = [], array $options = []) |
||
10 | { |
||
11 | $dom = new SmartDOMDocument(); |
||
12 | if (!isset($options['selected'])) { |
||
13 | $options['selected'] = null; |
||
14 | } |
||
15 | $select = $dom->createElement('select'); |
||
16 | foreach ($attributes as $key => $val) { |
||
17 | if (is_callable($val)) { |
||
18 | if (isset($options[$val])) { //arguments |
||
19 | $select->setAttribute($key, call_user_func($val, $options[$val])); |
||
20 | continue; //break here |
||
21 | } |
||
22 | } |
||
23 | // otherwise call default actions |
||
24 | $select->setAttribute($key, $val); |
||
25 | } |
||
26 | foreach ($data as $opt) { |
||
27 | $option = $dom->createElement('option', $opt); |
||
28 | $option->setAttribute('value', $opt); |
||
29 | if ($options['selected'] == $opt) { |
||
30 | $option->setAttribute('selected', 'selected'); |
||
31 | } |
||
32 | $select->appendChild($option); |
||
33 | } |
||
34 | $dom->appendChild($select); |
||
35 | |||
36 | return $dom->saveHTML(); |
||
37 | } |
||
39 |