Move connect() to Driver

This commit is contained in:
Jakub Vrana
2025-03-30 07:51:47 +02:00
parent 992561f75e
commit 7ee6f4f7ac
13 changed files with 96 additions and 113 deletions

View File

@@ -110,6 +110,16 @@ if (isset($_GET["elastic"])) {
public array $insertFunctions = array("json");
public array $operators = array("=", "must", "should", "must_not");
static function connect(?string $server, string $username, string $password) {
if (!preg_match('~^(https?://)?[-a-z\d.]+(:\d+)?$~', $server)) {
return lang('Invalid server.');
}
if ($password != "" && is_object(parent::connect($server, $username, ""))) {
return lang('Database does not support password.');
}
return parent::connect($server, $username, $password);
}
function __construct(Db $connection) {
parent::__construct($connection);
$this->types = array(
@@ -283,20 +293,6 @@ if (isset($_GET["elastic"])) {
}
}
function connect($credentials) {
$connection = new Db;
list($server, $username, $password) = $credentials;
if (!preg_match('~^(https?://)?[-a-z\d.]+(:\d+)?$~', $server)) {
return lang('Invalid server.');
}
if ($password != "" && $connection->attach($server, $username, "")) {
return lang('Database does not support password.');
}
return ($connection->attach($server, $username, $password) ?: $connection);
}
function support($feature) {
return preg_match("~table|columns~", $feature);
}