|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace ByJG\AnyDataset\Repository; |
|
4
|
|
|
|
|
5
|
|
|
use ByJG\AnyDataset\Exception\DatasetException; |
|
6
|
|
|
use ByJG\Util\XmlUtil; |
|
7
|
|
|
use DOMDocument; |
|
8
|
|
|
use InvalidArgumentException; |
|
9
|
|
|
|
|
10
|
|
|
class XmlDataset |
|
11
|
|
|
{ |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* String |
|
15
|
|
|
* |
|
16
|
|
|
* @var string |
|
17
|
|
|
*/ |
|
18
|
|
|
private $_rowNode = null; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Enter description here... |
|
22
|
|
|
* |
|
23
|
|
|
* @var string[] |
|
24
|
|
|
*/ |
|
25
|
|
|
private $_colNodes = null; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @var DOMDocument |
|
29
|
|
|
*/ |
|
30
|
|
|
private $_domDocument; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* |
|
34
|
|
|
* @var string |
|
35
|
|
|
*/ |
|
36
|
|
|
protected $_registerNS; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* |
|
40
|
|
|
* @param DOMDocument $xml |
|
41
|
|
|
* @param string $rowNode |
|
42
|
|
|
* @param string[] $colNode |
|
43
|
|
|
* @param array $registerNS |
|
44
|
|
|
* @throws DatasetException |
|
45
|
|
|
* @throws InvalidArgumentException |
|
46
|
|
|
*/ |
|
47
|
|
|
public function __construct($xml, $rowNode, $colNode, $registerNS = null) |
|
48
|
|
|
{ |
|
49
|
|
|
if (!is_array($colNode)) { |
|
50
|
|
|
throw new DatasetException("XmlDataset constructor: Column nodes must be an array."); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
if ($xml instanceof DOMDocument) { |
|
54
|
|
|
$this->_domDocument = $xml; |
|
55
|
|
|
} else { |
|
56
|
|
|
$this->_domDocument = XmlUtil::createXmlDocumentFromStr($xml); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
if (is_null($registerNS)) { |
|
60
|
|
|
$registerNS = array(); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
if (!is_array($registerNS)) { |
|
64
|
|
|
throw new InvalidArgumentException('The parameter $registerNS must be an associative array'); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
$this->_registerNS = $registerNS; |
|
|
|
|
|
|
68
|
|
|
$this->_rowNode = $rowNode; |
|
69
|
|
|
$this->_colNodes = $colNode; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* @access public |
|
74
|
|
|
* @return DBIterator |
|
75
|
|
|
*/ |
|
76
|
|
|
public function getIterator() |
|
77
|
|
|
{ |
|
78
|
|
|
$it = new XmlIterator(XmlUtil::selectNodes($this->_domDocument->documentElement, $this->_rowNode, |
|
79
|
|
|
$this->_registerNS), $this->_colNodes, $this->_registerNS); |
|
|
|
|
|
|
80
|
|
|
return $it; |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..