-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLabel.php
54 lines (43 loc) · 1.36 KB
/
Label.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
namespace Onimla\HTML;
#require_once 'Element.class.php';
/**
* @method string|FALSE|self for(string $value = FALSE)
*/
class Label extends Element {
public function __construct($for = FALSE, $text = FALSE) {
parent::__construct('label');
$this->selfClose(FALSE);
$this->attrFor($for);
$this->text($text);
}
public function __call($name, $arguments) {
if ($name == 'for') {
return call_user_func_array(array($this, 'attrFor'), $arguments);
}
# Coloca o nome no começo do array
array_unshift($arguments, $name);
return call_user_func_array(array($this, 'attr'), $arguments);
}
public function attrFor($value = FALSE) {
if ($value === FALSE) {
return $this->attr('for');
}
if (is_object($value) AND method_exists($value, 'id')) {
if (strlen($value->id()) < 1) {
if (method_exists($value, 'uniqid')) {
$value->uniqid();
} else {
$value->id(uniqid());
}
}
$this->attr('for', $value->id(), 'safe');
} else {
$this->attr('for', $value, 'safe');
}
return $this;
}
public function path() {
return parent::path() . "[{$this->getAttribute('for')}]";
}
}