From 54f8d731b320101ea7712306a74fafd9381261b9 Mon Sep 17 00:00:00 2001 From: Jakub Vrana Date: Fri, 28 Mar 2025 09:57:33 +0100 Subject: [PATCH] Doc-comments: Sync method signatures --- adminer/drivers/mssql.inc.php | 30 ++++++++++---------- adminer/drivers/mysql.inc.php | 34 +++++++++++----------- adminer/drivers/oracle.inc.php | 24 ++++++++-------- adminer/drivers/pgsql.inc.php | 44 ++++++++++++++-------------- adminer/drivers/sqlite.inc.php | 30 ++++++++++---------- adminer/include/driver.inc.php | 2 +- adminer/include/pdo.inc.php | 12 ++++---- plugins/drivers/clickhouse.php | 26 +++++++---------- plugins/drivers/elastic.php | 23 +++++++-------- plugins/drivers/firebird.php | 16 +++++------ plugins/drivers/imap.php | 14 ++++----- plugins/drivers/mongo.php | 52 ++++++++++++++++------------------ plugins/drivers/simpledb.php | 24 ++++++++-------- 13 files changed, 161 insertions(+), 170 deletions(-) diff --git a/adminer/drivers/mssql.inc.php b/adminer/drivers/mssql.inc.php index 87905cc0..7b16d85b 100644 --- a/adminer/drivers/mssql.inc.php +++ b/adminer/drivers/mssql.inc.php @@ -25,7 +25,7 @@ if (isset($_GET["mssql"])) { $this->error = rtrim($this->error); } - function connect($server, $username, $password) { + function connect(string $server, string $username, string $password): bool { global $adminer; $connection_info = array("UID" => $username, "PWD" => $password, "CharacterSet" => "UTF-8"); $ssl = $adminer->connectSsl(); @@ -49,16 +49,16 @@ if (isset($_GET["mssql"])) { return (bool) $this->link; } - function quote($string) { + function quote(string $string): string { $unicode = strlen($string) != strlen(utf8_decode($string)); return ($unicode ? "N" : "") . "'" . str_replace("'", "''", $string) . "'"; } - function select_db($database) { + function select_db(string $database): bool { return $this->query(use_sql($database)); } - function query($query, $unbuffered = false) { + function query(string $query, bool $unbuffered = false) { $result = sqlsrv_query($this->link, $query); //! , array(), ($unbuffered ? array() : array("Scrollable" => "keyset")) $this->error = ""; if (!$result) { @@ -68,7 +68,7 @@ if (isset($_GET["mssql"])) { return $this->store_result($result); } - function multi_query($query) { + function multi_query(string $query) { $this->result = sqlsrv_query($this->link, $query); $this->error = ""; if (!$this->result) { @@ -92,7 +92,7 @@ if (isset($_GET["mssql"])) { return true; } - function next_result() { + function next_result(): bool { return $this->result ? sqlsrv_next_result($this->result) : null; } } @@ -116,15 +116,15 @@ if (isset($_GET["mssql"])) { return $row; } - function fetch_assoc() { + function fetch_assoc(): array { return $this->convert(sqlsrv_fetch_array($this->result, SQLSRV_FETCH_ASSOC)); } - function fetch_row() { + function fetch_row(): array { return $this->convert(sqlsrv_fetch_array($this->result, SQLSRV_FETCH_NUMERIC)); } - function fetch_field() { + function fetch_field(): object { if (!$this->fields) { $this->fields = sqlsrv_field_metadata($this->result); } @@ -160,7 +160,7 @@ if (isset($_GET["mssql"])) { } else { abstract class MssqlDb extends PdoDb { - function select_db($database) { + function select_db(string $database): bool { // database selection is separated from the connection so dbname in DSN can't be used return $this->query(use_sql($database)); } @@ -182,7 +182,7 @@ if (isset($_GET["mssql"])) { class Db extends MssqlDb { public $extension = "PDO_SQLSRV"; - function connect($server, $username, $password) { + function connect(string $server, string $username, string $password): bool { $this->dsn("sqlsrv:Server=" . str_replace(":", ",", $server), $username, $password); return true; } @@ -192,7 +192,7 @@ if (isset($_GET["mssql"])) { class Db extends MssqlDb { public $extension = "PDO_DBLIB"; - function connect($server, $username, $password) { + function connect(string $server, string $username, string $password): bool { $this->dsn("dblib:charset=utf8;host=" . str_replace(":", ";unix_socket=", preg_replace('~:(\d)~', ';port=\1', $server)), $username, $password); return true; } @@ -220,7 +220,7 @@ if (isset($_GET["mssql"])) { public $onActions = "NO ACTION|CASCADE|SET NULL|SET DEFAULT"; public $generated = array("PERSISTED", "VIRTUAL"); - function __construct($connection) { + function __construct(Db $connection) { parent::__construct($connection); $this->types = array( //! use sys.types lang('Numbers') => array("tinyint" => 3, "smallint" => 5, "int" => 10, "bigint" => 20, "bit" => 1, "decimal" => 0, "real" => 12, "float" => 53, "smallmoney" => 10, "money" => 20), @@ -230,7 +230,7 @@ if (isset($_GET["mssql"])) { ); } - function insertUpdate($table, $rows, $primary) { + function insertUpdate(string $table, array $rows, array $primary) { $fields = fields($table); $update = array(); $where = array(); @@ -274,7 +274,7 @@ if (isset($_GET["mssql"])) { return queries("BEGIN TRANSACTION"); } - function tableHelp($name, $is_view = false) { + function tableHelp(string $name, bool $is_view = false) { $links = array( "sys" => "catalog-views/sys-", "INFORMATION_SCHEMA" => "information-schema-views/", diff --git a/adminer/drivers/mysql.inc.php b/adminer/drivers/mysql.inc.php index 6f268874..be50d52a 100644 --- a/adminer/drivers/mysql.inc.php +++ b/adminer/drivers/mysql.inc.php @@ -54,7 +54,7 @@ if (!defined('Adminer\DRIVER')) { return ($row ? $row[$field] : false); } - function quote($string) { + function quote(string $string): string { return "'" . $this->escape_string($string) . "'"; } } @@ -63,7 +63,7 @@ if (!defined('Adminer\DRIVER')) { class Db extends SqlDb { private resource $link; - function connect($server, $username, $password) { + function connect(string $server, string $username, string $password): bool { if (ini_bool("mysql.allow_local_infile")) { $this->error = lang('Disable %s or enable %s or %s extensions.', "'mysql.allow_local_infile'", "MySQLi", "PDO_MySQL"); return false; @@ -95,15 +95,15 @@ if (!defined('Adminer\DRIVER')) { return $this->query("SET NAMES $charset"); } - function quote($string) { + function quote(string $string): string { return "'" . mysql_real_escape_string($string, $this->link) . "'"; } - function select_db($database) { + function select_db(string $database): bool { return mysql_select_db($database, $this->link); } - function query($query, $unbuffered = false) { + function query(string $query, bool $unbuffered = false) { $result = @($unbuffered ? mysql_unbuffered_query($query, $this->link) : mysql_query($query, $this->link)); // @ - mute mysql.trace_mode $this->error = ""; if (!$result) { @@ -164,7 +164,7 @@ if (!defined('Adminer\DRIVER')) { class Db extends PdoDb { public $extension = "PDO_MySQL"; - function connect($server, $username, $password) { + function connect(string $server, string $username, string $password): bool { global $adminer; $options = array(\PDO::MYSQL_ATTR_LOCAL_INFILE => false); $ssl = $adminer->connectSsl(); @@ -195,12 +195,12 @@ if (!defined('Adminer\DRIVER')) { return $this->query("SET NAMES $charset"); // charset in DSN is ignored before PHP 5.3.6 } - function select_db($database) { + function select_db(string $database): bool { // database selection is separated from the connection so dbname in DSN can't be used return $this->query("USE " . idf_escape($database)); } - function query($query, $unbuffered = false) { + function query(string $query, bool $unbuffered = false) { $this->pdo->setAttribute(\PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, !$unbuffered); return parent::query($query, $unbuffered); } @@ -219,7 +219,7 @@ if (!defined('Adminer\DRIVER')) { /** @var list */ public array $functions = array("char_length", "date", "from_unixtime", "lower", "round", "floor", "ceil", "sec_to_time", "time_to_sec", "upper"); /** @var list */ public array $grouping = array("avg", "count", "count distinct", "group_concat", "max", "min", "sum"); - function __construct($connection) { + function __construct(Db $connection) { parent::__construct($connection); $this->types = array( lang('Numbers') => array("tinyint" => 3, "smallint" => 5, "mediumint" => 8, "int" => 10, "bigint" => 20, "decimal" => 66, "float" => 12, "double" => 21), @@ -257,18 +257,18 @@ if (!defined('Adminer\DRIVER')) { } } - function unconvertFunction($field) { + function unconvertFunction(array $field) { return (preg_match("~binary~", $field["type"]) ? "UNHEX" : ($field["type"] == "bit" ? doc_link(array('sql' => 'bit-value-literals.html'), "b''") : (preg_match("~geometry|point|linestring|polygon~", $field["type"]) ? "GeomFromText" : ""))); } - function insert($table, $set) { + function insert(string $table, array $set) { return ($set ? parent::insert($table, $set) : queries("INSERT INTO " . table($table) . " ()\nVALUES ()")); } - function insertUpdate($table, $rows, $primary) { + function insertUpdate(string $table, array $rows, array $primary) { $columns = array_keys(reset($rows)); $prefix = "INSERT INTO " . table($table) . " (" . implode(", ", $columns) . ") VALUES\n"; $values = array(); @@ -293,7 +293,7 @@ if (!defined('Adminer\DRIVER')) { return queries($prefix . implode(",\n", $values) . $suffix); } - function slowQuery($query, $timeout) { + function slowQuery(string $query, int $timeout) { if (min_version('5.7.8', '10.1.2')) { if ($this->conn->flavor == 'maria') { return "SET STATEMENT max_statement_time=$timeout FOR $query"; @@ -303,7 +303,7 @@ if (!defined('Adminer\DRIVER')) { } } - function convertSearch($idf, $val, $field) { + function convertSearch(string $idf, array $val, array $field): string { return (preg_match('~char|text|enum|set~', $field["type"]) && !preg_match("~^utf8~", $field["collation"]) && preg_match('~[\x80-\xFF]~', $val['val']) ? "CONVERT($idf USING " . charset($this->conn) . ")" : $idf @@ -319,7 +319,7 @@ if (!defined('Adminer\DRIVER')) { } } - function tableHelp($name, $is_view = false) { + function tableHelp(string $name, bool $is_view = false) { $maria = ($this->conn->flavor == 'maria'); if (information_schema(DB)) { return strtolower("information-schema-" . ($maria ? "$name-table/" : str_replace("_", "-", $name) . "-table.html")); @@ -329,7 +329,7 @@ if (!defined('Adminer\DRIVER')) { } } - function hasCStyleEscapes() { + function hasCStyleEscapes(): bool { static $c_style; if ($c_style === null) { $sql_mode = $this->conn->result("SHOW VARIABLES LIKE 'sql_mode'", 1); @@ -338,7 +338,7 @@ if (!defined('Adminer\DRIVER')) { return $c_style; } - function engines() { + function engines(): array { $return = array(); foreach (get_rows("SHOW ENGINES") as $row) { if (preg_match("~YES|DEFAULT~", $row["Support"])) { diff --git a/adminer/drivers/oracle.inc.php b/adminer/drivers/oracle.inc.php index af28f1b7..55c9447f 100644 --- a/adminer/drivers/oracle.inc.php +++ b/adminer/drivers/oracle.inc.php @@ -19,7 +19,7 @@ if (isset($_GET["oracle"])) { $this->error = $error; } - function connect($server, $username, $password) { + function connect(string $server, string $username, string $password): bool { $this->link = @oci_new_connect($username, $password, $server, "AL32UTF8"); if ($this->link) { $this->server_info = oci_server_version($this->link); @@ -30,16 +30,16 @@ if (isset($_GET["oracle"])) { return false; } - function quote($string) { + function quote(string $string): string { return "'" . str_replace("'", "''", $string) . "'"; } - function select_db($database) { + function select_db(string $database): bool { $this->_current_db = $database; return true; } - function query($query, $unbuffered = false) { + function query(string $query, bool $unbuffered = false) { $result = oci_parse($this->link, $query); $this->error = ""; if (!$result) { @@ -79,15 +79,15 @@ if (isset($_GET["oracle"])) { return $row; } - function fetch_assoc() { + function fetch_assoc(): array { return $this->convert(oci_fetch_assoc($this->result)); } - function fetch_row() { + function fetch_row(): array { return $this->convert(oci_fetch_row($this->result)); } - function fetch_field() { + function fetch_field(): object { $column = $this->offset++; $return = new \stdClass; $return->name = oci_field_name($this->result, $column); @@ -106,12 +106,12 @@ if (isset($_GET["oracle"])) { public $extension = "PDO_OCI"; public $_current_db; - function connect($server, $username, $password) { + function connect(string $server, string $username, string $password): bool { $this->dsn("oci:dbname=//$server;charset=AL32UTF8", $username, $password); return true; } - function select_db($database) { + function select_db(string $database): bool { $this->_current_db = $database; return true; } @@ -140,7 +140,7 @@ if (isset($_GET["oracle"])) { public $functions = array("length", "lower", "round", "upper"); public $grouping = array("avg", "count", "count distinct", "max", "min", "sum"); - function __construct($connection) { + function __construct(Db $connection) { parent::__construct($connection); $this->types = array( lang('Numbers') => array("number" => 38, "binary_float" => 12, "binary_double" => 21), @@ -156,7 +156,7 @@ if (isset($_GET["oracle"])) { return true; // automatic start } - function insertUpdate($table, $rows, $primary) { + function insertUpdate(string $table, array $rows, array $primary) { global $connection; foreach ($rows as $set) { $update = array(); @@ -177,7 +177,7 @@ if (isset($_GET["oracle"])) { return true; } - function hasCStyleEscapes() { + function hasCStyleEscapes(): bool { return true; } } diff --git a/adminer/drivers/pgsql.inc.php b/adminer/drivers/pgsql.inc.php index adb74b59..069e329f 100644 --- a/adminer/drivers/pgsql.inc.php +++ b/adminer/drivers/pgsql.inc.php @@ -18,7 +18,7 @@ if (isset($_GET["pgsql"])) { $this->error = $error; } - function connect($server, $username, $password) { + function connect(string $server, string $username, string $password): bool { global $adminer; $db = $adminer->database(); set_error_handler(array($this, '_error')); @@ -40,18 +40,18 @@ if (isset($_GET["pgsql"])) { return (bool) $this->link; } - function quote($string) { + function quote(string $string): string { return (function_exists('pg_escape_literal') ? pg_escape_literal($this->link, $string) // available since PHP 5.4.4 : "'" . pg_escape_string($this->link, $string) . "'" ); } - function value($val, $field) { + function value(string $val, array $field): string { return ($field["type"] == "bytea" && $val !== null ? pg_unescape_bytea($val) : $val); } - function select_db($database) { + function select_db(string $database): bool { global $adminer; if ($database == $adminer->database()) { return $this->database; @@ -67,7 +67,7 @@ if (isset($_GET["pgsql"])) { $this->link = @pg_connect("$this->string dbname='postgres'"); } - function query($query, $unbuffered = false) { + function query(string $query, bool $unbuffered = false) { $result = @pg_query($this->link, $query); $this->error = ""; if (!$result) { @@ -100,15 +100,15 @@ if (isset($_GET["pgsql"])) { $this->num_rows = pg_num_rows($result); } - function fetch_assoc() { + function fetch_assoc(): array { return pg_fetch_assoc($this->result); } - function fetch_row() { + function fetch_row(): array { return pg_fetch_row($this->result); } - function fetch_field() { + function fetch_field(): object { $column = $this->offset++; $return = new \stdClass; $return->orgtable = pg_field_table($this->result, $column); @@ -127,7 +127,7 @@ if (isset($_GET["pgsql"])) { class Db extends PdoDb { public $extension = "PDO_PgSQL", $timeout; - function connect($server, $username, $password) { + function connect(string $server, string $username, string $password): bool { global $adminer; $db = $adminer->database(); //! client_encoding is supported since 9.1, but we can't yet use min_version here @@ -140,12 +140,12 @@ if (isset($_GET["pgsql"])) { return true; } - function select_db($database) { + function select_db(string $database): bool { global $adminer; return ($adminer->database() == $database); } - function query($query, $unbuffered = false) { + function query(string $query, bool $unbuffered = false) { $return = parent::query($query, $unbuffered); if ($this->timeout) { $this->timeout = 0; @@ -174,7 +174,7 @@ if (isset($_GET["pgsql"])) { public $functions = array("char_length", "lower", "round", "to_hex", "to_timestamp", "upper"); public $grouping = array("avg", "count", "count distinct", "max", "min", "sum"); - function __construct($connection) { + function __construct(Db $connection) { parent::__construct($connection); $this->types = array( //! arrays lang('Numbers') => array("smallint" => 5, "integer" => 10, "bigint" => 19, "boolean" => 1, "numeric" => 0, "real" => 7, "double precision" => 16, "money" => 20), @@ -205,7 +205,7 @@ if (isset($_GET["pgsql"])) { } } - function enumLength($field) { + function enumLength(array $field) { $enum = $this->types[lang('User types')][$field["type"]]; return ($enum ? type_values($enum) : ""); } @@ -214,14 +214,14 @@ if (isset($_GET["pgsql"])) { $this->types[lang('User types')] = array_flip($types); } - function insertReturning($table) { + function insertReturning(string $table): string { $auto_increment = array_filter(fields($table), function ($field) { return $field['auto_increment']; }); return (count($auto_increment) == 1 ? " RETURNING " . idf_escape(key($auto_increment)) : ""); } - function insertUpdate($table, $rows, $primary) { + function insertUpdate(string $table, array $rows, array $primary) { global $connection; foreach ($rows as $set) { $update = array(); @@ -242,13 +242,13 @@ if (isset($_GET["pgsql"])) { return true; } - function slowQuery($query, $timeout) { + function slowQuery(string $query, int $timeout) { $this->conn->query("SET statement_timeout = " . (1000 * $timeout)); $this->conn->timeout = 1000 * $timeout; return $query; } - function convertSearch($idf, $val, $field) { + function convertSearch(string $idf, array $val, array $field): string { $textTypes = "char|text"; if (strpos($val["op"], "LIKE") === false) { $textTypes .= "|date|time(stamp)?|boolean|uuid|inet|cidr|macaddr|" . number_type(); @@ -257,7 +257,7 @@ if (isset($_GET["pgsql"])) { return (preg_match("~$textTypes~", $field["type"]) ? $idf : "CAST($idf AS text)"); } - function quoteBinary($s) { + function quoteBinary(string $s): string { return "'\\x" . bin2hex($s) . "'"; // available since PostgreSQL 8.1 } @@ -265,7 +265,7 @@ if (isset($_GET["pgsql"])) { return $this->conn->warnings(); } - function tableHelp($name, $is_view = false) { + function tableHelp(string $name, bool $is_view = false) { $links = array( "information_schema" => "infoschema", "pg_catalog" => ($is_view ? "view" : "catalog"), @@ -276,12 +276,12 @@ if (isset($_GET["pgsql"])) { } } - function supportsIndex($table_status) { + function supportsIndex(array $table_status): bool { // returns true for "materialized view" return $table_status["Engine"] != "view"; } - function hasCStyleEscapes() { + function hasCStyleEscapes(): bool { static $c_style; if ($c_style === null) { $c_style = ($this->conn->result("SHOW standard_conforming_strings") == "off"); @@ -772,7 +772,7 @@ ORDER BY SPECIFIC_NAME'); } } - function types() { + function types(): array { return get_key_vals( "SELECT oid, typname FROM pg_type diff --git a/adminer/drivers/sqlite.inc.php b/adminer/drivers/sqlite.inc.php index f03cba46..f7a0f3c0 100644 --- a/adminer/drivers/sqlite.inc.php +++ b/adminer/drivers/sqlite.inc.php @@ -11,14 +11,14 @@ if (isset($_GET["sqlite"])) { public $extension = "SQLite3"; private $link; - function connect($filename, $username = '', $password = '') { + function connect(string $filename, string $username = '', string $password = ''): bool { $this->link = new \SQLite3($filename); $version = $this->link->version(); $this->server_info = $version["versionString"]; return true; } - function query($query, $unbuffered = false) { + function query(string $query, bool $unbuffered = false) { $result = @$this->link->query($query); $this->error = ""; if (!$result) { @@ -32,7 +32,7 @@ if (isset($_GET["sqlite"])) { return true; } - function quote($string) { + function quote(string $string): string { return (is_utf8($string) ? "'" . $this->link->escapeString($string) . "'" : "x'" . first(unpack('H*', $string)) . "'" @@ -48,15 +48,15 @@ if (isset($_GET["sqlite"])) { $this->result = $result; } - function fetch_assoc() { + function fetch_assoc(): array { return $this->result->fetchArray(SQLITE3_ASSOC); } - function fetch_row() { + function fetch_row(): array { return $this->result->fetchArray(SQLITE3_NUM); } - function fetch_field() { + function fetch_field(): object { $column = $this->offset++; $type = $this->result->columnType($column); return (object) array( @@ -75,7 +75,7 @@ if (isset($_GET["sqlite"])) { abstract class SqliteDb extends PdoDb { public $extension = "PDO_SQLite"; - function connect($filename, $username = '', $password = '') { + function connect(string $filename, string $username = '', string $password = ''): bool { $this->dsn(DRIVER . ":$filename", "", ""); $this->query("PRAGMA foreign_keys = 1"); $this->query("PRAGMA busy_timeout = 500"); @@ -87,14 +87,14 @@ if (isset($_GET["sqlite"])) { if (class_exists('Adminer\SqliteDb')) { class Db extends SqliteDb { - function connect($filename, $username = '', $password = '') { + function connect(string $filename, string $username = '', string $password = ''): bool { parent::connect($filename); $this->query("PRAGMA foreign_keys = 1"); $this->query("PRAGMA busy_timeout = 500"); return true; } - function select_db($filename) { + function select_db(string $filename): bool { if (is_readable($filename) && $this->query("ATTACH " . $this->quote(preg_match("~(^[/\\\\]|:)~", $filename) ? $filename : dirname($_SERVER["SCRIPT_FILENAME"]) . "/$filename") . " AS a")) { return self::connect($filename); } @@ -125,18 +125,18 @@ if (isset($_GET["sqlite"])) { public $functions = array("hex", "length", "lower", "round", "unixepoch", "upper"); public $grouping = array("avg", "count", "count distinct", "group_concat", "max", "min", "sum"); - function __construct($connection) { + function __construct(Db $connection) { parent::__construct($connection); if (min_version(3.31, 0, $connection)) { $this->generated = array("STORED", "VIRTUAL"); } } - function structuredTypes() { + function structuredTypes(): array { return array_keys($this->types[0]); } - function insertUpdate($table, $rows, $primary) { + function insertUpdate(string $table, array $rows, array $primary) { $values = array(); foreach ($rows as $set) { $values[] = "(" . implode(", ", $set) . ")"; @@ -144,7 +144,7 @@ if (isset($_GET["sqlite"])) { return queries("REPLACE INTO " . table($table) . " (" . implode(", ", array_keys(reset($rows))) . ") VALUES\n" . implode(",\n", $values)); } - function tableHelp($name, $is_view = false) { + function tableHelp(string $name, bool $is_view = false) { if ($name == "sqlite_sequence") { return "fileformat2.html#seqtab"; } @@ -153,7 +153,7 @@ if (isset($_GET["sqlite"])) { } } - function checkConstraints($table) { + function checkConstraints(string $table): array { preg_match_all('~ CHECK *(\( *(((?>[^()]*[^() ])|(?1))*) *\))~', $this->conn->result("SELECT sql FROM sqlite_master WHERE type = 'table' AND name = " . q($table)), $matches); //! could be inside a comment return array_combine($matches[2], $matches[2]); } @@ -667,7 +667,7 @@ if (isset($_GET["sqlite"])) { function found_rows($table_status, $where) { } - function types() { + function types(): array { return array(); } diff --git a/adminer/include/driver.inc.php b/adminer/include/driver.inc.php index b8036a65..276a1284 100644 --- a/adminer/include/driver.inc.php +++ b/adminer/include/driver.inc.php @@ -46,7 +46,7 @@ abstract class SqlDriver { /** Get structured types * @return list[]|list [$description => [$type, ...], ...] */ - function structuredTypes() { + function structuredTypes(): array { return array_map('array_keys', $this->types); } diff --git a/adminer/include/pdo.inc.php b/adminer/include/pdo.inc.php index 0b7be4ec..3169529b 100644 --- a/adminer/include/pdo.inc.php +++ b/adminer/include/pdo.inc.php @@ -20,11 +20,11 @@ if (extension_loaded('pdo')) { $this->server_info = @$this->pdo->getAttribute(\PDO::ATTR_SERVER_VERSION); } - function quote($string) { + function quote(string $string): string { return $this->pdo->quote($string); } - function query($query, $unbuffered = false) { + function query(string $query, bool $unbuffered = false) { /** @var Result|bool */ $result = $this->pdo->query($query); $this->error = ""; @@ -54,7 +54,7 @@ if (extension_loaded('pdo')) { return true; } - function next_result() { + function next_result(): bool { /** @var PdoResult|bool */ $result = $this->multi; if (!is_object($result)) { @@ -68,15 +68,15 @@ if (extension_loaded('pdo')) { class PdoResult extends \PDOStatement { public $_offset = 0, $num_rows; - function fetch_assoc() { + function fetch_assoc(): array { return $this->fetch(\PDO::FETCH_ASSOC); } - function fetch_row() { + function fetch_row(): array { return $this->fetch(\PDO::FETCH_NUM); } - function fetch_field() { + function fetch_field(): object { $row = (object) $this->getColumnMeta($this->_offset++); $type = $row->pdo_type; $row->type = ($type == \PDO::PARAM_INT ? 0 : 15); diff --git a/plugins/drivers/clickhouse.php b/plugins/drivers/clickhouse.php index bfecb509..f434e1ad 100644 --- a/plugins/drivers/clickhouse.php +++ b/plugins/drivers/clickhouse.php @@ -52,23 +52,23 @@ if (isset($_GET["clickhouse"])) { return (bool) preg_match('~^(select|show)~i', $query); } - function query($query, $unbuffered = false) { + function query(string $query, bool $unbuffered = false) { return $this->rootQuery($this->_db, $query); } - function connect($server, $username, $password) { + function connect(string $server, string $username, string $password): bool { preg_match('~^(https?://)?(.*)~', $server, $match); $this->url = ($match[1] ?: "http://") . urlencode($username) . ":" . urlencode($password) . "@$match[2]"; $return = $this->query('SELECT 1'); return (bool) $return; } - function select_db($database) { + function select_db(string $database): bool { $this->_db = $database; return true; } - function quote($string) { + function quote(string $string): string { return "'" . addcslashes($string, "\\'") . "'"; } } @@ -91,19 +91,19 @@ if (isset($_GET["clickhouse"])) { reset($this->rows); } - function fetch_assoc() { + function fetch_assoc(): array { $row = current($this->rows); next($this->rows); return $row === false ? false : array_combine($this->columns, $row); } - function fetch_row() { + function fetch_row(): array { $row = current($this->rows); next($this->rows); return $row; } - function fetch_field() { + function fetch_field(): object { $column = $this->offset++; $return = new \stdClass; if ($column < count($this->columns)) { @@ -123,7 +123,7 @@ if (isset($_GET["clickhouse"])) { public $operators = array("=", "<", ">", "<=", ">=", "!=", "~", "!~", "LIKE", "LIKE %%", "IN", "IS NULL", "NOT LIKE", "NOT IN", "IS NOT NULL", "SQL"); public $grouping = array("avg", "count", "count distinct", "max", "min", "sum"); - function __construct($connection) { + function __construct(Db $connection) { parent::__construct($connection); $this->types = array( //! arrays lang('Numbers') => array( @@ -138,14 +138,14 @@ if (isset($_GET["clickhouse"])) { ); } - function delete($table, $queryWhere, $limit = 0) { + function delete(string $table, string $queryWhere, int $limit = 0) { if ($queryWhere === '') { $queryWhere = 'WHERE 1=1'; } return queries("ALTER TABLE " . table($table) . " DELETE $queryWhere"); } - function update($table, $set, $queryWhere, $limit = 0, $separator = "\n") { + function update(string $table, array $set, string $queryWhere, int $limit = 0, string $separator = "\n") { $values = array(); foreach ($set as $key => $val) { $values[] = "$key = $val"; @@ -259,10 +259,6 @@ if (isset($_GET["clickhouse"])) { function db_collation($db, $collations) { } - function engines() { - return array('MergeTree'); - } - function logged_user() { $adminer = adminer(); $credentials = $adminer->credentials(); @@ -355,7 +351,7 @@ if (isset($_GET["clickhouse"])) { return h($connection->error); } - function types() { + function types(): array { return array(); } diff --git a/plugins/drivers/elastic.php b/plugins/drivers/elastic.php index 347a4b9c..5e5e1343 100644 --- a/plugins/drivers/elastic.php +++ b/plugins/drivers/elastic.php @@ -75,11 +75,11 @@ if (isset($_GET["elastic"])) { return (bool) $return; } - function select_db($database) { + function select_db(string $database): bool { return true; } - function quote($string) { + function quote(string $string): string { return $string; } } @@ -91,20 +91,17 @@ if (isset($_GET["elastic"])) { function __construct($rows) { $this->num_rows = count($rows); $this->rows = $rows; - reset($this->rows); } - function fetch_assoc() { + function fetch_assoc(): array { $return = current($this->rows); next($this->rows); - return $return; } - function fetch_row() { + function fetch_row(): array { $row = $this->fetch_assoc(); - return $row ? array_values($row) : false; } } @@ -117,7 +114,7 @@ if (isset($_GET["elastic"])) { public $editFunctions = array(array("json")); public $operators = array("=", "must", "should", "must_not"); - function __construct($connection) { + function __construct(Db $connection) { parent::__construct($connection); $this->types = array( lang('Numbers') => array("long" => 3, "integer" => 5, "short" => 8, "byte" => 10, "double" => 20, "float" => 66, "half_float" => 12, "scaled_float" => 21), @@ -127,7 +124,7 @@ if (isset($_GET["elastic"])) { ); } - function select($table, $select, $where, $group, $order = array(), $limit = 1, $page = 0, $print = false) { + function select(string $table, array $select, array $where, array $group, array $order = array(), $limit = 1, int $page = 0, bool $print = false) { $data = array(); if ($select != array("*")) { $data["fields"] = array_values($select); @@ -224,7 +221,7 @@ if (isset($_GET["elastic"])) { return new Result($return); } - function update($type, $record, $queryWhere, $limit = 0, $separator = "\n") { + function update(string $table, array $set, string $queryWhere, int $limit = 0, string $separator = "\n") { //! use $limit $parts = preg_split('~ *= *~', $queryWhere); if (count($parts) == 2) { @@ -237,7 +234,7 @@ if (isset($_GET["elastic"])) { return false; } - function insert($type, $record) { + function insert(string $type, array $record) { $query = "$type/_doc/"; if (isset($record["_id"]) && $record["_id"] != "NULL") { $query .= $record["_id"]; @@ -257,7 +254,7 @@ if (isset($_GET["elastic"])) { return $response['result']; } - function delete($table, $queryWhere, $limit = 0) { + function delete(string $table, string $queryWhere, int $limit = 0) { //! use $limit $ids = array(); if (idx($_GET["where"], "_id")) { @@ -285,7 +282,7 @@ if (isset($_GET["elastic"])) { return !!$this->conn->affected_rows; } - function convertOperator($operator) { + function convertOperator(string $operator): string { return $operator == "LIKE %%" ? "should" : $operator; } } diff --git a/plugins/drivers/firebird.php b/plugins/drivers/firebird.php index 4955a9cd..6030f05a 100644 --- a/plugins/drivers/firebird.php +++ b/plugins/drivers/firebird.php @@ -14,7 +14,7 @@ if (isset($_GET["firebird"])) { class Db extends SqlDb { public $extension = "Firebird", $_link; - function connect($server, $username, $password) { + function connect(string $server, string $username, string $password): bool { $this->_link = ibase_connect($server, $username, $password); if ($this->_link) { $url_parts = explode(':', $server); @@ -27,15 +27,15 @@ if (isset($_GET["firebird"])) { return (bool) $this->_link; } - function quote($string) { + function quote(string $string): string { return "'" . str_replace("'", "''", $string) . "'"; } - function select_db($database) { + function select_db(string $database): bool { return ($database == "domain"); } - function query($query, $unbuffered = false) { + function query(string $query, bool $unbuffered = false) { $result = ibase_query($this->_link, $query); if (!$result) { $this->errno = ibase_errcode(); @@ -60,15 +60,15 @@ if (isset($_GET["firebird"])) { // $this->num_rows = ibase_num_rows($result); } - function fetch_assoc() { + function fetch_assoc(): array { return ibase_fetch_assoc($this->result); } - function fetch_row() { + function fetch_row(): array { return ibase_fetch_row($this->result); } - function fetch_field() { + function fetch_field(): object { $field = ibase_field_info($this->result, $this->offset++); return (object) array( 'name' => $field['name'], @@ -260,7 +260,7 @@ ORDER BY RDB$INDEX_SEGMENTS.RDB$FIELD_POSITION'; return h($connection->error); } - function types() { + function types(): array { return array(); } diff --git a/plugins/drivers/imap.php b/plugins/drivers/imap.php index af313767..bde674a5 100644 --- a/plugins/drivers/imap.php +++ b/plugins/drivers/imap.php @@ -24,7 +24,7 @@ if (isset($_GET["imap"])) { private $mailbox; private $imap; - function connect($server, $username, $password) { + function connect(string $server, string $username, string $password): bool { $this->mailbox = "{" . "$server:993/ssl}"; // Adminer disallows specifying privileged port in server name $this->imap = @imap_open($this->mailbox, $username, $password, OP_HALFOPEN, 1); if (!$this->imap) { @@ -33,11 +33,11 @@ if (isset($_GET["imap"])) { return $this->imap; } - function select_db($database) { + function select_db(string $database): bool { return ($database == "mail"); } - function query($query, $unbuffered = false) { + function query(string $query, bool $unbuffered = false) { if (preg_match('~DELETE FROM "(.+?)"~', $query)) { preg_match_all('~"uid" = (\d+)~', $query, $matches); return imap_delete($this->imap, implode(",", $matches[1]), FT_UID); @@ -70,7 +70,7 @@ if (isset($_GET["imap"])) { return false; } - function quote($string) { + function quote(string $string): string { return $string; } @@ -123,18 +123,18 @@ if (isset($_GET["imap"])) { $this->fields = array_keys(idx($result, 0, array())); } - function fetch_assoc() { + function fetch_assoc(): array { $row = current($this->result); next($this->result); return $row; } - function fetch_row() { + function fetch_row(): array { $row = $this->fetch_assoc(); return ($row ? array_values($row) : false); } - function fetch_field() { + function fetch_field(): object { $field = current($this->fields); next($this->fields); return ($field != '' ? (object) array('name' => $field, 'type' => 15, 'charsetnr' => 0) : false); diff --git a/plugins/drivers/mongo.php b/plugins/drivers/mongo.php index 5aa6c27e..8b0d74b5 100644 --- a/plugins/drivers/mongo.php +++ b/plugins/drivers/mongo.php @@ -12,8 +12,20 @@ if (isset($_GET["mongo"])) { public \MongoDB\Driver\Manager $_link; public $_db, $_db_name; - function connect($uri, $options) { - $this->_link = new \MongoDB\Driver\Manager($uri, $options); + function connect(string $server, string $username, string $password): bool { + $options = array(); + if ($username . $password != "") { + $options["username"] = $username; + $options["password"] = $password; + } + $db = adminer()->database(); + if ($db != "") { + $options["db"] = $db; + } + if (($auth_source = getenv("MONGO_AUTH_SOURCE"))) { + $options["authSource"] = $auth_source; + } + $this->_link = new \MongoDB\Driver\Manager("mongodb://$server", $options); $this->executeDbCommand($options["db"], array('ping' => 1)); } @@ -41,16 +53,16 @@ if (isset($_GET["mongo"])) { } } - function query($query, $unbuffered = false) { + function query(string $query, bool $unbuffered = false) { return false; } - function select_db($database) { + function select_db(string $database): bool { $this->_db_name = $database; return true; } - function quote($string) { + function quote(string $string): string { return $string; } } @@ -85,7 +97,7 @@ if (isset($_GET["mongo"])) { $this->num_rows = count($this->rows); } - function fetch_assoc() { + function fetch_assoc(): array { $row = current($this->rows); if (!$row) { return $row; @@ -98,7 +110,7 @@ if (isset($_GET["mongo"])) { return $return; } - function fetch_row() { + function fetch_row(): array { $return = $this->fetch_assoc(); if (!$return) { return $return; @@ -106,7 +118,7 @@ if (isset($_GET["mongo"])) { return array_values($return); } - function fetch_field() { + function fetch_field(): object { $keys = array_keys($this->rows[0]); $name = $keys[$this->offset++]; return (object) array( @@ -310,7 +322,7 @@ if (isset($_GET["mongo"])) { public $primary = "_id"; - function select($table, $select, $where, $group, $order = array(), $limit = 1, $page = 0, $print = false) { + function select(string $table, array $select, array $where, array $group, array $order = array(), $limit = 1, int $page = 0, bool $print = false) { $select = ($select == array("*") ? array() : array_fill_keys($select, 1) @@ -337,7 +349,7 @@ if (isset($_GET["mongo"])) { } } - function update($table, $set, $queryWhere, $limit = 0, $separator = "\n") { + function update(string $table, array $set, string $queryWhere, int $limit = 0, string $separator = "\n") { $db = $this->conn->_db_name; $where = sql_query_where_parser($queryWhere); $bulk = new \MongoDB\Driver\BulkWrite(array()); @@ -359,7 +371,7 @@ if (isset($_GET["mongo"])) { return $this->conn->executeBulkWrite("$db.$table", $bulk, 'getModifiedCount'); } - function delete($table, $queryWhere, $limit = 0) { + function delete(string $table, string $queryWhere, int $limit = 0) { $db = $this->conn->_db_name; $where = sql_query_where_parser($queryWhere); $bulk = new \MongoDB\Driver\BulkWrite(array()); @@ -367,7 +379,7 @@ if (isset($_GET["mongo"])) { return $this->conn->executeBulkWrite("$db.$table", $bulk, 'getDeletedCount'); } - function insert($table, $set) { + function insert(string $table, array $set) { $db = $this->conn->_db_name; $bulk = new \MongoDB\Driver\BulkWrite(array()); if ($set['_id'] == '') { @@ -420,24 +432,10 @@ if (isset($_GET["mongo"])) { function connect($credentials) { $connection = new Db; list($server, $username, $password) = $credentials; - if ($server == "") { $server = "localhost:27017"; } - - $options = array(); - if ($username . $password != "") { - $options["username"] = $username; - $options["password"] = $password; - } - $db = adminer()->database(); - if ($db != "") { - $options["db"] = $db; - } - if (($auth_source = getenv("MONGO_AUTH_SOURCE"))) { - $options["authSource"] = $auth_source; - } - $connection->connect("mongodb://$server", $options); + $connection->connect($server, $username, $password); if ($connection->error) { return $connection->error; } diff --git a/plugins/drivers/simpledb.php b/plugins/drivers/simpledb.php index d1b660dd..89445219 100644 --- a/plugins/drivers/simpledb.php +++ b/plugins/drivers/simpledb.php @@ -10,11 +10,11 @@ if (isset($_GET["simpledb"])) { class Db extends SqlDb { public $extension = "SimpleXML", $server_info = '2009-04-15', $timeout, $next; - function select_db($database) { + function select_db(string $database): bool { return ($database == "domain"); } - function query($query, $unbuffered = false) { + function query(string $query, bool $unbuffered = false) { $params = array('SelectExpression' => $query, 'ConsistentRead' => 'true'); if ($this->next) { $params['NextToken'] = $this->next; @@ -37,7 +37,7 @@ if (isset($_GET["simpledb"])) { return new Result($result); } - function quote($string) { + function quote(string $string): string { return "'" . str_replace("'", "''", $string) . "'"; } } @@ -76,7 +76,7 @@ if (isset($_GET["simpledb"])) { return (is_object($element) && $element['encoding'] == 'base64' ? base64_decode($element) : (string) $element); } - function fetch_assoc() { + function fetch_assoc(): array { $row = current($this->rows); if (!$row) { return $row; @@ -89,7 +89,7 @@ if (isset($_GET["simpledb"])) { return $return; } - function fetch_row() { + function fetch_row(): array { $return = $this->fetch_assoc(); if (!$return) { return $return; @@ -97,7 +97,7 @@ if (isset($_GET["simpledb"])) { return array_values($return); } - function fetch_field() { + function fetch_field(): object { $keys = array_keys($this->rows[0]); return (object) array('name' => $keys[$this->offset++], 'type' => 15, 'charsetnr' => 0); } @@ -145,7 +145,7 @@ if (isset($_GET["simpledb"])) { return $return; } - function select($table, $select, $where, $group, $order = array(), $limit = 1, $page = 0, $print = false) { + function select(string $table, array $select, array $where, array $group, array $order = array(), $limit = 1, int $page = 0, bool $print = false) { $connection = connection(); $connection->next = $_GET["next"]; $return = parent::select($table, $select, $where, $group, $order, $limit, $page, $print); @@ -153,7 +153,7 @@ if (isset($_GET["simpledb"])) { return $return; } - function delete($table, $queryWhere, $limit = 0) { + function delete(string $table, string $queryWhere, int $limit = 0) { return $this->chunkRequest( $this->extractIds($table, $queryWhere, $limit), 'BatchDeleteAttributes', @@ -161,7 +161,7 @@ if (isset($_GET["simpledb"])) { ); } - function update($table, $set, $queryWhere, $limit = 0, $separator = "\n") { + function update(string $table, array $set, string $queryWhere, int $limit = 0, string $separator = "\n") { $delete = array(); $insert = array(); $i = 0; @@ -190,7 +190,7 @@ if (isset($_GET["simpledb"])) { ; } - function insert($table, $set) { + function insert(string $table, array $set) { $params = array("DomainName" => $table); $i = 0; foreach ($set as $name => $value) { @@ -210,7 +210,7 @@ if (isset($_GET["simpledb"])) { return sdb_request('PutAttributes', $params); } - function insertUpdate($table, $rows, $primary) { + function insertUpdate(string $table, array $rows, array $primary) { //! use one batch request foreach ($rows as $set) { if (!$this->update($table, $set, "WHERE `itemName()` = " . q($set["`itemName()`"]))) { @@ -232,7 +232,7 @@ if (isset($_GET["simpledb"])) { return false; } - function slowQuery($query, $timeout) { + function slowQuery(string $query, int $timeout) { $this->conn->timeout = $timeout; return $query; } -- 2.39.5