1 | <?php |
||
11 | class SQLDumper |
||
12 | { |
||
13 | /** |
||
14 | * @var string Host for the DB connection |
||
15 | */ |
||
16 | protected $host = ''; |
||
17 | |||
18 | /** |
||
19 | * @var string Name of the DB |
||
20 | */ |
||
21 | protected $dbname = ''; |
||
22 | |||
23 | /** |
||
24 | * @var string Username used for the DB connection |
||
25 | */ |
||
26 | protected $username = ''; |
||
27 | |||
28 | /** |
||
29 | * @var string Password used for the DB connection |
||
30 | */ |
||
31 | protected $password = ''; |
||
32 | |||
33 | /** |
||
34 | * @var PDO PDO instance of the DB |
||
35 | */ |
||
36 | protected $db = NULL; |
||
37 | |||
38 | /** |
||
39 | * @var TableDumperCollection Contains all TableDumper objects that will be used for this dump |
||
40 | */ |
||
41 | protected $listTableDumpers; |
||
42 | |||
43 | /** |
||
44 | * @var boolean Determines if DROP statements should be grouped together |
||
45 | */ |
||
46 | protected $groupDrops = false; |
||
47 | |||
48 | /** |
||
49 | * @var boolean Determines if INSERT statements should be grouped together |
||
50 | */ |
||
51 | protected $groupInserts = false; |
||
52 | |||
53 | |||
54 | /** |
||
55 | * @param string Host for the DB connection |
||
56 | * @param string Name of the DB |
||
57 | * @param string Username used for the DB connection |
||
58 | * @param string Password used for the DB connection |
||
59 | */ |
||
60 | 45 | public function __construct(string $host, string $dbname, string $username, string $password = '') |
|
71 | |||
72 | /** |
||
73 | * Connects to the SQL database |
||
74 | * |
||
75 | * @return void |
||
76 | */ |
||
77 | 45 | protected function connect(): void |
|
88 | |||
89 | /** |
||
90 | * Get the main list of TableDumper |
||
91 | * |
||
92 | * @return TableDumperCollection Returns the list of table dumpers as TableDumperCollection |
||
93 | */ |
||
94 | 3 | public function getListTableDumpers(): TableDumperCollection |
|
98 | |||
99 | /** |
||
100 | * Set a TableDumper for the given table in order to specify certain dump options on it |
||
101 | * |
||
102 | * @param Table|string The table to set |
||
103 | * |
||
104 | * @return TableDumper Returns a TableDumper |
||
105 | */ |
||
106 | 27 | public function table($table): TableDumper |
|
110 | |||
111 | /** |
||
112 | * Set a TableDumperCollection for the given list of tables in order to specify certain dump options on them |
||
113 | * |
||
114 | * @param TableDumperCollection|array<TableDumper|Table|string> The list of tables to set (either as a TableDumperCollection, or an array containing either TableDumper objects, Table objects or table names) |
||
115 | * |
||
116 | * @return TableDumperCollection Returns a TableDumperCollection |
||
117 | */ |
||
118 | 15 | public function listTables($listTables): TableDumperCollection |
|
122 | |||
123 | /** |
||
124 | * Set a TableDumperCollection for all the tables in the database, in order to specify certain dump options on them |
||
125 | * |
||
126 | * @return TableDumperCollection Returns a TableDumperCollection |
||
127 | */ |
||
128 | 9 | public function allTables(): TableDumperCollection |
|
143 | |||
144 | /** |
||
145 | * Writes the complete dump of the database to the given stream |
||
146 | * |
||
147 | * @param resource Stream to write to |
||
148 | * |
||
149 | * @return void |
||
150 | */ |
||
151 | 27 | public function dump($stream): void |
|
160 | |||
161 | /** |
||
162 | * Creates and saves the dump to a file |
||
163 | * |
||
164 | * @param string File name for the dump |
||
165 | * |
||
166 | * @return void |
||
167 | */ |
||
168 | 3 | public function save(string $filename): void |
|
175 | |||
176 | /** |
||
177 | * Set parameter that determines if DROP statements should be grouped together |
||
178 | * @param bool $group Set to TRUE if it should be grouped, FALSE otherwise |
||
179 | * @return void |
||
180 | */ |
||
181 | 3 | public function groupDrops(bool $group): void |
|
185 | |||
186 | /** |
||
187 | * Set parameter that determines if INSERT statements should be grouped together |
||
188 | * @param bool $group Set to TRUE if it should be grouped, FALSE otherwise |
||
189 | * @return void |
||
190 | */ |
||
191 | 3 | public function groupInserts(bool $group): void |
|
195 | } |