for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
* This file is part of the Happyr Doctrine Specification package.
*
* (c) Tobias Nyholm <[email protected]>
* Kacper Gunia <[email protected]>
* Peter Gribanov <[email protected]>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Happyr\DoctrineSpecification\Query;
use Doctrine\ORM\Query\QueryException;
use Doctrine\ORM\QueryBuilder;
use Happyr\DoctrineSpecification\Operand\Field;
* Class IndexBy.
class IndexBy implements QueryModifier
{
* @var Field
private $field;
* @var string|null
private $dqlAlias;
* @param Field|string $field Field name for indexing
* @param string|null $dqlAlias DQL alias of field
public function __construct($field, $dqlAlias = null)
if (!($field instanceof Field)) {
$field = new Field($field);
}
$this->field = $field;
$this->dqlAlias = $dqlAlias;
* @param QueryBuilder $qb
* @param string $dqlAlias
* @throws QueryException
public function modify(QueryBuilder $qb, $dqlAlias)
if (null !== $this->dqlAlias) {
$dqlAlias = $this->dqlAlias;
// doctrine/orm < 2.5
if (!method_exists($qb, 'indexBy')) {
throw new \RuntimeException('IndexBy query modifier require doctrine/orm >= 2.5');
$qb->indexBy($dqlAlias, $this->field->transform($qb, $dqlAlias));