ExpressionBuilder.php
99 lines
| 1 | <?php |
| 2 | namespace MailPoetVendor\Doctrine\DBAL\Query\Expression; |
| 3 | if (!defined('ABSPATH')) exit; |
| 4 | use MailPoetVendor\Doctrine\DBAL\Connection; |
| 5 | use MailPoetVendor\Doctrine\Deprecations\Deprecation; |
| 6 | use function func_get_arg; |
| 7 | use function func_get_args; |
| 8 | use function func_num_args; |
| 9 | use function implode; |
| 10 | use function sprintf; |
| 11 | class ExpressionBuilder |
| 12 | { |
| 13 | public const EQ = '='; |
| 14 | public const NEQ = '<>'; |
| 15 | public const LT = '<'; |
| 16 | public const LTE = '<='; |
| 17 | public const GT = '>'; |
| 18 | public const GTE = '>='; |
| 19 | private Connection $connection; |
| 20 | public function __construct(Connection $connection) |
| 21 | { |
| 22 | $this->connection = $connection; |
| 23 | } |
| 24 | public function and($expression, ...$expressions) : CompositeExpression |
| 25 | { |
| 26 | return CompositeExpression::and($expression, ...$expressions); |
| 27 | } |
| 28 | public function or($expression, ...$expressions) : CompositeExpression |
| 29 | { |
| 30 | return CompositeExpression::or($expression, ...$expressions); |
| 31 | } |
| 32 | public function andX($x = null) |
| 33 | { |
| 34 | Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/3851', 'ExpressionBuilder::andX() is deprecated, use ExpressionBuilder::and() instead.'); |
| 35 | return new CompositeExpression(CompositeExpression::TYPE_AND, func_get_args()); |
| 36 | } |
| 37 | public function orX($x = null) |
| 38 | { |
| 39 | Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/3851', 'ExpressionBuilder::orX() is deprecated, use ExpressionBuilder::or() instead.'); |
| 40 | return new CompositeExpression(CompositeExpression::TYPE_OR, func_get_args()); |
| 41 | } |
| 42 | public function comparison($x, $operator, $y) |
| 43 | { |
| 44 | return $x . ' ' . $operator . ' ' . $y; |
| 45 | } |
| 46 | public function eq($x, $y) |
| 47 | { |
| 48 | return $this->comparison($x, self::EQ, $y); |
| 49 | } |
| 50 | public function neq($x, $y) |
| 51 | { |
| 52 | return $this->comparison($x, self::NEQ, $y); |
| 53 | } |
| 54 | public function lt($x, $y) |
| 55 | { |
| 56 | return $this->comparison($x, self::LT, $y); |
| 57 | } |
| 58 | public function lte($x, $y) |
| 59 | { |
| 60 | return $this->comparison($x, self::LTE, $y); |
| 61 | } |
| 62 | public function gt($x, $y) |
| 63 | { |
| 64 | return $this->comparison($x, self::GT, $y); |
| 65 | } |
| 66 | public function gte($x, $y) |
| 67 | { |
| 68 | return $this->comparison($x, self::GTE, $y); |
| 69 | } |
| 70 | public function isNull($x) |
| 71 | { |
| 72 | return $x . ' IS NULL'; |
| 73 | } |
| 74 | public function isNotNull($x) |
| 75 | { |
| 76 | return $x . ' IS NOT NULL'; |
| 77 | } |
| 78 | public function like($x, $y) |
| 79 | { |
| 80 | return $this->comparison($x, 'LIKE', $y) . (func_num_args() >= 3 ? sprintf(' ESCAPE %s', func_get_arg(2)) : ''); |
| 81 | } |
| 82 | public function notLike($x, $y) |
| 83 | { |
| 84 | return $this->comparison($x, 'NOT LIKE', $y) . (func_num_args() >= 3 ? sprintf(' ESCAPE %s', func_get_arg(2)) : ''); |
| 85 | } |
| 86 | public function in($x, $y) |
| 87 | { |
| 88 | return $this->comparison($x, 'IN', '(' . implode(', ', (array) $y) . ')'); |
| 89 | } |
| 90 | public function notIn($x, $y) |
| 91 | { |
| 92 | return $this->comparison($x, 'NOT IN', '(' . implode(', ', (array) $y) . ')'); |
| 93 | } |
| 94 | public function literal($input, $type = null) |
| 95 | { |
| 96 | return $this->connection->quote($input, $type); |
| 97 | } |
| 98 | } |
| 99 |