diff options
Diffstat (limited to 'vendor/doctrine/orm/src/Query/Expr/Composite.php')
-rw-r--r-- | vendor/doctrine/orm/src/Query/Expr/Composite.php | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/vendor/doctrine/orm/src/Query/Expr/Composite.php b/vendor/doctrine/orm/src/Query/Expr/Composite.php new file mode 100644 index 0000000..f3007a7 --- /dev/null +++ b/vendor/doctrine/orm/src/Query/Expr/Composite.php | |||
@@ -0,0 +1,50 @@ | |||
1 | <?php | ||
2 | |||
3 | declare(strict_types=1); | ||
4 | |||
5 | namespace Doctrine\ORM\Query\Expr; | ||
6 | |||
7 | use Stringable; | ||
8 | |||
9 | use function implode; | ||
10 | use function is_object; | ||
11 | use function preg_match; | ||
12 | |||
13 | /** | ||
14 | * Expression class for building DQL and parts. | ||
15 | * | ||
16 | * @link www.doctrine-project.org | ||
17 | */ | ||
18 | class Composite extends Base | ||
19 | { | ||
20 | public function __toString(): string | ||
21 | { | ||
22 | if ($this->count() === 1) { | ||
23 | return (string) $this->parts[0]; | ||
24 | } | ||
25 | |||
26 | $components = []; | ||
27 | |||
28 | foreach ($this->parts as $part) { | ||
29 | $components[] = $this->processQueryPart($part); | ||
30 | } | ||
31 | |||
32 | return implode($this->separator, $components); | ||
33 | } | ||
34 | |||
35 | private function processQueryPart(string|Stringable $part): string | ||
36 | { | ||
37 | $queryPart = (string) $part; | ||
38 | |||
39 | if (is_object($part) && $part instanceof self && $part->count() > 1) { | ||
40 | return $this->preSeparator . $queryPart . $this->postSeparator; | ||
41 | } | ||
42 | |||
43 | // Fixes DDC-1237: User may have added a where item containing nested expression (with "OR" or "AND") | ||
44 | if (preg_match('/\s(OR|AND)\s/i', $queryPart)) { | ||
45 | return $this->preSeparator . $queryPart . $this->postSeparator; | ||
46 | } | ||
47 | |||
48 | return $queryPart; | ||
49 | } | ||
50 | } | ||