doctrine/phpcr-odm — pull request #318 by dantleech (2013-08-13 16:56:29+00:00)
Title: [WIP] Query Builder V2

| Q | A
| ------------- | ---
| Bug fix? | no
| New feature? | yes
| BC breaks? | yes
| Deprecations? | no
| Tests pass? | no
| Fixed tickets | N/A
| License | MIT
| Doc PR | --

This is still very early but I feel I am on more solid ground with the QB architecture now.

The the query builder will just be an object graph with no references to PHPCR, this object graph will be transformed into a PHPCR query later somehow.

The QueryBuilder is Node based, and each node defines a cardinality map, which says, for example, that there must be 0..* Columns, or 1..1 Wheres. This provides good runtime validation and error reporting.

Following rough example from : https://github.com/symfony-cmf/symfony-cmf/wiki/Query-Builder-v2

````php
$qb->select()
->column('foobar', null, 'a')
->column('barfoo', null, 'a');
$qb->from()
->join()
->left()->document('Doctrine\Fqn\Foobar', 'a')
->right()->document('Doctrine\Fqn\Foobar', 'b')
->condition()->equi('a', 'foobar', 'b', 'barfoo');
$qb->where()
->and()
->descendantNode('/foobar')
->equals()
->nodeLocalName('a')
->bindVariable('test_bar');
$qb->orderBy()
->ascending()->propertyValue('foobar', 'a')
->descending()->nodeLocalName('a');
$q = $qb->getQuery();
$q->setParameter('test_bar');
$q->execute();
````

@lsmith has some other ideas, but my main aim at the moment is building something like the above as it will cover all use cases, then adding bonus features later.