1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace BfwSql\Queries\Parts; |
4
|
|
|
|
5
|
|
|
use \BfwSql\Queries\AbstractQuery; |
6
|
|
|
|
7
|
|
|
abstract class AbstractPart implements PartInterface |
8
|
|
|
{ |
9
|
|
|
/** |
10
|
|
|
* @const ERR_INVOKE_PART_DISABLED Exception code when invoke is used |
11
|
|
|
* with a part which is disabled. |
12
|
|
|
*/ |
13
|
|
|
const ERR_INVOKE_PART_DISABLED = 2502001; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @var \BfwSql\Queries\AbstractQuery $querySystem The object who generate |
17
|
|
|
* the full query |
18
|
|
|
*/ |
19
|
|
|
protected $querySystem; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @var string $tablePrefix The prefix to use which all table into the base |
23
|
|
|
*/ |
24
|
|
|
protected $tablePrefix = ''; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var string $partPrefix The prefix to use before this query part |
28
|
|
|
*/ |
29
|
|
|
protected $partPrefix = ''; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var boolean $usePartPrefix If the part don't have prefix |
33
|
|
|
*/ |
34
|
|
|
protected $usePartPrefix = true; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var boolean $canBeEmpty If the query part generated can be empty |
38
|
|
|
* Example : The FROM part can not be empty for a SELECT query |
39
|
|
|
*/ |
40
|
|
|
protected $canBeEmpty = true; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* |
44
|
|
|
* @var bool $isDisabled Define if the current part is disabled (or not) |
45
|
|
|
* for the specific SGBD. |
46
|
|
|
*/ |
47
|
|
|
protected $isDisabled = false; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Define querySystem property and find the tablePrefix |
51
|
|
|
* |
52
|
|
|
* @param \BfwSql\Queries\AbstractQuery $querySystem |
53
|
|
|
*/ |
54
|
|
|
public function __construct(AbstractQuery $querySystem) |
55
|
|
|
{ |
56
|
|
|
$this->querySystem = $querySystem; |
57
|
|
|
$this->tablePrefix = $querySystem |
58
|
|
|
->getSqlConnect() |
59
|
|
|
->getConnectionInfos() |
60
|
|
|
->tablePrefix |
61
|
|
|
; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Getter accessor to property querySystem |
66
|
|
|
* |
67
|
|
|
* @return \BfwSql\Queries\AbstractQuery |
68
|
|
|
*/ |
69
|
|
|
public function getQuerySystem(): AbstractQuery |
70
|
|
|
{ |
71
|
|
|
return $this->querySystem; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Getter accessor to property tablePrefix |
76
|
|
|
* |
77
|
|
|
* @return string |
78
|
|
|
*/ |
79
|
|
|
public function getTablePrefix(): string |
80
|
|
|
{ |
81
|
|
|
return $this->tablePrefix; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Getter accessor to property partPrefix |
86
|
|
|
* |
87
|
|
|
* @return string |
88
|
|
|
*/ |
89
|
|
|
public function getPartPrefix(): string |
90
|
|
|
{ |
91
|
|
|
return $this->partPrefix; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Getter accessor to property usePartPrefix |
96
|
|
|
* |
97
|
|
|
* @return bool |
98
|
|
|
*/ |
99
|
|
|
public function getUsePartPrefix(): bool |
100
|
|
|
{ |
101
|
|
|
return $this->usePartPrefix; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* Getter accessor to property canBeEmpty |
106
|
|
|
* |
107
|
|
|
* @return bool |
108
|
|
|
*/ |
109
|
|
|
public function getCanBeEmpty(): bool |
110
|
|
|
{ |
111
|
|
|
return $this->canBeEmpty; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* Getter accessor to property canBeEmpty |
116
|
|
|
* |
117
|
|
|
* @return bool |
118
|
|
|
*/ |
119
|
|
|
public function getIsDisabled(): bool |
120
|
|
|
{ |
121
|
|
|
return $this->isDisabled; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* Setter accessor to property canBeEmpty |
126
|
|
|
* |
127
|
|
|
* @param bool $isDisabled new value for isDisabled |
128
|
|
|
* |
129
|
|
|
* @return $this |
130
|
|
|
*/ |
131
|
|
|
public function setIsDisabled(bool $isDisabled): self |
132
|
|
|
{ |
133
|
|
|
$this->isDisabled = $isDisabled; |
134
|
|
|
return $this; |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* Check if the part is disabled, and throw an Exception if it is. |
139
|
|
|
* Should be use in __invoke method. |
140
|
|
|
* |
141
|
|
|
* @throws \Exception |
142
|
|
|
* |
143
|
|
|
* @return void |
144
|
|
|
*/ |
145
|
|
|
protected function invokeCheckIsDisabled() |
146
|
|
|
{ |
147
|
|
|
if ($this->isDisabled === true) { |
148
|
|
|
throw new \Exception( |
149
|
|
|
'This query part is disabled for the used SGBD.', |
150
|
|
|
self::ERR_INVOKE_PART_DISABLED |
151
|
|
|
); |
152
|
|
|
} |
153
|
|
|
} |
154
|
|
|
} |
155
|
|
|
|