Collection
9 months ago
Entity
9 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
SqlValueVisitor.php
50 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 | class SqlValueVisitor extends ExpressionVisitor |
| 10 | { |
| 11 | private $values = []; |
| 12 | private $types = []; |
| 13 | public function walkComparison(Comparison $comparison) |
| 14 | { |
| 15 | $value = $this->getValueFromComparison($comparison); |
| 16 | $this->values[] = $value; |
| 17 | $this->types[] = [$comparison->getField(), $value, $comparison->getOperator()]; |
| 18 | return null; |
| 19 | } |
| 20 | public function walkCompositeExpression(CompositeExpression $expr) |
| 21 | { |
| 22 | foreach ($expr->getExpressionList() as $child) { |
| 23 | $this->dispatch($child); |
| 24 | } |
| 25 | return null; |
| 26 | } |
| 27 | public function walkValue(Value $value) |
| 28 | { |
| 29 | return null; |
| 30 | } |
| 31 | public function getParamsAndTypes() |
| 32 | { |
| 33 | return [$this->values, $this->types]; |
| 34 | } |
| 35 | protected function getValueFromComparison(Comparison $comparison) |
| 36 | { |
| 37 | $value = $comparison->getValue()->getValue(); |
| 38 | switch ($comparison->getOperator()) { |
| 39 | case Comparison::CONTAINS: |
| 40 | return '%' . $value . '%'; |
| 41 | case Comparison::STARTS_WITH: |
| 42 | return $value . '%'; |
| 43 | case Comparison::ENDS_WITH: |
| 44 | return '%' . $value; |
| 45 | default: |
| 46 | return $value; |
| 47 | } |
| 48 | } |
| 49 | } |
| 50 |