-
-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #545 from nextras/joins-part1
Joins refactoring - part 1
- Loading branch information
Showing
11 changed files
with
245 additions
and
186 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace Nextras\Orm\Collection\Functions; | ||
|
||
|
||
use Nextras\Dbal\QueryBuilder\QueryBuilder; | ||
use Nextras\Orm\Collection\Helpers\DbalExpressionResult; | ||
use Nextras\Orm\Collection\Helpers\DbalQueryBuilderHelper; | ||
use Nextras\Orm\Collection\Helpers\IDbalAggregator; | ||
|
||
|
||
/** | ||
* @internal | ||
*/ | ||
trait JunctionFunctionTrait | ||
{ | ||
/** | ||
* Normalizes directly entered column => value expression to expression array. | ||
* @phpstan-param array<string, mixed>|list<mixed> $args | ||
* @phpstan-return list<mixed> | ||
*/ | ||
protected function normalizeFunctions(array $args): array | ||
{ | ||
// Args passed as array values | ||
// [ICollection::AND, ['id' => 1], ['name' => John]] | ||
if (isset($args[0])) { | ||
/** @phpstan-var list<mixed> $args */ | ||
return $args; | ||
} | ||
|
||
// Args passed as keys | ||
// [ICollection::AND, 'id' => 1, 'name!=' => John] | ||
/** @phpstan-var array<string, mixed> $args */ | ||
$processedArgs = []; | ||
foreach ($args as $argName => $argValue) { | ||
$functionCall = $this->conditionParser->parsePropertyOperator($argName); | ||
$functionCall[] = $argValue; | ||
$processedArgs[] = $functionCall; | ||
} | ||
return $processedArgs; | ||
} | ||
|
||
|
||
/** | ||
* @param literal-string $dbalModifier either %or or %and dbal modifier | ||
* @param array<int|string, mixed> $args | ||
*/ | ||
protected function processQueryBuilderExpressionWithModifier( | ||
string $dbalModifier, | ||
DbalQueryBuilderHelper $helper, | ||
QueryBuilder $builder, | ||
array $args, | ||
?IDbalAggregator $aggregator | ||
): DbalExpressionResult | ||
{ | ||
$isHavingClause = false; | ||
$processedArgs = []; | ||
$joins = []; | ||
|
||
foreach ($this->normalizeFunctions($args) as $collectionFunctionArgs) { | ||
$expression = $helper->processFilterFunction($builder, $collectionFunctionArgs, $aggregator); | ||
$expression = $expression->applyAggregator($builder); | ||
$processedArgs[] = $expression->getExpansionArguments(); | ||
$joins = array_merge($joins, $expression->joins); | ||
$isHavingClause = $isHavingClause || $expression->isHavingClause; | ||
} | ||
|
||
return new DbalExpressionResult( | ||
$dbalModifier, | ||
[$processedArgs], | ||
$helper->mergeJoins($dbalModifier, $joins), | ||
null, | ||
$isHavingClause, | ||
null, | ||
null | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.