Skip to content
This repository was archived by the owner on Oct 2, 2019. It is now read-only.

Commit f97605a

Browse files
committed
draft code for issue 504
needs tests
1 parent 8fc9980 commit f97605a

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

library/Zend/Dom/Query.php

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,14 @@ class Zend_Dom_Query
4848
/**#@+
4949
* Document types
5050
*/
51+
const DOC_DOM = 'docDom';
5152
const DOC_XML = 'docXml';
5253
const DOC_HTML = 'docHtml';
5354
const DOC_XHTML = 'docXhtml';
5455
/**#@-*/
5556

5657
/**
57-
* @var string
58+
* @var string|DOMDocument
5859
*/
5960
protected $_document;
6061

@@ -85,7 +86,7 @@ class Zend_Dom_Query
8586
/**
8687
* Constructor
8788
*
88-
* @param null|string $document
89+
* @param null|string|DOMDocument $document
8990
* @param null|string $encoding
9091
*/
9192
public function __construct($document = null, $encoding = null)
@@ -119,12 +120,15 @@ public function getEncoding()
119120
/**
120121
* Set document to query
121122
*
122-
* @param string $document
123+
* @param string|DOMDocument $document
123124
* @param null|string $encoding Document encoding
124125
* @return Zend_Dom_Query
125126
*/
126127
public function setDocument($document, $encoding = null)
127128
{
129+
if ($document instanceof DOMDocument) {
130+
return $this->setDocumentDom($document);
131+
}
128132
if (0 === strlen($document)) {
129133
return $this;
130134
}
@@ -142,6 +146,17 @@ public function setDocument($document, $encoding = null)
142146
return $this->setDocumentHtml($document, $encoding);
143147
}
144148

149+
/**
150+
* @param DOMDocument $document
151+
* @param string $encoding
152+
*/
153+
public function setDocumentDom(DOMDocument $document)
154+
{
155+
$this->_document = $document;
156+
$this->_docType = self::DOC_DOM;
157+
return $this;
158+
}
159+
145160
/**
146161
* Register HTML document
147162
*
@@ -259,6 +274,9 @@ public function queryXpath($xpathQuery, $query = null)
259274
}
260275
$type = $this->getDocumentType();
261276
switch ($type) {
277+
case self::DOC_DOM:
278+
$domDoc = $this->_document;
279+
break;
262280
case self::DOC_XML:
263281
try {
264282
$domDoc = Zend_Xml_Security::scan($document, $domDoc);

0 commit comments

Comments
 (0)