2016-10-02 21:07:17 +00:00
|
|
|
<?php
|
2016-10-06 02:08:43 +00:00
|
|
|
declare(strict_types=1);
|
2016-10-02 21:07:17 +00:00
|
|
|
namespace JKingWeb\NewsSync;
|
|
|
|
|
|
|
|
class Database {
|
|
|
|
protected $drv;
|
|
|
|
|
|
|
|
public function __construct(Conf $conf) {
|
|
|
|
$driver = $conf->dbClass;
|
2016-10-06 02:08:43 +00:00
|
|
|
$this->drv = $driver::create($conf);
|
2016-10-02 21:07:17 +00:00
|
|
|
}
|
|
|
|
|
2016-10-06 02:08:43 +00:00
|
|
|
static public function listDrivers(): array {
|
|
|
|
$sep = \DIRECTORY_SEPARATOR;
|
|
|
|
$path = __DIR__.$sep."Db".$sep;
|
|
|
|
$classes = [];
|
|
|
|
foreach(glob($path."Driver?*.php") as $file) {
|
|
|
|
$name = basename($file, ".php");
|
|
|
|
if(substr($name,-3) != "PDO") {
|
|
|
|
$name = NS_BASE."Db\\$name";
|
|
|
|
if(class_exists($name)) {
|
|
|
|
$classes[$name] = $name::driverName();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $classes;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function schemaVersion(): int {
|
|
|
|
return $this->drv->schemaVersion();
|
2016-10-02 21:07:17 +00:00
|
|
|
}
|
|
|
|
}
|