"an essential part of the Drupal and PHP communities"
Extending the QueryPath class
By Matt Butcher ~ Posted Thu, 07/23/2009 - 23:27
In QueryPath 2.0, the QueryPath class is no longer marked final. You can now extend QueryPath itself.
<?php
class MyQueryPath extends QueryPath {
// Your new stuff goes here.
}
?>Not only that, but the QueryPath factory function, qp(), can now use your custom class:
<?php
qp($doc, $selector, array('QueryPath_class' => 'MyQueryPath')); // Returns an instance of MyQueryPath.
?>A better way to do the above, though, is to use the QueryPathOptions class to set a global QueryPath implementation:
<?php
QueryPathOptions::merge(array('QueryPath_class' => 'MyQueryPath'));
qp($doc, $selector); // Returns an instance of MyQueryPath.
qp(); // Also returns an instance of MyQueryPath.
?>This is all true as of QueryPath 2.0 beta 2.

