Completed
Push — master ( 67c338...c7b167 )
by Wanderson
04:24
created

Select::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
dl 0
loc 4
rs 10
c 1
b 0
f 1
cc 1
eloc 3
nc 1
nop 2
1
<?php
2
3
/**
4
 * Select
5
 * Auxilia nas <select>
6
 * @author WebCorpore
7
 */
8
9
namespace Win\Html\Form;
10
11
class Select {
12
13
	private $options = [];
14
	private $currentValue;
15
16
	/**
17
	 * Cria o select com os <option>'s
18
	 * @param string[] $options array com titulo dos options
19
	 * @param string $currentValue option que será selecionado
20
	 */
21
	public function __construct($options = [], $currentValue = '') {
22
		$this->options = $options;
23
		$this->currentValue = $currentValue;
24
	}
25
26
	/**
27
	 * Exibe os <option>'s do select
28
	 * @return string
29
	 */
30
	public function __toString() {
31
		$html = '';
32
		foreach ($this->options as $option):
33
			$html .= '<option value="' . $option . '" ' . static::active($option, $this->currentValue) . '>' . $option . '</option>';
34
		endforeach;
35
		return $html;
36
	}
37
38
	/**
39
	 * Retorna selected="true" se os valores são iguais
40
	 * @param mixed $value1
41
	 * @param mixed $value2
42
	 */
43
	public static function active($value1, $value2 = true) {
44
		if ($value1 == $value2) {
45
			return 'selected="true"';
46
		}
47
	}
48
49
}
50