Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
element.php
1
<?php
2
namespace
Bitrix\Main\Web\DOM
;
3
4
class
Element
extends
Node
5
{
9
protected
$parentElement
;
13
protected
$attributes
;
17
protected
$tagName
;
21
protected
$classList
;
25
protected
$id
;
29
protected
$name
;
33
protected
$className
;
37
protected
$style
;
38
39
40
public
function
__construct
($name)
41
{
42
$this->
init
();
43
44
$this->nodeType = self::ELEMENT_NODE;
45
$this->nodeName = mb_strtoupper(
$name
);
46
$this->tagName = $this->nodeName;
47
48
if
(self::$isNodeListAsArray)
49
{
50
$this->attributes = array();
51
}
52
else
53
{
54
$this->attributes =
new
NamedNodeMap
;
55
}
56
}
57
58
public
function
getTagName
()
59
{
60
return
$this->tagName;
61
}
62
63
public
function
getId
()
64
{
65
return
$this->
getAttribute
(
'id'
);
66
}
67
68
public
function
setId
($id)
69
{
70
$this->
setAttribute
(
'id'
,
$id
);
71
}
72
73
public
function
getName
()
74
{
75
return
$this->
getAttribute
(
'name'
);
76
}
77
78
public
function
setName
($id)
79
{
80
$this->
setAttribute
(
'name'
,
$id
);
81
}
82
83
public
function
getStyle
()
84
{
85
return
$this->
getAttribute
(
'style'
);
86
}
87
88
public
function
setStyle
($style)
89
{
90
$this->
setAttribute
(
'style'
,
$style
);
91
}
92
93
public
function
getClassName
()
94
{
95
return
$this->
getAttribute
(
'class'
);
96
}
97
98
public
function
setClassName
($className)
99
{
100
$this->
setAttribute
(
'class'
,
$className
);
101
}
102
103
public
function
getClassList
()
104
{
105
return
explode(
' '
, $this->
getClassName
());
106
}
107
108
public
function
setClassList
(array $classList)
109
{
110
$this->
setAttribute
(
'class'
, implode(
' '
, $classList));
111
}
112
113
public
function
getParentElement
()
114
{
115
return
$this->parentElement;
116
}
117
118
public
function
getTextContent
()
119
{
120
$content =
''
;
121
foreach
($this->
getChildNodesArray
() as $child)
122
{
123
if
($child->getNodeType() === self::COMMENT_NODE || $child->getNodeType() === self::PROCESSING_INSTRUCTION_NODE )
124
{
125
continue
;
126
}
127
128
$content .= $child->getTextContent();
129
}
130
131
return
$content;
132
}
133
134
protected
function
setParentElement
(
Element
$parentElement)
135
{
136
$this->parentElement = $parentElement;
137
}
138
139
public
function
getAttributesArray
()
140
{
141
if
(self::$isNodeListAsArray)
142
{
143
return
$this->attributes;
144
}
145
else
146
{
147
return
$this->attributes->get();
148
}
149
}
150
151
public
function
setAttributeNode
(
Attr
$attr)
152
{
153
if
(self::$isNodeListAsArray)
154
{
155
$name
= $attr->
getName
();
156
$this->attributes[
$name
] = $attr;
157
}
158
else
159
{
160
$this->
getAttributes
()->setNamedItem($attr);
161
}
162
163
$attr->
setParentNode
($this);
164
}
165
166
public
function
getAttributeNode
($name)
167
{
168
$result =
null
;
169
if
($this->
hasAttributes
())
170
{
171
if
(self::$isNodeListAsArray)
172
{
173
$result = $this->attributes[
$name
] ??
null
;
174
}
175
else
176
{
177
$result = $this->attributes->getNamedItem(
$name
);
178
}
179
}
180
181
return
$result;
182
}
183
184
public
function
removeAttributeNode
(
Attr
$oldNode)
185
{
186
if
($this->attributes)
187
{
188
if
(self::$isNodeListAsArray)
189
{
190
$name
= $oldNode->
getName
();
191
unset($this->attributes[
$name
]);
192
}
193
else
194
{
195
$this->attributes->removeNamedItem($oldNode->
getName
());
196
}
197
198
$oldNode->
setParentNode
(
null
);
199
}
200
}
201
202
public
function
setAttribute
($name, $value)
203
{
204
$attr = $this->
getAttributeNode
(
$name
);
205
if
(!$attr)
206
{
207
$attr = $this->ownerDocument->createAttribute(
$name
, $value);
208
}
209
else
210
{
211
$attr->setValue($value);
212
}
213
214
$this->
setAttributeNode
($attr);
215
}
216
221
public
function
hasAttribute
($attributeName)
222
{
223
$result =
false
;
224
if
($this->
hasAttributes
())
225
{
226
if
(self::$isNodeListAsArray)
227
{
228
$result = array_key_exists($attributeName, $this->attributes);
229
}
230
else
231
{
232
$result = !is_null($this->attributes->getNamedItem($attributeName));
233
}
234
}
235
return
$result;
236
}
237
238
public
function
getAttribute
($name)
239
{
240
$attr = $this->
getAttributeNode
(
$name
);
241
if
($attr)
242
{
243
return
$attr->getValue();
244
}
245
246
return
null
;
247
}
248
249
public
function
removeAttribute
($name)
250
{
251
$attr = $this->
getAttributeNode
(
$name
);
252
if
($attr)
253
{
254
$this->
removeAttributeNode
($attr);
255
}
256
}
257
}
Bitrix\Main\Web\DOM\Attr
Definition
attr.php:5
Bitrix\Main\Web\DOM\Attr\getName
getName()
Definition
attr.php:28
Bitrix\Main\Web\DOM\Element
Definition
element.php:5
Bitrix\Main\Web\DOM\Element\setAttributeNode
setAttributeNode(Attr $attr)
Definition
element.php:151
Bitrix\Main\Web\DOM\Element\setStyle
setStyle($style)
Definition
element.php:88
Bitrix\Main\Web\DOM\Element\$className
$className
Definition
element.php:33
Bitrix\Main\Web\DOM\Element\hasAttribute
hasAttribute($attributeName)
Definition
element.php:221
Bitrix\Main\Web\DOM\Element\getId
getId()
Definition
element.php:63
Bitrix\Main\Web\DOM\Element\getStyle
getStyle()
Definition
element.php:83
Bitrix\Main\Web\DOM\Element\setClassList
setClassList(array $classList)
Definition
element.php:108
Bitrix\Main\Web\DOM\Element\getTagName
getTagName()
Definition
element.php:58
Bitrix\Main\Web\DOM\Element\getName
getName()
Definition
element.php:73
Bitrix\Main\Web\DOM\Element\$id
$id
Definition
element.php:25
Bitrix\Main\Web\DOM\Element\__construct
__construct($name)
Definition
element.php:40
Bitrix\Main\Web\DOM\Element\getParentElement
getParentElement()
Definition
element.php:113
Bitrix\Main\Web\DOM\Element\setAttribute
setAttribute($name, $value)
Definition
element.php:202
Bitrix\Main\Web\DOM\Element\$name
$name
Definition
element.php:29
Bitrix\Main\Web\DOM\Element\removeAttributeNode
removeAttributeNode(Attr $oldNode)
Definition
element.php:184
Bitrix\Main\Web\DOM\Element\getAttributeNode
getAttributeNode($name)
Definition
element.php:166
Bitrix\Main\Web\DOM\Element\$style
$style
Definition
element.php:37
Bitrix\Main\Web\DOM\Element\getAttributesArray
getAttributesArray()
Definition
element.php:139
Bitrix\Main\Web\DOM\Element\getClassList
getClassList()
Definition
element.php:103
Bitrix\Main\Web\DOM\Element\$classList
$classList
Definition
element.php:21
Bitrix\Main\Web\DOM\Element\setId
setId($id)
Definition
element.php:68
Bitrix\Main\Web\DOM\Element\setClassName
setClassName($className)
Definition
element.php:98
Bitrix\Main\Web\DOM\Element\$attributes
$attributes
Definition
element.php:13
Bitrix\Main\Web\DOM\Element\$parentElement
$parentElement
Definition
element.php:9
Bitrix\Main\Web\DOM\Element\getClassName
getClassName()
Definition
element.php:93
Bitrix\Main\Web\DOM\Element\removeAttribute
removeAttribute($name)
Definition
element.php:249
Bitrix\Main\Web\DOM\Element\setParentElement
setParentElement(Element $parentElement)
Definition
element.php:134
Bitrix\Main\Web\DOM\Element\getAttribute
getAttribute($name)
Definition
element.php:238
Bitrix\Main\Web\DOM\Element\setName
setName($id)
Definition
element.php:78
Bitrix\Main\Web\DOM\Element\getTextContent
getTextContent()
Definition
element.php:118
Bitrix\Main\Web\DOM\Element\$tagName
$tagName
Definition
element.php:17
Bitrix\Main\Web\DOM\NamedNodeMap
Definition
namednodemap.php:41
Bitrix\Main\Web\DOM\Node
Definition
node.php:5
Bitrix\Main\Web\DOM\Node\hasAttributes
hasAttributes()
Definition
node.php:84
Bitrix\Main\Web\DOM\Node\init
init()
Definition
node.php:57
Bitrix\Main\Web\DOM\Node\setParentNode
setParentNode(Node $node=null)
Definition
node.php:79
Bitrix\Main\Web\DOM\Node\getChildNodesArray
getChildNodesArray()
Definition
node.php:211
Bitrix\Main\Web\DOM\Node\getAttributes
getAttributes()
Definition
node.php:101
Bitrix\Main\Web\DOM
Definition
attr.php:2
modules
main
lib
web
dom
element.php
Создано системой
1.10.0