Collection
9 months ago
Entity
8 months ago
Exception
9 months ago
MatchingAssociationFieldRequiresObject.php
9 months ago
PersisterException.php
9 months ago
SqlExpressionVisitor.php
9 months ago
SqlValueVisitor.php
9 months ago
index.php
9 months ago
SqlExpressionVisitor.php
59 lines
| 1 | <?php |
| 2 | declare (strict_types=1); |
| 3 | namespace MailPoetVendor\Doctrine\ORM\Persisters; |
| 4 | if (!defined('ABSPATH')) exit; |
| 5 | use MailPoetVendor\Doctrine\Common\Collections\Expr\Comparison; |
| 6 | use MailPoetVendor\Doctrine\Common\Collections\Expr\CompositeExpression; |
| 7 | use MailPoetVendor\Doctrine\Common\Collections\Expr\ExpressionVisitor; |
| 8 | use MailPoetVendor\Doctrine\Common\Collections\Expr\Value; |
| 9 | use MailPoetVendor\Doctrine\ORM\Mapping\ClassMetadata; |
| 10 | use MailPoetVendor\Doctrine\ORM\Persisters\Entity\BasicEntityPersister; |
| 11 | use RuntimeException; |
| 12 | use function defined; |
| 13 | use function implode; |
| 14 | use function in_array; |
| 15 | use function is_object; |
| 16 | class SqlExpressionVisitor extends ExpressionVisitor |
| 17 | { |
| 18 | private $persister; |
| 19 | private $classMetadata; |
| 20 | public function __construct(BasicEntityPersister $persister, ClassMetadata $classMetadata) |
| 21 | { |
| 22 | $this->persister = $persister; |
| 23 | $this->classMetadata = $classMetadata; |
| 24 | } |
| 25 | public function walkComparison(Comparison $comparison) |
| 26 | { |
| 27 | $field = $comparison->getField(); |
| 28 | $value = $comparison->getValue()->getValue(); |
| 29 | // shortcut for walkValue() |
| 30 | if (isset($this->classMetadata->associationMappings[$field]) && $value !== null && !is_object($value) && !in_array($comparison->getOperator(), [Comparison::IN, Comparison::NIN], \true)) { |
| 31 | throw MatchingAssociationFieldRequiresObject::fromClassAndAssociation($this->classMetadata->name, $field); |
| 32 | } |
| 33 | return $this->persister->getSelectConditionStatementSQL($field, $value, null, $comparison->getOperator()); |
| 34 | } |
| 35 | public function walkCompositeExpression(CompositeExpression $expr) |
| 36 | { |
| 37 | $expressionList = []; |
| 38 | foreach ($expr->getExpressionList() as $child) { |
| 39 | $expressionList[] = $this->dispatch($child); |
| 40 | } |
| 41 | switch ($expr->getType()) { |
| 42 | case CompositeExpression::TYPE_AND: |
| 43 | return '(' . implode(' AND ', $expressionList) . ')'; |
| 44 | case CompositeExpression::TYPE_OR: |
| 45 | return '(' . implode(' OR ', $expressionList) . ')'; |
| 46 | default: |
| 47 | // Multiversion support for `doctrine/collections` before and after v2.1.0 |
| 48 | if (defined(CompositeExpression::class . '::TYPE_NOT') && $expr->getType() === CompositeExpression::TYPE_NOT) { |
| 49 | return 'NOT (' . $expressionList[0] . ')'; |
| 50 | } |
| 51 | throw new RuntimeException('Unknown composite ' . $expr->getType()); |
| 52 | } |
| 53 | } |
| 54 | public function walkValue(Value $value) |
| 55 | { |
| 56 | return '?'; |
| 57 | } |
| 58 | } |
| 59 |