Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
namednodemap.php
1
<?php
2
namespace
Bitrix\Main\Web\DOM
;
3
4
/*
5
class NamedNodeMap extends NodeList
6
{
7
public function getNamedItem($name)
8
{
9
for($index = 0; $index < $this->count(); $index++)
10
{
11
if($this->item($index)->getName() === $name)
12
{
13
return $this->item($index);
14
}
15
}
16
17
return null;
18
}
19
20
public function setNamedItem(Node $node)
21
{
22
$this->offsetSet(null, $node);
23
}
24
25
public function removeNamedItem($name)
26
{
27
for($index = 0; $index < $this->count(); $index++)
28
{
29
if($this->item($index)->getName() === $name)
30
{
31
$this->offsetUnset($index);
32
}
33
}
34
35
$this->rewind();
36
}
37
}
38
*/
39
40
class
NamedNodeMap
extends
NodeList
41
{
42
protected
$names
= array();
43
protected
$nameByPosition
= array();
44
protected
$positionByName
= array();
45
46
public
function
set
(array
$values
)
47
{
48
$this->nameByPosition = array();
49
$this->positionByName = array();
50
51
parent::set(
$values
);
52
}
53
54
public
function
get
()
55
{
56
return
$this->values
;
57
}
58
59
public
function
key
()
60
{
61
return
$this->nameByPosition[
$this->position
];
62
}
63
64
public
function
getNamedItem
($name)
65
{
66
if
(!isset($this->positionByName[$name]))
67
{
68
return
null
;
69
}
70
71
return
$this->
item
($this->positionByName[$name]);
72
}
73
74
/*
75
* Adds a node using its nodeName attribute.
76
* If a node with that name is already present in this map, it is replaced by the new one.
77
* Replacing a node by itself has no effect.
78
* As the nodeName attribute is used to derive the name which the node must be stored under,
79
* multiple nodes of certain types (those that have a "special" string value) cannot be stored as the names would clash.
80
* This is seen as preferable to allowing nodes to be aliased.
81
*/
82
public
function
setNamedItem
(
Attr
$node)
83
{
84
$result =
null
;
85
$name = $node->
getName
();
86
if
(isset($this->positionByName[$name]))
87
{
88
$position
= $this->positionByName[$name];
89
$result = $this->
item
(
$position
);
90
}
91
else
92
{
93
$position
= $this->
getLength
();
94
}
95
96
$this->values[
$position
] = $node;
97
$this->nameByPosition[
$position
] = $name;
98
$this->positionByName[$name] =
$position
;
99
100
$this->length = count($this->values);
101
102
return
$result;
103
}
104
105
/*
106
* Removes a node specified by name.
107
* When this map contains the attributes attached to an element,
108
* if the removed attribute is known to have a default value,
109
* an attribute immediately appears containing the default value as well
110
* as the corresponding namespace URI, local name, and prefix when applicable.
111
*/
112
public
function
removeNamedItem
($name)
113
{
114
$item = $this->
getNamedItem
($name);
115
if
($item)
116
{
117
$position
= $this->positionByName[$name];
118
unset($this->values[
$position
]);
119
unset($this->nameByPosition[
$position
]);
120
unset($this->positionByName[$name]);
121
$this->length = count($this->values);
122
123
return
$item;
124
}
125
else
126
{
127
throw
new \Bitrix\Main\Web\DOM\DomException(
''
, \
Bitrix
\Main\Web\DOM\
DomException::NOT_FOUND_ERR
);
128
}
129
}
130
}
Bitrix\Main\Web\DOM\Attr
Definition
attr.php:5
Bitrix\Main\Web\DOM\Attr\getName
getName()
Definition
attr.php:28
Bitrix\Main\Web\DOM\DomException\NOT_FOUND_ERR
const NOT_FOUND_ERR
Definition
domexception.php:13
Bitrix\Main\Web\DOM\NamedNodeMap
Definition
namednodemap.php:41
Bitrix\Main\Web\DOM\NamedNodeMap\setNamedItem
setNamedItem(Attr $node)
Definition
namednodemap.php:82
Bitrix\Main\Web\DOM\NamedNodeMap\getNamedItem
getNamedItem($name)
Definition
namednodemap.php:64
Bitrix\Main\Web\DOM\NamedNodeMap\$nameByPosition
$nameByPosition
Definition
namednodemap.php:43
Bitrix\Main\Web\DOM\NamedNodeMap\key
key()
Definition
namednodemap.php:59
Bitrix\Main\Web\DOM\NamedNodeMap\removeNamedItem
removeNamedItem($name)
Definition
namednodemap.php:112
Bitrix\Main\Web\DOM\NamedNodeMap\$positionByName
$positionByName
Definition
namednodemap.php:44
Bitrix\Main\Web\DOM\NamedNodeMap\$names
$names
Definition
namednodemap.php:42
Bitrix\Main\Web\DOM\NodeList
Definition
nodelist.php:39
Bitrix\Main\Web\DOM\NodeList\$position
$position
Definition
nodelist.php:41
Bitrix\Main\Web\DOM\NodeList\getLength
getLength()
Definition
nodelist.php:53
Bitrix\Main\Web\DOM\NodeList\item
item($index)
Definition
nodelist.php:61
Bitrix\Main\Web\DOM\NodeList\$values
$values
Definition
nodelist.php:42
Bitrix\Main\Web\DOM
Definition
attr.php:2
Bitrix
modules
main
lib
web
dom
namednodemap.php
Создано системой
1.10.0