-
Notifications
You must be signed in to change notification settings - Fork 0
/
NodeList.php
executable file
·57 lines (49 loc) · 1.5 KB
/
NodeList.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
/*
* PHP DOM: Implementation of the Document Object Model (DOM) Level 3 Core Specification <http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226> in PHP.
* Jonas Raoni Soares da Silva <http://raoni.org>
* https://github.com/jonasraoni/php-dom
*/
class NodeList {
var $length = 0,
$_nodes = array();
function &item($index){
if(IsSet($this->_nodes[$index])) return $this->_nodes[$index];
return null;
}
function _add(&$item){
if(!inheritsFrom($item,'Node')) return false;
$this->_nodes[$this->length++] = &$item;
return true;
}
function &_addBefore(&$item,&$ref) {
if(!inheritsFrom($ref, 'Node') || !inheritsFrom($item, 'Node')) return null;
if (-1 != $key = $this->_getKey($ref)) {
++$this->length;
Array_Splice($this->_nodes, $key, 0, array(&$item));
return $this->_nodes[$key];
}
return null;
}
function _getKey(&$item){
if(!inheritsFrom($item,'Node')) return -1;
ForEach($this->_nodes As $key=>$node)
If($node->_GUID == $item->_GUID)
return $key;
return -1;
}
function &_remove(&$item){
if(!inheritsFrom($item,'Node')) return null;
if(-1 != $key = $this->_getKey($item)) {
$this->length--;
$removedNode = &Array_Splice($this->_nodes, $key, 1);
return $removedNode[0];
}
return null;
}
function &_merge(&$nodeList){
if(!inheritsFrom($nodeList,'NodeList')) return null;
$this->_nodes=&Array_Merge($this->_nodes, $nodeList->_nodes);
$this->length = $this->length+$nodeList->length;
}
}