diff options
| author | polo <ordipolo@gmx.fr> | 2024-08-13 23:45:21 +0200 |
|---|---|---|
| committer | polo <ordipolo@gmx.fr> | 2024-08-13 23:45:21 +0200 |
| commit | bf6655a534a6775d30cafa67bd801276bda1d98d (patch) | |
| tree | c6381e3f6c81c33eab72508f410b165ba05f7e9c /vendor/doctrine/orm/src/Persisters/SqlValueVisitor.php | |
| parent | 94d67a4b51f8e62e7d518cce26a526ae1ec48278 (diff) | |
| download | AppliGestionPHP-bf6655a534a6775d30cafa67bd801276bda1d98d.tar.gz AppliGestionPHP-bf6655a534a6775d30cafa67bd801276bda1d98d.tar.bz2 AppliGestionPHP-bf6655a534a6775d30cafa67bd801276bda1d98d.zip | |
VERSION 0.2 doctrine ORM et entités
Diffstat (limited to 'vendor/doctrine/orm/src/Persisters/SqlValueVisitor.php')
| -rw-r--r-- | vendor/doctrine/orm/src/Persisters/SqlValueVisitor.php | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/vendor/doctrine/orm/src/Persisters/SqlValueVisitor.php b/vendor/doctrine/orm/src/Persisters/SqlValueVisitor.php new file mode 100644 index 0000000..7f987ad --- /dev/null +++ b/vendor/doctrine/orm/src/Persisters/SqlValueVisitor.php | |||
| @@ -0,0 +1,88 @@ | |||
| 1 | <?php | ||
| 2 | |||
| 3 | declare(strict_types=1); | ||
| 4 | |||
| 5 | namespace Doctrine\ORM\Persisters; | ||
| 6 | |||
| 7 | use Doctrine\Common\Collections\Expr\Comparison; | ||
| 8 | use Doctrine\Common\Collections\Expr\CompositeExpression; | ||
| 9 | use Doctrine\Common\Collections\Expr\ExpressionVisitor; | ||
| 10 | use Doctrine\Common\Collections\Expr\Value; | ||
| 11 | |||
| 12 | /** | ||
| 13 | * Extract the values from a criteria/expression | ||
| 14 | */ | ||
| 15 | class SqlValueVisitor extends ExpressionVisitor | ||
| 16 | { | ||
| 17 | /** @var mixed[] */ | ||
| 18 | private array $values = []; | ||
| 19 | |||
| 20 | /** @var mixed[][] */ | ||
| 21 | private array $types = []; | ||
| 22 | |||
| 23 | /** | ||
| 24 | * Converts a comparison expression into the target query language output. | ||
| 25 | * | ||
| 26 | * {@inheritDoc} | ||
| 27 | */ | ||
| 28 | public function walkComparison(Comparison $comparison) | ||
| 29 | { | ||
| 30 | $value = $this->getValueFromComparison($comparison); | ||
| 31 | |||
| 32 | $this->values[] = $value; | ||
| 33 | $this->types[] = [$comparison->getField(), $value, $comparison->getOperator()]; | ||
| 34 | |||
| 35 | return null; | ||
| 36 | } | ||
| 37 | |||
| 38 | /** | ||
| 39 | * Converts a composite expression into the target query language output. | ||
| 40 | * | ||
| 41 | * {@inheritDoc} | ||
| 42 | */ | ||
| 43 | public function walkCompositeExpression(CompositeExpression $expr) | ||
| 44 | { | ||
| 45 | foreach ($expr->getExpressionList() as $child) { | ||
| 46 | $this->dispatch($child); | ||
| 47 | } | ||
| 48 | |||
| 49 | return null; | ||
| 50 | } | ||
| 51 | |||
| 52 | /** | ||
| 53 | * Converts a value expression into the target query language part. | ||
| 54 | * | ||
| 55 | * {@inheritDoc} | ||
| 56 | */ | ||
| 57 | public function walkValue(Value $value) | ||
| 58 | { | ||
| 59 | return null; | ||
| 60 | } | ||
| 61 | |||
| 62 | /** | ||
| 63 | * Returns the Parameters and Types necessary for matching the last visited expression. | ||
| 64 | * | ||
| 65 | * @return mixed[][] | ||
| 66 | * @psalm-return array{0: array, 1: array<array<mixed>>} | ||
| 67 | */ | ||
| 68 | public function getParamsAndTypes(): array | ||
| 69 | { | ||
| 70 | return [$this->values, $this->types]; | ||
| 71 | } | ||
| 72 | |||
| 73 | /** | ||
| 74 | * Returns the value from a Comparison. In case of a CONTAINS comparison, | ||
| 75 | * the value is wrapped in %-signs, because it will be used in a LIKE clause. | ||
| 76 | */ | ||
| 77 | protected function getValueFromComparison(Comparison $comparison): mixed | ||
| 78 | { | ||
| 79 | $value = $comparison->getValue()->getValue(); | ||
| 80 | |||
| 81 | return match ($comparison->getOperator()) { | ||
| 82 | Comparison::CONTAINS => '%' . $value . '%', | ||
| 83 | Comparison::STARTS_WITH => $value . '%', | ||
| 84 | Comparison::ENDS_WITH => '%' . $value, | ||
| 85 | default => $value, | ||
| 86 | }; | ||
| 87 | } | ||
| 88 | } | ||
