/**
  * Modifies the QueryBuilder according to the passed Specification.
  * Will also set the condition for this query if needed.
  *
  * @param QueryBuilder           $queryBuilder
  * @param SpecificationInterface $specification
  *
  * @internal param string $dqlAlias
  */
 private function modifyQueryBuilder(QueryBuilder $queryBuilder, SpecificationInterface $specification)
 {
     $condition = $specification->modify($queryBuilder, $this->dqlAlias);
     if (empty($condition)) {
         return;
     }
     $queryBuilder->where($condition);
 }
 /**
  * Get the query after matching with given specification.
  *
  * @param SpecificationInterface $specification
  * @param ModifierInterface      $resultModifier
  *
  * @throws LogicException
  *
  * @return Query
  */
 public function match(SpecificationInterface $specification, ModifierInterface $resultModifier = null)
 {
     if (!$specification->isSatisfiedBy($this->getEntityName())) {
         throw new LogicException(sprintf('Specification "%s" not supported by this repository!', get_class($specification)));
     }
     $dqlAlias = $this->dqlAlias;
     $queryBuilder = $this->createQueryBuilder($dqlAlias);
     $condition = $specification->modify($queryBuilder, $dqlAlias);
     if (!empty($condition)) {
         $queryBuilder->where($condition);
     }
     $query = $queryBuilder->getQuery();
     if ($resultModifier) {
         $resultModifier->modify($query);
     }
     return $query;
 }
Example #3
0
 /**
  * {@inheritdoc}
  */
 public function isSatisfiedBy($value)
 {
     return $this->parent->isSatisfiedBy($value);
 }
 public function modify(QueryBuilder $queryBuilder, $dqlAlias)
 {
     call_user_func_array([$queryBuilder, $this->type], [$this->specification->modify($queryBuilder, $dqlAlias)]);
 }