This commit is contained in:
2021-06-28 23:15:13 -04:00
parent 0061a3d920
commit f4a8db56ff
93 changed files with 2422 additions and 0 deletions

View File

@ -0,0 +1,25 @@
<?php
namespace ProVM\Common\Service\Database;
class DSN {
public $engine;
public function __construct(string $engine) {
$this->engine = $engine;
}
public $pairs;
public function addPair($name, $value) {
if ($this->pairs === null) {
$this->pairs = [];
}
$this->pairs []= [$name, $value];
return $this;
}
public function __toString() {
return implode(':', [
$this->engine,
implode(';', array_map(function($item) {
return implode('=', $item);
}, $this->pairs))
]);
}
}

View File

@ -0,0 +1,21 @@
<?php
namespace ProVM\Common\Service\Database;
class MySQL {
protected $settings;
public function __construct($settings) {
$this->settings = $settings;
}
public function dsn(): string {
$dsn = (new DSN($this->settings->engine))
->addPair('host', $this->settings->host->name);
if (isset($this->settings->host->port)) {
$dsn->addPair('port', $this->settings->host->port);
}
$dsn->addPair('dbname', $this->settings->name);
return '' . $dsn;
}
public function hasUser(): bool {
return true;
}
}