Total Complexity | 13 |
Total Lines | 74 |
Duplicated Lines | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
15 | class XHtmlElement extends XHtmlSimpleElement |
||
16 | { |
||
17 | public $_text; |
||
18 | public $_htmlcode = ''; |
||
19 | public $_siblings = []; |
||
20 | |||
21 | public function __construct($text = null) |
||
22 | { |
||
23 | parent::__construct(); |
||
24 | |||
25 | if ($text) { |
||
26 | $this->set_text($text); |
||
27 | } |
||
28 | } |
||
29 | |||
30 | /* |
||
31 | * Adds an xhtml child to element |
||
32 | * |
||
33 | * @param XHtmlElement $object The element to become a child of element |
||
34 | */ |
||
35 | public function add(&XHtmlOption $object) |
||
|
|||
36 | { |
||
37 | array_push($this->_siblings, $object); |
||
38 | } |
||
39 | |||
40 | /* |
||
41 | * The CDATA section of Element |
||
42 | * |
||
43 | * @param string $text Text content of the element |
||
44 | */ |
||
45 | public function set_text($text) |
||
46 | { |
||
47 | if ($text) { |
||
48 | $this->_text = htmlspecialchars($text); |
||
49 | } |
||
50 | } |
||
51 | |||
52 | public function fetch() |
||
53 | { |
||
54 | return $this->_html(); |
||
55 | } |
||
56 | |||
57 | public function _html() |
||
58 | { |
||
59 | $this->_htmlcode = "<{$this->_element}"; |
||
60 | foreach ($this->_attributes as $attribute => $value) { |
||
61 | if (!empty($value)) { |
||
62 | $this->_htmlcode .= sprintf(' %s="%s" ', $attribute, $value); |
||
63 | } |
||
64 | } |
||
65 | $this->_htmlcode .= '>'; |
||
66 | |||
67 | if ($this->_text) { |
||
68 | $this->_htmlcode .= $this->_text; |
||
69 | } |
||
70 | |||
71 | foreach ($this->_siblings as $obj) { |
||
72 | $this->_htmlcode .= $obj->fetch(); |
||
73 | } |
||
74 | |||
75 | $this->_htmlcode .= "</{$this->_element}>"; |
||
76 | |||
77 | return $this->_htmlcode; |
||
78 | } |
||
79 | |||
80 | // Returns siblings of Element |
||
81 | public function get_siblings() |
||
82 | { |
||
83 | return $this->_siblings; |
||
84 | } |
||
85 | |||
86 | public function has_siblings() |
||
87 | { |
||
88 | return 0 != count($this->_siblings); |
||
89 | } |
||
91 |