zendframework/zf2 — pull request #5356 by ThomasCantonnet (2013-10-26 10:07:40+00:00)
Title: Deprecate Zend\Dom\Query in favor of more logical OO approach

Hello everyone,

I am quite a heavy user of DOMDocument XPath queries and I have always been bothered by the Dom implementation in ZF2. The Zend\Dom\Query class seems very illogical as an object and contains quite a lot of inefficiencies and lacks access to the used DOMDocument generated from a string.

I refactored the class into a Zend\Dom\Document which makes more sense, because we are querying this object and not the other way around (creating a Query object that generates a DOMDocument which we then query and that we can't even access).

Old behavior:

$query = new Query($html);
$query->execute('a'); // Generation of a DOMDocument
$query->execute('span'); // Generation of another DOMDocument from the same input string
$query->getDOMDocument(): // Impossible

New behavior:

$document = new Document($html);
$document->queryCss('a');
$document->queryXpath('//span');
$dom = $document->getDomDocument();
$dom->createTextNode('');

Problems solved:
* Addition of a method to get the created DOMDocument instance
* Caching of generated DOMDocument on each query
* More logical object (Document VS Query)

The methods more or less stay the same, I reused the tests already available for Query and added some for the new behavior. I deprecated Zend\Dom\Query in favor of this new class.