Skip to content

Commit

Permalink
collection function: extract retreiving a collection function
Browse files Browse the repository at this point in the history
  • Loading branch information
hrach committed May 23, 2020
1 parent 54b4523 commit 7aa81d0
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/Collection/Helpers/DbalQueryBuilderHelper.php
Expand Up @@ -83,10 +83,7 @@ public function processPropertyExpr(QueryBuilder $builder, $expr): DbalExpressio
{
if (is_array($expr)) {
$function = array_shift($expr);
$collectionFunction = $this->repository->getCollectionFunction($function);
if (!$collectionFunction instanceof IQueryBuilderFunction) {
throw new InvalidArgumentException("Collection function $function has to implement " . IQueryBuilderFunction::class . ' interface.');
}
$collectionFunction = $this->getCollectionFunction($function);
return $collectionFunction->processQueryBuilderExpression($this, $builder, $expr);
}

Expand All @@ -101,10 +98,7 @@ public function processPropertyExpr(QueryBuilder $builder, $expr): DbalExpressio
public function processFilterFunction(QueryBuilder $builder, array $expr): DbalExpressionResult
{
$function = isset($expr[0]) ? array_shift($expr) : ICollection::AND;
$collectionFunction = $this->repository->getCollectionFunction($function);
if (!$collectionFunction instanceof IQueryBuilderFunction) {
throw new InvalidArgumentException("Collection function $function has to implement " . IQueryBuilderFunction::class . ' interface.');
}
$collectionFunction = $this->getCollectionFunction($function);
return $collectionFunction->processQueryBuilderExpression($this, $builder, $expr);
}

Expand Down Expand Up @@ -199,6 +193,16 @@ public function normalizeValue($value, PropertyMetadata $propertyMetadata, IConv
}


private function getCollectionFunction(string $name): IQueryBuilderFunction
{
$collectionFunction = $this->repository->getCollectionFunction($name);
if (!$collectionFunction instanceof IQueryBuilderFunction) {
throw new InvalidArgumentException("Collection function $name has to implement " . IQueryBuilderFunction::class . ' interface.');
}
return $collectionFunction;
}


/**
* @param array<string> $tokens
* @param class-string<\Nextras\Orm\Entity\IEntity>|null $sourceEntity
Expand Down

0 comments on commit 7aa81d0

Please sign in to comment.