1
0
mirror of https://github.com/vrana/adminer.git synced 2025-08-11 09:04:02 +02:00

Doc-comments: Sync method signatures

This commit is contained in:
Jakub Vrana
2025-03-28 09:57:33 +01:00
parent ab4208dcb8
commit 54f8d731b3
13 changed files with 161 additions and 170 deletions

View File

@@ -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();
}

View File

@@ -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;
}
}

View File

@@ -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();
}

View File

@@ -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);

View File

@@ -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;
}

View File

@@ -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;
}