1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Doctrine\DBAL\Query; |
6
|
|
|
|
7
|
|
|
use Doctrine\DBAL\Query\Expression\CompositeExpression; |
8
|
|
|
|
9
|
|
|
class QueryParts |
10
|
|
|
{ |
11
|
|
|
/** @var string[] */ |
12
|
|
|
public $select = []; |
13
|
|
|
|
14
|
|
|
/** @var bool */ |
15
|
|
|
public $distinct = false; |
16
|
|
|
|
17
|
|
|
/** @var QueryPartFrom[] */ |
18
|
|
|
public $from = []; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Lists of joins indexed by from alias. |
22
|
|
|
* |
23
|
|
|
* @var array<string, QueryPartJoin[]> |
24
|
|
|
*/ |
25
|
|
|
public $join = []; |
26
|
|
|
|
27
|
|
|
/** @var string[] */ |
28
|
|
|
public $set = []; |
29
|
|
|
|
30
|
|
|
/** @var CompositeExpression|null */ |
31
|
|
|
public $where = null; |
32
|
|
|
|
33
|
|
|
/** @var string[] */ |
34
|
|
|
public $groupBy = []; |
35
|
|
|
|
36
|
|
|
/** @var CompositeExpression|null */ |
37
|
|
|
public $having = null; |
38
|
|
|
|
39
|
|
|
/** @var string[] */ |
40
|
|
|
public $orderBy = []; |
41
|
|
|
|
42
|
|
|
/** @var array<string, mixed> */ |
43
|
|
|
public $values = []; |
44
|
|
|
|
45
|
|
|
public function reset() : void |
46
|
|
|
{ |
47
|
|
|
$this->resetSelect(); |
48
|
|
|
$this->resetDistinct(); |
49
|
|
|
$this->resetFrom(); |
50
|
|
|
$this->resetJoin(); |
51
|
|
|
$this->resetSet(); |
52
|
|
|
$this->resetWhere(); |
53
|
|
|
$this->resetGroupBy(); |
54
|
|
|
$this->resetHaving(); |
55
|
|
|
$this->resetOrderBy(); |
56
|
|
|
$this->resetValues(); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function resetSelect() : void |
60
|
|
|
{ |
61
|
|
|
$this->select = []; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function resetDistinct() : void |
65
|
|
|
{ |
66
|
|
|
$this->distinct = false; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public function resetFrom() : void |
70
|
|
|
{ |
71
|
|
|
$this->from = []; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function resetJoin() : void |
75
|
|
|
{ |
76
|
|
|
$this->join = []; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
public function resetSet() : void |
80
|
|
|
{ |
81
|
|
|
$this->set = []; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
public function resetWhere() : void |
85
|
|
|
{ |
86
|
|
|
$this->where = null; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
public function resetGroupBy() : void |
90
|
|
|
{ |
91
|
|
|
$this->groupBy = []; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
public function resetHaving() : void |
95
|
|
|
{ |
96
|
|
|
$this->having = null; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
public function resetOrderBy() : void |
100
|
|
|
{ |
101
|
|
|
$this->orderBy = []; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
public function resetValues() : void |
105
|
|
|
{ |
106
|
|
|
$this->values = []; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* Deep clone of all expression objects in the SQL parts. |
111
|
|
|
*/ |
112
|
|
|
public function __clone() |
113
|
|
|
{ |
114
|
|
|
foreach ($this->from as $key => $from) { |
115
|
|
|
$this->from[$key] = clone $from; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
foreach ($this->join as $fromAlias => $joins) { |
119
|
|
|
foreach ($joins as $key => $join) { |
120
|
|
|
$this->join[$fromAlias][$key] = clone $join; |
121
|
|
|
} |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
if ($this->where !== null) { |
125
|
|
|
$this->where = clone $this->where; |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
if ($this->having !== null) { |
129
|
|
|
$this->having = clone $this->having; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
// @todo What about $values, should they be (deep-)cloned? |
133
|
|
|
// The previous implementation blindly cloned objects and 1-level deep arrays of objects, so this also |
134
|
|
|
// applied to the $sqlParts['values']; was this intentional? I'm not sure. |
135
|
|
|
} |
136
|
|
|
} |
137
|
|
|
|