Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Commit

Permalink
ZF-9881: Allow registration of XPath namespaces in Zend_Test_PHPUnit_…
Browse files Browse the repository at this point in the history
…ControllerTestCase, Zend_Test_PHPUnit_Constraint_DomQuery, and Zend_Dom_Query

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@22291 44c647ce-9c0f-0410-b52a-842ac1e357ba
  • Loading branch information
bradley.holt committed May 25, 2010
1 parent 9cb733f commit 49e4d7c
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ class Zend_Dom_Query
*/
protected $_docType;

/**
* XPath namespaces
* @var array
*/
protected $_xpathNamespaces = array();

/**
* Constructor
*
Expand Down Expand Up @@ -220,6 +226,17 @@ public function queryXpath($xpathQuery, $query = null)
return new Zend_Dom_Query_Result($query, $xpathQuery, $domDoc, $nodeList);
}

/**
* Register XPath namespaces
*
* @param array $xpathNamespaces
* @return void
*/
public function registerXpathNamespaces($xpathNamespaces)
{
$this->_xpathNamespaces = $xpathNamespaces;
}

/**
* Prepare node list
*
Expand All @@ -230,6 +247,9 @@ public function queryXpath($xpathQuery, $query = null)
protected function _getNodeList($document, $xpathQuery)
{
$xpath = new DOMXPath($document);
foreach ($this->_xpathNamespaces as $prefix => $namespaceUri) {
$xpath->registerNamespace($prefix, $namespaceUri);
}
$xpathQuery = (string) $xpathQuery;
if (preg_match_all('|\[contains\((@[a-z0-9_-]+),\s?\' |i', $xpathQuery, $matches)) {
foreach ($matches[1] as $attribute) {
Expand Down

0 comments on commit 49e4d7c

Please sign in to comment.