|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Coco\SourceWatcher\Core\Database\Connections; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* Class PostgreSqlConnector |
|
7
|
|
|
* @package Coco\SourceWatcher\Core\Database\Connections |
|
8
|
|
|
* |
|
9
|
|
|
* Following the definition from: https://www.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#pdo-pgsql |
|
10
|
|
|
*/ |
|
11
|
|
|
class PostgreSqlConnector extends ClientServerDatabaseConnector |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* @var string |
|
15
|
|
|
*/ |
|
16
|
|
|
protected string $charset = ""; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @var string |
|
20
|
|
|
*/ |
|
21
|
|
|
protected string $defaultDatabaseName = ""; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @var string |
|
25
|
|
|
*/ |
|
26
|
|
|
protected string $sslMode = ""; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @var string |
|
30
|
|
|
*/ |
|
31
|
|
|
protected string $sslRootCert = ""; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @var string |
|
35
|
|
|
*/ |
|
36
|
|
|
protected string $sslCert = ""; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @var string |
|
40
|
|
|
*/ |
|
41
|
|
|
protected string $sslKey = ""; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @var string |
|
45
|
|
|
*/ |
|
46
|
|
|
protected string $sslCrl = ""; |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @var string |
|
50
|
|
|
*/ |
|
51
|
|
|
protected string $applicationName = ""; |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* PostgreSqlConnector constructor. |
|
55
|
|
|
*/ |
|
56
|
|
|
public function __construct () |
|
57
|
|
|
{ |
|
58
|
|
|
$this->driver = "pdo_pgsql"; |
|
59
|
|
|
|
|
60
|
|
|
$this->port = 5432; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @return string |
|
65
|
|
|
*/ |
|
66
|
|
|
public function getCharset () : string |
|
67
|
|
|
{ |
|
68
|
|
|
return $this->charset; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* @param string $charset |
|
73
|
|
|
*/ |
|
74
|
|
|
public function setCharset ( string $charset ) : void |
|
75
|
|
|
{ |
|
76
|
|
|
$this->charset = $charset; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* @return string |
|
81
|
|
|
*/ |
|
82
|
|
|
public function getDefaultDatabaseName () : string |
|
83
|
|
|
{ |
|
84
|
|
|
return $this->defaultDatabaseName; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* @param string $defaultDatabaseName |
|
89
|
|
|
*/ |
|
90
|
|
|
public function setDefaultDatabaseName ( string $defaultDatabaseName ) : void |
|
91
|
|
|
{ |
|
92
|
|
|
$this->defaultDatabaseName = $defaultDatabaseName; |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* @return string |
|
97
|
|
|
*/ |
|
98
|
|
|
public function getSslMode () : string |
|
99
|
|
|
{ |
|
100
|
|
|
return $this->sslMode; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* @param string $sslMode |
|
105
|
|
|
*/ |
|
106
|
|
|
public function setSslMode ( string $sslMode ) : void |
|
107
|
|
|
{ |
|
108
|
|
|
$this->sslMode = $sslMode; |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* @return string |
|
113
|
|
|
*/ |
|
114
|
|
|
public function getSslRootCert () : string |
|
115
|
|
|
{ |
|
116
|
|
|
return $this->sslRootCert; |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
/** |
|
120
|
|
|
* @param string $sslRootCert |
|
121
|
|
|
*/ |
|
122
|
|
|
public function setSslRootCert ( string $sslRootCert ) : void |
|
123
|
|
|
{ |
|
124
|
|
|
$this->sslRootCert = $sslRootCert; |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
/** |
|
128
|
|
|
* @return string |
|
129
|
|
|
*/ |
|
130
|
|
|
public function getSslCert () : string |
|
131
|
|
|
{ |
|
132
|
|
|
return $this->sslCert; |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
/** |
|
136
|
|
|
* @param string $sslCert |
|
137
|
|
|
*/ |
|
138
|
|
|
public function setSslCert ( string $sslCert ) : void |
|
139
|
|
|
{ |
|
140
|
|
|
$this->sslCert = $sslCert; |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
|
|
/** |
|
144
|
|
|
* @return string |
|
145
|
|
|
*/ |
|
146
|
|
|
public function getSslKey () : string |
|
147
|
|
|
{ |
|
148
|
|
|
return $this->sslKey; |
|
149
|
|
|
} |
|
150
|
|
|
|
|
151
|
|
|
/** |
|
152
|
|
|
* @param string $sslKey |
|
153
|
|
|
*/ |
|
154
|
|
|
public function setSslKey ( string $sslKey ) : void |
|
155
|
|
|
{ |
|
156
|
|
|
$this->sslKey = $sslKey; |
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
|
|
/** |
|
160
|
|
|
* @return string |
|
161
|
|
|
*/ |
|
162
|
|
|
public function getSslCrl () : string |
|
163
|
|
|
{ |
|
164
|
|
|
return $this->sslCrl; |
|
165
|
|
|
} |
|
166
|
|
|
|
|
167
|
|
|
/** |
|
168
|
|
|
* @param string $sslCrl |
|
169
|
|
|
*/ |
|
170
|
|
|
public function setSslCrl ( string $sslCrl ) : void |
|
171
|
|
|
{ |
|
172
|
|
|
$this->sslCrl = $sslCrl; |
|
173
|
|
|
} |
|
174
|
|
|
|
|
175
|
|
|
/** |
|
176
|
|
|
* @return string |
|
177
|
|
|
*/ |
|
178
|
|
|
public function getApplicationName () : string |
|
179
|
|
|
{ |
|
180
|
|
|
return $this->applicationName; |
|
181
|
|
|
} |
|
182
|
|
|
|
|
183
|
|
|
/** |
|
184
|
|
|
* @param string $applicationName |
|
185
|
|
|
*/ |
|
186
|
|
|
public function setApplicationName ( string $applicationName ) : void |
|
187
|
|
|
{ |
|
188
|
|
|
$this->applicationName = $applicationName; |
|
189
|
|
|
} |
|
190
|
|
|
|
|
191
|
|
|
/** |
|
192
|
|
|
* @return array |
|
193
|
|
|
*/ |
|
194
|
|
|
protected function getConnectionParameters () : array |
|
195
|
|
|
{ |
|
196
|
|
|
$this->connectionParameters = array(); |
|
197
|
|
|
|
|
198
|
|
|
$this->connectionParameters["driver"] = $this->driver; |
|
199
|
|
|
$this->connectionParameters["user"] = $this->user; |
|
200
|
|
|
$this->connectionParameters["password"] = $this->password; |
|
201
|
|
|
$this->connectionParameters["host"] = $this->host; |
|
202
|
|
|
$this->connectionParameters["port"] = $this->port; |
|
203
|
|
|
$this->connectionParameters["dbname"] = $this->dbName; |
|
204
|
|
|
|
|
205
|
|
|
$this->connectionParameters["charset"] = $this->charset; |
|
206
|
|
|
$this->connectionParameters["default_dbname"] = $this->defaultDatabaseName; |
|
207
|
|
|
$this->connectionParameters["sslmode"] = $this->sslMode; |
|
208
|
|
|
$this->connectionParameters["sslrootcert"] = $this->sslRootCert; |
|
209
|
|
|
$this->connectionParameters["sslcert"] = $this->sslCert; |
|
210
|
|
|
$this->connectionParameters["sslkey"] = $this->sslKey; |
|
211
|
|
|
$this->connectionParameters["sslcrl"] = $this->sslCrl; |
|
212
|
|
|
$this->connectionParameters["application_name"] = $this->applicationName; |
|
213
|
|
|
|
|
214
|
|
|
return $this->connectionParameters; |
|
215
|
|
|
} |
|
216
|
|
|
} |
|
217
|
|
|
|