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
Composite.php
34 lines
| 1 | <?php |
| 2 | declare (strict_types=1); |
| 3 | namespace MailPoetVendor\Doctrine\ORM\Query\Expr; |
| 4 | if (!defined('ABSPATH')) exit; |
| 5 | use function implode; |
| 6 | use function is_object; |
| 7 | use function preg_match; |
| 8 | class Composite extends Base |
| 9 | { |
| 10 | public function __toString() |
| 11 | { |
| 12 | if ($this->count() === 1) { |
| 13 | return (string) $this->parts[0]; |
| 14 | } |
| 15 | $components = []; |
| 16 | foreach ($this->parts as $part) { |
| 17 | $components[] = $this->processQueryPart($part); |
| 18 | } |
| 19 | return implode($this->separator, $components); |
| 20 | } |
| 21 | private function processQueryPart($part) : string |
| 22 | { |
| 23 | $queryPart = (string) $part; |
| 24 | if (is_object($part) && $part instanceof self && $part->count() > 1) { |
| 25 | return $this->preSeparator . $queryPart . $this->postSeparator; |
| 26 | } |
| 27 | // Fixes DDC-1237: User may have added a where item containing nested expression (with "OR" or "AND") |
| 28 | if (preg_match('/\\s(OR|AND)\\s/i', $queryPart)) { |
| 29 | return $this->preSeparator . $queryPart . $this->postSeparator; |
| 30 | } |
| 31 | return $queryPart; |
| 32 | } |
| 33 | } |
| 34 |