AST
9 months ago
Exec
9 months ago
Expr
9 months ago
Filter
9 months ago
Expr.php
9 months ago
FilterCollection.php
9 months ago
Lexer.php
9 months ago
OutputWalker.php
9 months ago
Parameter.php
9 months ago
ParameterTypeInferer.php
9 months ago
Parser.php
9 months ago
ParserResult.php
9 months ago
Printer.php
9 months ago
QueryException.php
9 months ago
QueryExpressionVisitor.php
9 months ago
ResultSetMapping.php
9 months ago
ResultSetMappingBuilder.php
9 months ago
SqlOutputWalker.php
9 months ago
SqlWalker.php
9 months ago
TokenType.php
9 months ago
TreeWalker.php
9 months ago
TreeWalkerAdapter.php
9 months ago
TreeWalkerChain.php
9 months ago
TreeWalkerChainIterator.php
9 months ago
index.php
9 months ago
Expr.php
223 lines
| 1 | <?php |
| 2 | declare (strict_types=1); |
| 3 | namespace MailPoetVendor\Doctrine\ORM\Query; |
| 4 | if (!defined('ABSPATH')) exit; |
| 5 | use Traversable; |
| 6 | use function func_get_args; |
| 7 | use function implode; |
| 8 | use function is_bool; |
| 9 | use function is_float; |
| 10 | use function is_int; |
| 11 | use function is_iterable; |
| 12 | use function iterator_to_array; |
| 13 | use function str_replace; |
| 14 | class Expr |
| 15 | { |
| 16 | public function andX($x = null) |
| 17 | { |
| 18 | return new Expr\Andx(func_get_args()); |
| 19 | } |
| 20 | public function orX($x = null) |
| 21 | { |
| 22 | return new Expr\Orx(func_get_args()); |
| 23 | } |
| 24 | public function asc($expr) |
| 25 | { |
| 26 | return new Expr\OrderBy($expr, 'ASC'); |
| 27 | } |
| 28 | public function desc($expr) |
| 29 | { |
| 30 | return new Expr\OrderBy($expr, 'DESC'); |
| 31 | } |
| 32 | public function eq($x, $y) |
| 33 | { |
| 34 | return new Expr\Comparison($x, Expr\Comparison::EQ, $y); |
| 35 | } |
| 36 | public function neq($x, $y) |
| 37 | { |
| 38 | return new Expr\Comparison($x, Expr\Comparison::NEQ, $y); |
| 39 | } |
| 40 | public function lt($x, $y) |
| 41 | { |
| 42 | return new Expr\Comparison($x, Expr\Comparison::LT, $y); |
| 43 | } |
| 44 | public function lte($x, $y) |
| 45 | { |
| 46 | return new Expr\Comparison($x, Expr\Comparison::LTE, $y); |
| 47 | } |
| 48 | public function gt($x, $y) |
| 49 | { |
| 50 | return new Expr\Comparison($x, Expr\Comparison::GT, $y); |
| 51 | } |
| 52 | public function gte($x, $y) |
| 53 | { |
| 54 | return new Expr\Comparison($x, Expr\Comparison::GTE, $y); |
| 55 | } |
| 56 | public function avg($x) |
| 57 | { |
| 58 | return new Expr\Func('AVG', [$x]); |
| 59 | } |
| 60 | public function max($x) |
| 61 | { |
| 62 | return new Expr\Func('MAX', [$x]); |
| 63 | } |
| 64 | public function min($x) |
| 65 | { |
| 66 | return new Expr\Func('MIN', [$x]); |
| 67 | } |
| 68 | public function count($x) |
| 69 | { |
| 70 | return new Expr\Func('COUNT', [$x]); |
| 71 | } |
| 72 | public function countDistinct($x) |
| 73 | { |
| 74 | return 'COUNT(DISTINCT ' . implode(', ', func_get_args()) . ')'; |
| 75 | } |
| 76 | public function exists($subquery) |
| 77 | { |
| 78 | return new Expr\Func('EXISTS', [$subquery]); |
| 79 | } |
| 80 | public function all($subquery) |
| 81 | { |
| 82 | return new Expr\Func('ALL', [$subquery]); |
| 83 | } |
| 84 | public function some($subquery) |
| 85 | { |
| 86 | return new Expr\Func('SOME', [$subquery]); |
| 87 | } |
| 88 | public function any($subquery) |
| 89 | { |
| 90 | return new Expr\Func('ANY', [$subquery]); |
| 91 | } |
| 92 | public function not($restriction) |
| 93 | { |
| 94 | return new Expr\Func('NOT', [$restriction]); |
| 95 | } |
| 96 | public function abs($x) |
| 97 | { |
| 98 | return new Expr\Func('ABS', [$x]); |
| 99 | } |
| 100 | public function mod($x, $y) : Expr\Func |
| 101 | { |
| 102 | return new Expr\Func('MOD', [$x, $y]); |
| 103 | } |
| 104 | public function prod($x, $y) |
| 105 | { |
| 106 | return new Expr\Math($x, '*', $y); |
| 107 | } |
| 108 | public function diff($x, $y) |
| 109 | { |
| 110 | return new Expr\Math($x, '-', $y); |
| 111 | } |
| 112 | public function sum($x, $y) |
| 113 | { |
| 114 | return new Expr\Math($x, '+', $y); |
| 115 | } |
| 116 | public function quot($x, $y) |
| 117 | { |
| 118 | return new Expr\Math($x, '/', $y); |
| 119 | } |
| 120 | public function sqrt($x) |
| 121 | { |
| 122 | return new Expr\Func('SQRT', [$x]); |
| 123 | } |
| 124 | public function in($x, $y) |
| 125 | { |
| 126 | if (is_iterable($y)) { |
| 127 | if ($y instanceof Traversable) { |
| 128 | $y = iterator_to_array($y); |
| 129 | } |
| 130 | foreach ($y as &$literal) { |
| 131 | if (!$literal instanceof Expr\Literal) { |
| 132 | $literal = $this->quoteLiteral($literal); |
| 133 | } |
| 134 | } |
| 135 | } |
| 136 | return new Expr\Func($x . ' IN', (array) $y); |
| 137 | } |
| 138 | public function notIn($x, $y) |
| 139 | { |
| 140 | if (is_iterable($y)) { |
| 141 | if ($y instanceof Traversable) { |
| 142 | $y = iterator_to_array($y); |
| 143 | } |
| 144 | foreach ($y as &$literal) { |
| 145 | if (!$literal instanceof Expr\Literal) { |
| 146 | $literal = $this->quoteLiteral($literal); |
| 147 | } |
| 148 | } |
| 149 | } |
| 150 | return new Expr\Func($x . ' NOT IN', (array) $y); |
| 151 | } |
| 152 | public function isNull($x) |
| 153 | { |
| 154 | return $x . ' IS NULL'; |
| 155 | } |
| 156 | public function isNotNull($x) |
| 157 | { |
| 158 | return $x . ' IS NOT NULL'; |
| 159 | } |
| 160 | public function like($x, $y) |
| 161 | { |
| 162 | return new Expr\Comparison($x, 'LIKE', $y); |
| 163 | } |
| 164 | public function notLike($x, $y) |
| 165 | { |
| 166 | return new Expr\Comparison($x, 'NOT LIKE', $y); |
| 167 | } |
| 168 | public function concat($x, $y) |
| 169 | { |
| 170 | return new Expr\Func('CONCAT', func_get_args()); |
| 171 | } |
| 172 | public function substring($x, $from, $len = null) |
| 173 | { |
| 174 | $args = [$x, $from]; |
| 175 | if ($len !== null) { |
| 176 | $args[] = $len; |
| 177 | } |
| 178 | return new Expr\Func('SUBSTRING', $args); |
| 179 | } |
| 180 | public function lower($x) |
| 181 | { |
| 182 | return new Expr\Func('LOWER', [$x]); |
| 183 | } |
| 184 | public function upper($x) |
| 185 | { |
| 186 | return new Expr\Func('UPPER', [$x]); |
| 187 | } |
| 188 | public function length($x) |
| 189 | { |
| 190 | return new Expr\Func('LENGTH', [$x]); |
| 191 | } |
| 192 | public function literal($literal) |
| 193 | { |
| 194 | return new Expr\Literal($this->quoteLiteral($literal)); |
| 195 | } |
| 196 | private function quoteLiteral($literal) : string |
| 197 | { |
| 198 | if (is_int($literal) || is_float($literal)) { |
| 199 | return (string) $literal; |
| 200 | } |
| 201 | if (is_bool($literal)) { |
| 202 | return $literal ? 'true' : 'false'; |
| 203 | } |
| 204 | return "'" . str_replace("'", "''", $literal) . "'"; |
| 205 | } |
| 206 | public function between($val, $x, $y) |
| 207 | { |
| 208 | return $val . ' BETWEEN ' . $x . ' AND ' . $y; |
| 209 | } |
| 210 | public function trim($x) |
| 211 | { |
| 212 | return new Expr\Func('TRIM', $x); |
| 213 | } |
| 214 | public function isMemberOf($x, $y) |
| 215 | { |
| 216 | return new Expr\Comparison($x, 'MEMBER OF', $y); |
| 217 | } |
| 218 | public function isInstanceOf($x, $y) |
| 219 | { |
| 220 | return new Expr\Comparison($x, 'INSTANCE OF', $y); |
| 221 | } |
| 222 | } |
| 223 |