Andx.php
9 months ago
Base.php
9 months ago
Comparison.php
9 months ago
Composite.php
9 months ago
From.php
9 months ago
Func.php
9 months ago
GroupBy.php
9 months ago
Join.php
9 months ago
Literal.php
9 months ago
Math.php
9 months ago
OrderBy.php
9 months ago
Orx.php
9 months ago
Select.php
9 months ago
index.php
9 months ago
Base.php
55 lines
| 1 | <?php |
| 2 | declare (strict_types=1); |
| 3 | namespace MailPoetVendor\Doctrine\ORM\Query\Expr; |
| 4 | if (!defined('ABSPATH')) exit; |
| 5 | use InvalidArgumentException; |
| 6 | use Stringable; |
| 7 | use function count; |
| 8 | use function get_class; |
| 9 | use function get_debug_type; |
| 10 | use function implode; |
| 11 | use function in_array; |
| 12 | use function is_string; |
| 13 | use function sprintf; |
| 14 | abstract class Base |
| 15 | { |
| 16 | protected $preSeparator = '('; |
| 17 | protected $separator = ', '; |
| 18 | protected $postSeparator = ')'; |
| 19 | protected $allowedClasses = []; |
| 20 | protected $parts = []; |
| 21 | public function __construct($args = []) |
| 22 | { |
| 23 | $this->addMultiple($args); |
| 24 | } |
| 25 | public function addMultiple($args = []) |
| 26 | { |
| 27 | foreach ((array) $args as $arg) { |
| 28 | $this->add($arg); |
| 29 | } |
| 30 | return $this; |
| 31 | } |
| 32 | public function add($arg) |
| 33 | { |
| 34 | if ($arg !== null && (!$arg instanceof self || $arg->count() > 0)) { |
| 35 | // If we decide to keep Expr\Base instances, we can use this check |
| 36 | if (!is_string($arg) && !in_array(get_class($arg), $this->allowedClasses, \true)) { |
| 37 | throw new InvalidArgumentException(sprintf("Expression of type '%s' not allowed in this context.", get_debug_type($arg))); |
| 38 | } |
| 39 | $this->parts[] = $arg; |
| 40 | } |
| 41 | return $this; |
| 42 | } |
| 43 | public function count() |
| 44 | { |
| 45 | return count($this->parts); |
| 46 | } |
| 47 | public function __toString() |
| 48 | { |
| 49 | if ($this->count() === 1) { |
| 50 | return (string) $this->parts[0]; |
| 51 | } |
| 52 | return $this->preSeparator . implode($this->separator, $this->parts) . $this->postSeparator; |
| 53 | } |
| 54 | } |
| 55 |