Exception
9 months ago
CountOutputWalker.php
9 months ago
CountWalker.php
9 months ago
LimitSubqueryOutputWalker.php
9 months ago
LimitSubqueryWalker.php
9 months ago
Paginator.php
9 months ago
RootTypeWalker.php
9 months ago
RowNumberOverFunction.php
9 months ago
WhereInWalker.php
9 months ago
index.php
9 months ago
WhereInWalker.php
66 lines
| 1 | <?php |
| 2 | declare (strict_types=1); |
| 3 | namespace MailPoetVendor\Doctrine\ORM\Tools\Pagination; |
| 4 | if (!defined('ABSPATH')) exit; |
| 5 | use MailPoetVendor\Doctrine\ORM\Query\AST\ArithmeticExpression; |
| 6 | use MailPoetVendor\Doctrine\ORM\Query\AST\ConditionalExpression; |
| 7 | use MailPoetVendor\Doctrine\ORM\Query\AST\ConditionalPrimary; |
| 8 | use MailPoetVendor\Doctrine\ORM\Query\AST\ConditionalTerm; |
| 9 | use MailPoetVendor\Doctrine\ORM\Query\AST\InListExpression; |
| 10 | use MailPoetVendor\Doctrine\ORM\Query\AST\InputParameter; |
| 11 | use MailPoetVendor\Doctrine\ORM\Query\AST\NullComparisonExpression; |
| 12 | use MailPoetVendor\Doctrine\ORM\Query\AST\PathExpression; |
| 13 | use MailPoetVendor\Doctrine\ORM\Query\AST\SelectStatement; |
| 14 | use MailPoetVendor\Doctrine\ORM\Query\AST\SimpleArithmeticExpression; |
| 15 | use MailPoetVendor\Doctrine\ORM\Query\AST\WhereClause; |
| 16 | use MailPoetVendor\Doctrine\ORM\Query\TreeWalkerAdapter; |
| 17 | use RuntimeException; |
| 18 | use function count; |
| 19 | use function reset; |
| 20 | class WhereInWalker extends TreeWalkerAdapter |
| 21 | { |
| 22 | public const HINT_PAGINATOR_HAS_IDS = 'doctrine.paginator_has_ids'; |
| 23 | public const PAGINATOR_ID_ALIAS = 'dpid'; |
| 24 | public function walkSelectStatement(SelectStatement $AST) |
| 25 | { |
| 26 | // Get the root entity and alias from the AST fromClause |
| 27 | $from = $AST->fromClause->identificationVariableDeclarations; |
| 28 | if (count($from) > 1) { |
| 29 | throw new RuntimeException('Cannot count query which selects two FROM components, cannot make distinction'); |
| 30 | } |
| 31 | $fromRoot = reset($from); |
| 32 | $rootAlias = $fromRoot->rangeVariableDeclaration->aliasIdentificationVariable; |
| 33 | $rootClass = $this->getMetadataForDqlAlias($rootAlias); |
| 34 | $identifierFieldName = $rootClass->getSingleIdentifierFieldName(); |
| 35 | $pathType = PathExpression::TYPE_STATE_FIELD; |
| 36 | if (isset($rootClass->associationMappings[$identifierFieldName])) { |
| 37 | $pathType = PathExpression::TYPE_SINGLE_VALUED_ASSOCIATION; |
| 38 | } |
| 39 | $pathExpression = new PathExpression(PathExpression::TYPE_STATE_FIELD | PathExpression::TYPE_SINGLE_VALUED_ASSOCIATION, $rootAlias, $identifierFieldName); |
| 40 | $pathExpression->type = $pathType; |
| 41 | $hasIds = $this->_getQuery()->getHint(self::HINT_PAGINATOR_HAS_IDS); |
| 42 | if ($hasIds) { |
| 43 | $arithmeticExpression = new ArithmeticExpression(); |
| 44 | $arithmeticExpression->simpleArithmeticExpression = new SimpleArithmeticExpression([$pathExpression]); |
| 45 | $expression = new InListExpression($arithmeticExpression, [new InputParameter(':' . self::PAGINATOR_ID_ALIAS)]); |
| 46 | } else { |
| 47 | $expression = new NullComparisonExpression($pathExpression); |
| 48 | } |
| 49 | $conditionalPrimary = new ConditionalPrimary(); |
| 50 | $conditionalPrimary->simpleConditionalExpression = $expression; |
| 51 | if ($AST->whereClause) { |
| 52 | if ($AST->whereClause->conditionalExpression instanceof ConditionalTerm) { |
| 53 | $AST->whereClause->conditionalExpression->conditionalFactors[] = $conditionalPrimary; |
| 54 | } elseif ($AST->whereClause->conditionalExpression instanceof ConditionalPrimary) { |
| 55 | $AST->whereClause->conditionalExpression = new ConditionalExpression([new ConditionalTerm([$AST->whereClause->conditionalExpression, $conditionalPrimary])]); |
| 56 | } else { |
| 57 | $tmpPrimary = new ConditionalPrimary(); |
| 58 | $tmpPrimary->conditionalExpression = $AST->whereClause->conditionalExpression; |
| 59 | $AST->whereClause->conditionalExpression = new ConditionalTerm([$tmpPrimary, $conditionalPrimary]); |
| 60 | } |
| 61 | } else { |
| 62 | $AST->whereClause = new WhereClause(new ConditionalExpression([new ConditionalTerm([$conditionalPrimary])])); |
| 63 | } |
| 64 | } |
| 65 | } |
| 66 |