|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of the Telegraph package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Arthur Edamov <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
* |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
declare(strict_types = 1); |
|
14
|
|
|
|
|
15
|
|
|
namespace Telegraph; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Class PageList |
|
19
|
|
|
* |
|
20
|
|
|
* This object represents a DOM element node. |
|
21
|
|
|
* |
|
22
|
|
|
* @package Telegraph |
|
23
|
|
|
*/ |
|
24
|
|
|
class NodeElement |
|
25
|
|
|
{ |
|
26
|
|
|
/** |
|
27
|
|
|
* Name of the DOM element. |
|
28
|
|
|
* Available tags: a, aside, b, blockquote, br, code, em, |
|
29
|
|
|
* figcaption, figure, h3, h4, hr, i, |
|
30
|
|
|
* iframe, img, li, ol, p, pre, s, strong, |
|
31
|
|
|
* u, ul, video. |
|
32
|
|
|
* |
|
33
|
|
|
* @var string |
|
34
|
|
|
*/ |
|
35
|
|
|
private $tag; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Attributes of the DOM element. |
|
39
|
|
|
* Key of object represents name of attribute, value represents value of attribute. |
|
40
|
|
|
* Available attributes: href, src. |
|
41
|
|
|
* |
|
42
|
|
|
* @var array |
|
43
|
|
|
*/ |
|
44
|
|
|
private $attrs; |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* List of child nodes for the DOM element. |
|
48
|
|
|
* |
|
49
|
|
|
* @var array |
|
50
|
|
|
*/ |
|
51
|
|
|
private $children; |
|
52
|
|
|
|
|
53
|
|
|
public function __construct(string $tag, array $attrs = [], array $children = []) |
|
54
|
|
|
{ |
|
55
|
|
|
$this->tag = $tag; |
|
56
|
|
|
$this->attrs = $attrs; |
|
57
|
|
|
$this->children = $children; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @return string |
|
62
|
|
|
*/ |
|
63
|
|
|
public function getTag(): string |
|
64
|
|
|
{ |
|
65
|
|
|
return $this->tag; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* @return array |
|
70
|
|
|
*/ |
|
71
|
|
|
public function getAttrs(): array |
|
72
|
|
|
{ |
|
73
|
|
|
return $this->attrs; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* @return array |
|
78
|
|
|
*/ |
|
79
|
|
|
public function getChildren(): array |
|
80
|
|
|
{ |
|
81
|
|
|
return $this->children; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
public function toArray() |
|
85
|
|
|
{ |
|
86
|
|
|
return [ |
|
87
|
|
|
'tag' => $this->getTag(), |
|
88
|
|
|
'attrs' => $this->getAttrs(), |
|
89
|
|
|
'children' => $this->getChildren(), |
|
90
|
|
|
]; |
|
91
|
|
|
} |
|
92
|
|
|
} |
|
93
|
|
|
|