1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Phuria\QueryBuilder\Table; |
4
|
|
|
|
5
|
|
|
use Phuria\QueryBuilder\QueryBuilder; |
6
|
|
|
use Phuria\QueryBuilder\ReferenceManager; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* @author Beniamin Jonatan Šimko <[email protected]> |
10
|
|
|
*/ |
11
|
|
|
abstract class AbstractTable |
12
|
|
|
{ |
13
|
|
|
const CROSS_JOIN = 'CROSS JOIN'; |
14
|
|
|
const LEFT_JOIN = 'LEFT JOIN'; |
15
|
|
|
const INNER_JOIN = 'INNER JOIN'; |
16
|
|
|
|
17
|
|
|
const ROOT_FROM = 1; |
18
|
|
|
const ROOT_UPDATE = 2; |
19
|
|
|
const ROOT_INSERT = 3; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @var QueryBuilder $qb |
23
|
|
|
*/ |
24
|
|
|
private $qb; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var string $tableAlias |
28
|
|
|
*/ |
29
|
|
|
private $tableAlias; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var string $joinType |
33
|
|
|
*/ |
34
|
|
|
private $joinType; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var int $root |
38
|
|
|
*/ |
39
|
|
|
private $rootType; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @var string $joinOn |
43
|
|
|
*/ |
44
|
|
|
private $joinOn; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @var bool $join |
48
|
|
|
*/ |
49
|
|
|
private $join = false; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @param QueryBuilder $qb |
53
|
|
|
*/ |
54
|
27 |
|
public function __construct(QueryBuilder $qb) |
55
|
|
|
{ |
56
|
27 |
|
$this->qb = $qb; |
57
|
27 |
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @return ReferenceManager |
|
|
|
|
61
|
|
|
*/ |
62
|
17 |
|
public function __toString() |
63
|
|
|
{ |
64
|
17 |
|
return $this->qb->getReferenceManager()->register($this); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @return string |
69
|
|
|
*/ |
70
|
|
|
abstract public function getTableName(); |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @return QueryBuilder |
74
|
|
|
*/ |
75
|
1 |
|
public function getQueryBuilder() |
76
|
|
|
{ |
77
|
1 |
|
return $this->qb; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @return string |
82
|
|
|
*/ |
83
|
25 |
|
public function getAlias() |
84
|
|
|
{ |
85
|
25 |
|
return $this->tableAlias; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @param string $alias |
90
|
|
|
* |
91
|
|
|
* @return $this |
92
|
|
|
*/ |
93
|
8 |
|
public function setAlias($alias) |
94
|
|
|
{ |
95
|
8 |
|
$this->tableAlias = $alias; |
96
|
|
|
|
97
|
8 |
|
return $this; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @return bool |
102
|
|
|
*/ |
103
|
25 |
|
public function isJoin() |
104
|
|
|
{ |
105
|
25 |
|
return $this->join; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* @return string |
110
|
|
|
*/ |
111
|
3 |
|
public function getJoinType() |
112
|
|
|
{ |
113
|
3 |
|
return $this->joinType; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* @param string $joinType |
118
|
|
|
* |
119
|
|
|
* @return $this |
120
|
|
|
*/ |
121
|
3 |
|
public function setJoinType($joinType) |
122
|
|
|
{ |
123
|
3 |
|
$this->joinType = $joinType; |
124
|
3 |
|
$this->join = true; |
125
|
|
|
|
126
|
3 |
|
return $this; |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* @return bool |
131
|
|
|
*/ |
132
|
25 |
|
public function isRoot() |
133
|
|
|
{ |
134
|
25 |
|
return null !== $this->rootType; |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* @param int $rootType |
139
|
|
|
* |
140
|
|
|
* @return $this |
141
|
|
|
*/ |
142
|
27 |
|
public function setRootType($rootType) |
143
|
|
|
{ |
144
|
27 |
|
$this->rootType = $rootType; |
145
|
|
|
|
146
|
27 |
|
return $this; |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
/** |
150
|
|
|
* @return int |
151
|
|
|
*/ |
152
|
25 |
|
public function getRootType() |
153
|
|
|
{ |
154
|
25 |
|
return $this->rootType; |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* @return string |
159
|
|
|
*/ |
160
|
17 |
|
public function getAliasOrName() |
161
|
|
|
{ |
162
|
17 |
|
return $this->getAlias() ?: $this->getTableName(); |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
/** |
166
|
|
|
* @param string $clause |
167
|
|
|
* |
168
|
|
|
* @return $this |
169
|
|
|
*/ |
170
|
5 |
|
public function addSelect($clause) |
171
|
|
|
{ |
172
|
5 |
|
$this->qb->addSelect($clause); |
173
|
|
|
|
174
|
5 |
|
return $this; |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
/** |
178
|
|
|
* @param string $clause |
179
|
|
|
* |
180
|
|
|
* @return $this |
181
|
|
|
*/ |
182
|
2 |
|
public function joinOn($clause) |
183
|
|
|
{ |
184
|
2 |
|
$this->joinOn = $clause; |
185
|
|
|
|
186
|
2 |
|
return $this; |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
/** |
190
|
|
|
* @return string |
191
|
|
|
*/ |
192
|
25 |
|
public function getJoinOn() |
193
|
|
|
{ |
194
|
25 |
|
return $this->joinOn; |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
/** |
198
|
|
|
* @param string $name |
199
|
|
|
* |
200
|
|
|
* @return string |
201
|
|
|
*/ |
202
|
17 |
|
public function column($name) |
203
|
|
|
{ |
204
|
17 |
|
return $this . '.' . $name; |
205
|
|
|
} |
206
|
|
|
} |
This check compares the return type specified in the
@return
annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.