|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* neuralyzer : Data Anonymization Library and CLI Tool |
|
4
|
|
|
* |
|
5
|
|
|
* PHP Version 7.1 |
|
6
|
|
|
* |
|
7
|
|
|
* @author Emmanuel Dyan |
|
8
|
|
|
* @copyright 2018 Emmanuel Dyan |
|
9
|
|
|
* |
|
10
|
|
|
* @package edyan/neuralyzer |
|
11
|
|
|
* |
|
12
|
|
|
* @license GNU General Public License v2.0 |
|
13
|
|
|
* |
|
14
|
|
|
* @link https://github.com/edyan/neuralyzer |
|
15
|
|
|
*/ |
|
16
|
|
|
|
|
17
|
|
|
namespace Edyan\Neuralyzer\Helper\DB; |
|
18
|
|
|
|
|
19
|
|
|
use Doctrine\DBAL\Connection; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Various methods to help interacting with DB servers |
|
23
|
|
|
*/ |
|
24
|
|
|
abstract class AbstractDBHelper |
|
25
|
|
|
{ |
|
26
|
|
|
/** |
|
27
|
|
|
* Execute (or not) queries |
|
28
|
|
|
* @var bool |
|
29
|
|
|
*/ |
|
30
|
|
|
public $pretend = false; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* DBAL connection |
|
34
|
|
|
* @var Connection |
|
35
|
|
|
*/ |
|
36
|
|
|
public $conn = null; |
|
37
|
|
|
|
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Requires a connection to work |
|
41
|
|
|
* |
|
42
|
|
|
* @param Connection $conn |
|
43
|
|
|
*/ |
|
44
|
75 |
|
public function __construct(Connection $conn) |
|
45
|
|
|
{ |
|
46
|
75 |
|
$this->conn = $conn; |
|
47
|
75 |
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Set Pretend to true to simulate queries, false to execute interface |
|
51
|
|
|
* |
|
52
|
|
|
* @param bool $pretend |
|
53
|
|
|
* |
|
54
|
|
|
* @return AbstractDBHelper |
|
55
|
|
|
*/ |
|
56
|
10 |
|
public function setPretend(bool $pretend): AbstractDBHelper |
|
57
|
|
|
{ |
|
58
|
10 |
|
$this->pretend = $pretend; |
|
59
|
|
|
|
|
60
|
10 |
|
return $this; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Get, for a driver options for connection (PDO) |
|
65
|
|
|
* |
|
66
|
|
|
* @return array |
|
67
|
|
|
*/ |
|
68
|
70 |
|
public static function getDriverOptions(): array |
|
69
|
|
|
{ |
|
70
|
70 |
|
return []; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* Set the right enclosure |
|
75
|
|
|
* @return string |
|
76
|
|
|
*/ |
|
77
|
1 |
|
public function getEnclosureForCSV(): string |
|
78
|
|
|
{ |
|
79
|
1 |
|
return '"'; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* Register doctrine custom types for driver |
|
84
|
|
|
* |
|
85
|
|
|
* @return void |
|
86
|
|
|
*/ |
|
87
|
33 |
|
public function registerCustomTypes(): void |
|
88
|
|
|
{ |
|
89
|
33 |
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* Load Data from a CSV |
|
93
|
|
|
* |
|
94
|
|
|
* @param string $table |
|
95
|
|
|
* @param string $fname File's name |
|
96
|
|
|
* @param array $fields |
|
97
|
|
|
* @param string $mode |
|
98
|
|
|
* |
|
99
|
|
|
* @return string |
|
100
|
|
|
*/ |
|
101
|
|
|
abstract public function loadData(string $table, string $fname, array $fields, string $mode): string; |
|
102
|
|
|
} |
|
103
|
|
|
|