1 | <?php |
||
20 | class Pgdump extends Abstraction implements Executable |
||
21 | { |
||
22 | /** |
||
23 | * Host to connect to |
||
24 | * --host=<hostname> |
||
25 | * |
||
26 | * @var string |
||
27 | */ |
||
28 | private $host; |
||
29 | |||
30 | /** |
||
31 | * Port to connect to |
||
32 | * --port=<portnumber> |
||
33 | * |
||
34 | * @var string |
||
35 | */ |
||
36 | private $port; |
||
37 | |||
38 | /** |
||
39 | * User to connect with |
||
40 | * --user=<username> |
||
41 | * |
||
42 | * @var string |
||
43 | */ |
||
44 | private $user; |
||
45 | |||
46 | /** |
||
47 | * Password to authenticate with |
||
48 | * --password=<password> |
||
49 | * |
||
50 | * @var string |
||
51 | */ |
||
52 | private $password; |
||
53 | |||
54 | /** |
||
55 | * Database to dump |
||
56 | * db-name |
||
57 | * |
||
58 | * @var string |
||
59 | */ |
||
60 | private $databaseToDump; |
||
61 | |||
62 | /** |
||
63 | * List of schmeas to dump |
||
64 | * --schema=<schema> |
||
65 | * |
||
66 | * @var array |
||
67 | */ |
||
68 | private $schemasToDump = []; |
||
69 | |||
70 | /** |
||
71 | * Exclude Schemas |
||
72 | * --exclude-schema=<schema> |
||
73 | * |
||
74 | * @var array |
||
75 | */ |
||
76 | private $schemasToExclude = []; |
||
77 | |||
78 | /** |
||
79 | * Tables to dump. |
||
80 | * --table=<table> |
||
81 | * |
||
82 | * @var array |
||
83 | */ |
||
84 | private $tablesToDump = []; |
||
85 | |||
86 | /** |
||
87 | * List of tables to exclude |
||
88 | * --exclude-table=<table> |
||
89 | * |
||
90 | * @var array |
||
91 | */ |
||
92 | private $tablesToExclude = []; |
||
93 | |||
94 | /** |
||
95 | * Don't dump the structure |
||
96 | * --data-only |
||
97 | * |
||
98 | * @var boolean |
||
99 | */ |
||
100 | private $dataOnly; |
||
101 | |||
102 | /** |
||
103 | * Dump only schema definitions. |
||
104 | * --schema-only |
||
105 | * |
||
106 | * @var boolean |
||
107 | */ |
||
108 | private $schemaOnly; |
||
109 | |||
110 | /** |
||
111 | * Do not dump data for any tables matching the table pattern. |
||
112 | * --exclude-table-data |
||
113 | * |
||
114 | * @var array |
||
115 | */ |
||
116 | private $excludeTableData = []; |
||
117 | |||
118 | /** |
||
119 | * Add drop statements to the dump. |
||
120 | * --clean |
||
121 | * |
||
122 | * @var boolean |
||
123 | */ |
||
124 | private $clean = false; |
||
125 | |||
126 | /** |
||
127 | * Encoding of the dump file |
||
128 | * --encoding |
||
129 | * |
||
130 | * @var boolean |
||
131 | */ |
||
132 | private $encoding; |
||
133 | |||
134 | /** |
||
135 | * postgreSQLdump format definition |
||
136 | * --format [plain|custom|directory|tar] |
||
137 | * |
||
138 | * @var string |
||
139 | */ |
||
140 | private $format; |
||
141 | |||
142 | /** |
||
143 | * Allow any user to restore the dump |
||
144 | * --no-owner |
||
145 | * |
||
146 | * @var bool |
||
147 | */ |
||
148 | private $noOwner = false; |
||
149 | |||
150 | /** |
||
151 | * Prevent dumping of access privileges. |
||
152 | * --no-acl |
||
153 | * |
||
154 | * @var boolean |
||
155 | */ |
||
156 | private $noPrivileges; |
||
157 | |||
158 | /** |
||
159 | * Do not output commands to select tablespaces. |
||
160 | * --no-tablespaces |
||
161 | * |
||
162 | * @var boolean |
||
163 | */ |
||
164 | private $noTablespaces; |
||
165 | |||
166 | /** |
||
167 | * File to dump to |
||
168 | * --file |
||
169 | * |
||
170 | * @var string |
||
171 | */ |
||
172 | private $file; |
||
173 | |||
174 | /** |
||
175 | * List of available output formats |
||
176 | * |
||
177 | * @var array |
||
178 | */ |
||
179 | private $availableFormats = [ |
||
180 | 'p' => true, |
||
181 | 'plain' => true, |
||
182 | 'c' => true, |
||
183 | 'custom' => true, |
||
184 | 'd' => true, |
||
185 | 'directory' => true, |
||
186 | 't' => true, |
||
187 | 'tar' => true, |
||
188 | ]; |
||
189 | |||
190 | /** |
||
191 | * Constructor. |
||
192 | * |
||
193 | * @param string $path |
||
194 | */ |
||
195 | public function __construct($path = null) |
||
200 | |||
201 | /** |
||
202 | * Set the postgreSQL credentials. |
||
203 | * |
||
204 | * @param string $user |
||
205 | * @param string $password |
||
206 | * @return \phpbu\App\Cli\Executable\Pgdump |
||
207 | */ |
||
208 | public function credentials($user = null, $password = null) |
||
214 | |||
215 | /** |
||
216 | * Set the postgreSQL hostname. |
||
217 | * |
||
218 | * @param string $host |
||
219 | * @return \phpbu\App\Cli\Executable\Pgdump |
||
220 | */ |
||
221 | public function useHost($host) |
||
226 | |||
227 | /** |
||
228 | * Set the postgreSQL port. |
||
229 | * |
||
230 | * @param int $port |
||
231 | * @return \phpbu\App\Cli\Executable\Pgdump |
||
232 | */ |
||
233 | public function usePort($port) |
||
238 | |||
239 | /** |
||
240 | * Set database to dump. |
||
241 | * |
||
242 | * @param string $database |
||
243 | * @return \phpbu\App\Cli\Executable\Pgdump |
||
244 | */ |
||
245 | public function dumpDatabase($database) |
||
250 | |||
251 | /** |
||
252 | * Add drop statements to the dump file. |
||
253 | * Works only on format=plain-text. |
||
254 | * |
||
255 | * @param boolean $bool |
||
256 | * @return \phpbu\App\Cli\Executable\Pgdump |
||
257 | */ |
||
258 | public function addDropStatements($bool) |
||
263 | |||
264 | /** |
||
265 | * Add the --no-owner option so no ownership setting commands will be added. |
||
266 | * |
||
267 | * @param boolean $bool |
||
268 | * @return \phpbu\App\Cli\Executable\Pgdump |
||
269 | */ |
||
270 | public function skipOwnerCommands($bool) |
||
275 | |||
276 | /** |
||
277 | * Set schemas to dump. |
||
278 | * |
||
279 | * @param array $schemas |
||
280 | * @return \phpbu\App\Cli\Executable\Pgdump |
||
281 | */ |
||
282 | public function dumpSchemas(array $schemas) |
||
287 | |||
288 | /** |
||
289 | * Set schemas to exclude. |
||
290 | * |
||
291 | * @param array $schemas |
||
292 | * @return \phpbu\App\Cli\Executable\Pgdump |
||
293 | */ |
||
294 | public function excludeSchemas(array $schemas) |
||
299 | |||
300 | /** |
||
301 | * Set tables to dump. |
||
302 | * |
||
303 | * @param array $tables |
||
304 | * @return \phpbu\App\Cli\Executable\Pgdump |
||
305 | */ |
||
306 | public function dumpTables(array $tables) |
||
311 | |||
312 | /** |
||
313 | * Set tables to ignore. |
||
314 | * |
||
315 | * @param array $tables |
||
316 | * @return \phpbu\App\Cli\Executable\Pgdump |
||
317 | */ |
||
318 | public function excludeTables(array $tables) |
||
323 | |||
324 | /** |
||
325 | * Set tables where no data is dumped. |
||
326 | * |
||
327 | * @param array $tables |
||
328 | * @return \phpbu\App\Cli\Executable\Pgdump |
||
329 | */ |
||
330 | public function excludeTableData(array $tables) |
||
335 | |||
336 | /** |
||
337 | * Dump only the schema information. |
||
338 | * |
||
339 | * @param boolean $bool |
||
340 | * @return \phpbu\App\Cli\Executable\Pgdump |
||
341 | * @throws \phpbu\App\Exception |
||
342 | */ |
||
343 | public function dumpSchemaOnly($bool) |
||
351 | |||
352 | /** |
||
353 | * Dump no schema information. |
||
354 | * |
||
355 | * @param boolean $bool |
||
356 | * @return \phpbu\App\Cli\Executable\Pgdump |
||
357 | * @throws \phpbu\App\Exception |
||
358 | */ |
||
359 | public function dumpDataOnly($bool) |
||
367 | |||
368 | /** |
||
369 | * Set the dump target path. |
||
370 | * |
||
371 | * @param string $path |
||
372 | * @return \phpbu\App\Cli\Executable\Pgdump |
||
373 | */ |
||
374 | public function dumpTo($path) |
||
379 | |||
380 | /** |
||
381 | * Set the dump format. |
||
382 | * |
||
383 | * @param string $format |
||
384 | * @return \phpbu\App\Cli\Executable\Pgdump |
||
385 | * @throws \phpbu\App\Exception |
||
386 | */ |
||
387 | public function dumpFormat($format) |
||
395 | |||
396 | /** |
||
397 | * Do not dump commands setting ownership. |
||
398 | * --no-owner |
||
399 | * |
||
400 | * @param $bool |
||
401 | * @return \phpbu\App\Cli\Executable\Pgdump |
||
402 | */ |
||
403 | public function dumpNoOwner($bool) |
||
408 | |||
409 | /** |
||
410 | * Do not output commands to select tablespaces. |
||
411 | * --no-tablespaces |
||
412 | * |
||
413 | * @param boolean $bool |
||
414 | * @return \phpbu\App\Cli\Executable\Pgdump |
||
415 | */ |
||
416 | public function dumpNoTablespaces($bool) |
||
421 | |||
422 | /** |
||
423 | * Prevent dumping of access privileges. |
||
424 | * --no-acl |
||
425 | * |
||
426 | * @param boolean $bool |
||
427 | * @return \phpbu\App\Cli\Executable\Pgdump |
||
428 | */ |
||
429 | public function dumpNoPrivileges($bool) |
||
434 | /** |
||
435 | * Set the output file encoding. |
||
436 | * |
||
437 | * @param string $encoding |
||
438 | * @return \phpbu\App\Cli\Executable\Pgdump |
||
439 | */ |
||
440 | public function encode($encoding) |
||
445 | |||
446 | /** |
||
447 | * Process generator. |
||
448 | * |
||
449 | * @return \phpbu\App\Cli\Process |
||
450 | */ |
||
451 | protected function createProcess() |
||
497 | } |
||
498 |
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.