Completed
Pull Request — master (#2)
by Michael
07:48
created

include/plugins/dump-json.php (11 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
/** Dump to JSON format
4
* @link https://www.adminer.org/plugins/#use
5
* @author Jakub Vrana, http://www.vrana.cz/
6
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
7
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2 (one or other)
8
*/
9
class AdminerDumpJson {
10
	/** @access protected */
11
	var $database = false;
12
	
13
	function dumpFormat() {
0 ignored issues
show
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...
14
		return array('json' => 'JSON');
15
	}
16
17
	function dumpTable($table, $style, $is_view = false) {
0 ignored issues
show
The parameter $table is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
The parameter $style is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
The parameter $is_view is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
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...
18
		if ($_POST['format'] == 'json') {
19
			return true;
20
		}
21
	}
22
	
23
	function _database() {
0 ignored issues
show
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...
24
		echo "}\n";
25
	}
26
	
27
	function dumpData($table, $style, $query) {
0 ignored issues
show
The parameter $style is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
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...
28
		if ($_POST['format'] == 'json') {
29
			if ($this->database) {
30
				echo ",\n";
31
			} else {
32
				$this->database = true;
33
				echo "{\n";
34
				register_shutdown_function(array($this, '_database'));
35
			}
36
			$connection = connection();
37
			$result = $connection->query($query, 1);
38
			if ($result) {
39
				echo '"' . addcslashes($table, "\r\n\"\\") . "\": [\n";
40
				$first = true;
41
				while ($row = $result->fetch_assoc()) {
42
					echo ($first ? '' : ', ');
43
					$first = false;
44
					foreach ($row as $key => $val) {
45
						json_row($key, $val);
46
					}
47
					json_row('');
48
				}
49
				echo ']';
50
			}
51
			return true;
52
		}
53
	}
54
55
	function dumpHeaders($identifier, $multi_table = false) {
0 ignored issues
show
The parameter $identifier is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
The parameter $multi_table is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
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...
56
		if ($_POST['format'] == 'json') {
57
			header('Content-Type: application/json; charset=utf-8');
58
			return 'json';
59
		}
60
	}
61
62
}
63