|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace arc\html; |
|
4
|
|
|
|
|
5
|
|
|
class NodeList extends \ArrayObject { |
|
6
|
|
|
use \arc\xml\NodeListTrait { |
|
7
|
|
|
\arc\xml\NodeListTrait::parseArgs as traitParseArgs; |
|
8
|
|
|
} |
|
9
|
|
|
|
|
10
|
2 |
|
protected function canHaveContent( $tagName ) { |
|
11
|
|
|
$cantHaveContent = [ |
|
12
|
2 |
|
'area', 'base', 'basefont', 'br', |
|
13
|
1 |
|
'col', 'frame', 'hr', 'img', 'input', |
|
14
|
1 |
|
'isindex', 'link', 'meta', 'param' |
|
15
|
1 |
|
]; |
|
16
|
2 |
|
return !in_array( trim( strtolower( $tagName ) ), $cantHaveContent ); |
|
17
|
|
|
} |
|
18
|
|
|
|
|
19
|
2 |
|
protected function element( $tagName, $attributes, $content ) { |
|
20
|
2 |
|
$tagName = \arc\html::name( $tagName ); |
|
21
|
2 |
|
$el = '<' . $tagName; |
|
22
|
2 |
|
$el .= $this->getAttributes( $attributes ); |
|
23
|
2 |
|
if ( $this->canHaveContent( $tagName ) ) { |
|
24
|
2 |
|
$el .= '>' . self::indent( $content, $this->writer->indent, $this->writer->newLine ); |
|
25
|
2 |
|
$el .= '</' . $tagName . '>'; |
|
26
|
1 |
|
} else { |
|
27
|
2 |
|
$el .= '>'; |
|
28
|
|
|
} |
|
29
|
2 |
|
return $el; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
2 |
|
protected function getAttributes( $attributes ) |
|
33
|
|
|
{ |
|
34
|
2 |
|
$result = ''; |
|
35
|
2 |
|
if (count( $attributes )) { |
|
36
|
2 |
|
foreach ($attributes as $name => $value ) { |
|
37
|
2 |
|
$result .= \arc\html::attribute( $name, $value ); |
|
38
|
1 |
|
} |
|
39
|
1 |
|
} |
|
40
|
2 |
|
return $result; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
2 |
|
protected function parseArgs( $args ) { |
|
44
|
2 |
|
if ( is_string($args) ) { |
|
45
|
|
|
// allows for <input type="radio" checked> |
|
46
|
|
|
// as \arc\html::input(['type' => 'radio', 'checked']); |
|
47
|
2 |
|
return [ [ $args => $args ], '' ]; |
|
48
|
|
|
} else { |
|
49
|
2 |
|
return $this->traitParseArgs($args); |
|
50
|
|
|
} |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
} |
|
54
|
|
|
|