technosophos/querypath — pull request #110 by mkalkbrenner (2013-04-10 14:29:43+00:00)
Title: Some safe API changes to run querypath2 and 3 in parallel

First some background information:
For the development of [HVRawConnectorPHP](https://github.com/mkalkbrenner/HVRawConnectorPHP/) I decided to use querypath 3.x.
Therefor the drupal integration module [HealthVault™ Connect](https://drupal.org/project/healthvault_connect) adds querypath3 as library to your drupal installation.
But as soon as you install another contrib module that depends on the [QueryPath](https://drupal.org/project/querypath) module which still contains querypath2, you end up with fatal errors because functions like qp() could not be redeclared.

Unfortunately it's not an option to upgrade the querypath library within the drupal QueryPath module, because (for whatever reason) modules like [Apache Solr Config Generator](https://drupal.org/project/apachesolr_confgen) don't work with querypath3.

But due to the fact that you introduced a \QueryPath namespace in querypath3, it's not a big problem to run querypath2 and 3 in parallel. But you have to avoid the redeclaration of the global functions qp() and htmlqp() and the class QueryPath must not be part of the global namespace.

So I applied these safe API changes to run querypath2 and 3 in parallel:
- renamed qp() to qp3()
- renamed htmlqp() to htmlqp3()
- renamed \QueryPath to \QueryPath\QueryPath

Now I can explicit use querypath3 in my module.

If querypath2 is not present, these changes happen on the fly for backwards compatibility, so that nobody has to change his existing code:
- declare function qp() as wrapper for qp3()
- declare function htmlqp() as wrapper for htmlqp3()
- declare \QueryPath as class alias for \QueryPath\QueryPath

To demonstrate the backwards compatibility I did not touch the tests in my patch.

What do you think about that?

From my point of view, the API change is OK, because querypath 3 is still very new and even the documentation on querypath.org has not been updated yet.

I'm open for a discussion or any other solution to run qp2 and qp3 in parallel.