AdminerDumpZip::dumpOutput()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
c 2
b 0
f 0
nc 2
nop 0
dl 0
loc 6
rs 9.4285
1
<?php
2
3
/** Dump to ZIP format
4
* @link https://www.adminer.org/plugins/#use
5
* @uses ZipArchive, tempnam("")
6
* @author Jakub Vrana, http://www.vrana.cz/
7
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
8
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2 (one or other)
9
*/
10
class AdminerDumpZip {
11
	/** @access protected */
12
	var $filename, $data;
13
14
	function dumpOutput() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
15
		if (!class_exists('ZipArchive')) {
16
			return array();
17
		}
18
		return array('zip' => 'ZIP');
19
	}
20
21
	function _zip($string, $state) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
22
		// ZIP can be created without temporary file by gzcompress - see PEAR File_Archive
23
		$this->data .= $string;
24
		if ($state & PHP_OUTPUT_HANDLER_END) {
25
			$zip = new ZipArchive;
26
			$zipFile = tempnam('', 'zip');
27
			$zip->open($zipFile, ZipArchive::OVERWRITE); // php://output is not supported
28
			$zip->addFromString($this->filename, $this->data);
29
			$zip->close();
30
			$return = file_get_contents($zipFile);
31
			unlink($zipFile);
32
			return $return;
33
		}
34
		return '';
35
	}
36
37
	function dumpHeaders($identifier, $multi_table = false) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
38
		if ($_POST['output'] == 'zip') {
39
			$this->filename = "$identifier." . ($multi_table && preg_match('~[ct]sv~', $_POST['format']) ? 'tar' : $_POST['format']);
40
			header('Content-Type: application/zip');
41
			ob_start(array($this, '_zip'));
42
		}
43
	}
44
45
}
46