1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Coco\SourceWatcher\Core\Database\Connections; |
4
|
|
|
|
5
|
|
|
use Coco\SourceWatcher\Core\Row; |
6
|
|
|
use Doctrine\DBAL\Connection; |
7
|
|
|
|
8
|
|
|
abstract class Connector |
9
|
|
|
{ |
10
|
|
|
protected string $driver = ""; |
11
|
|
|
protected array $connectionParameters = []; |
12
|
|
|
|
13
|
|
|
protected string $user; |
14
|
|
|
protected string $password; |
15
|
|
|
protected string $host; |
16
|
|
|
protected int $port; |
17
|
|
|
protected string $dbName; |
18
|
|
|
|
19
|
|
|
protected string $tableName = ""; |
20
|
|
|
|
21
|
|
|
public abstract function connect () : Connection; |
22
|
|
|
|
23
|
|
|
public abstract function insert ( Row $row ) : void; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @return string |
27
|
|
|
*/ |
28
|
|
|
public function getDriver () : string |
29
|
|
|
{ |
30
|
|
|
return $this->driver; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
protected abstract function getConnectionParameters () : array; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @return string |
37
|
|
|
*/ |
38
|
|
|
public function getUser () : string |
39
|
|
|
{ |
40
|
|
|
return $this->user; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @param string $user |
45
|
|
|
*/ |
46
|
|
|
public function setUser ( string $user ) : void |
47
|
|
|
{ |
48
|
|
|
$this->user = $user; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @return string |
53
|
|
|
*/ |
54
|
|
|
public function getPassword () : string |
55
|
|
|
{ |
56
|
|
|
return $this->password; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @param string $password |
61
|
|
|
*/ |
62
|
|
|
public function setPassword ( string $password ) : void |
63
|
|
|
{ |
64
|
|
|
$this->password = $password; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @return string |
69
|
|
|
*/ |
70
|
|
|
public function getHost () : string |
71
|
|
|
{ |
72
|
|
|
return $this->host; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @param string $host |
77
|
|
|
*/ |
78
|
|
|
public function setHost ( string $host ) : void |
79
|
|
|
{ |
80
|
|
|
$this->host = $host; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @return int |
85
|
|
|
*/ |
86
|
|
|
public function getPort () : int |
87
|
|
|
{ |
88
|
|
|
return $this->port; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @param int $port |
93
|
|
|
*/ |
94
|
|
|
public function setPort ( int $port ) : void |
95
|
|
|
{ |
96
|
|
|
$this->port = $port; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @return string |
101
|
|
|
*/ |
102
|
|
|
public function getDbName () : string |
103
|
|
|
{ |
104
|
|
|
return $this->dbName; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* @param string $dbName |
109
|
|
|
*/ |
110
|
|
|
public function setDbName ( string $dbName ) : void |
111
|
|
|
{ |
112
|
|
|
$this->dbName = $dbName; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* @return string |
117
|
|
|
*/ |
118
|
|
|
public function getTableName () : string |
119
|
|
|
{ |
120
|
|
|
return $this->tableName; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* @param string $tableName |
125
|
|
|
*/ |
126
|
|
|
public function setTableName ( string $tableName ) : void |
127
|
|
|
{ |
128
|
|
|
$this->tableName = $tableName; |
129
|
|
|
} |
130
|
|
|
} |
131
|
|
|
|