Browse Source

Remove last vestiges of PDO accomodation

microsub
J. King 7 years ago
parent
commit
337b2cf90c
  1. 5
      lib/Database.php
  2. 5
      lib/Db/Driver.php
  3. 15
      lib/Db/DriverSQLite3.php
  4. 2
      lib/User.php
  5. 2
      lib/User/Driver.php

5
lib/Database.php

@ -22,8 +22,8 @@ class Database {
public function __construct(RuntimeData $data) {
$this->data = $data;
$this->driver = $data->conf->dbDriver;
$this->db = $this->driver::create($data, INSTALL);
$this->driver = $driver = $data->conf->dbDriver;
$this->db = new $driver($data, INSTALL);
$ver = $this->db->schemaVersion();
if(!INSTALL && $ver < self::SCHEMA_VERSION) {
$this->db->update(self::SCHEMA_VERSION);
@ -298,6 +298,7 @@ class Database {
(new PicoFeed\Reader\Favicon)->find($url),
$feed->siteUrl,
// Convert the date formats to SQL date format before inserting.
// FIXME: Dates should be formatted transparently by the driver's Statement wrapper, not here
$this->driver::formatDate($feed->date),
$this->driver::formatDate($resource->getLastModified()),
$resource->getEtag(),

5
lib/Db/Driver.php

@ -2,9 +2,8 @@
declare(strict_types=1);
namespace JKingWeb\NewsSync\Db;
interface Driver {
// returns an instance of a class implementing this interface. Implemented as a static method so that classes may return their PDO equivalents instead of themselves
static function create(\JKingWeb\NewsSync\RuntimeData $data, bool $install = false): Driver;
interface Driver {
function __construct(\JKingWeb\NewsSync\RuntimeData $data, bool $install = false);
// returns a human-friendly name for the driver (for display in installer, for example)
static function driverName(): string;
// returns the version of the scheme of the opened database; if uninitialized should return 0

15
lib/Db/DriverSQLite3.php

@ -9,6 +9,8 @@ class DriverSQLite3 implements Driver {
protected $data;
private function __construct(\JKingWeb\NewsSync\RuntimeData $data, bool $install = false) {
// check to make sure required extension is loaded
if(!class_exists("SQLite3")) throw new Exception("extMissing", self::driverName());
$this->data = $data;
$file = $data->conf->dbSQLite3File;
// if the file exists (or we're initializing the database), try to open it and set initial options
@ -32,21 +34,10 @@ class DriverSQLite3 implements Driver {
}
public function __destruct() {
$this->db->close();
try{$this->db->close();} catch(\Exception $e) {}
unset($this->db);
}
static public function create(\JKingWeb\NewsSync\RuntimeData $data, bool $install = false): Driver {
// check to make sure required extensions are loaded
if(class_exists("SQLite3")) {
return new self($data, $install);
} else if(class_exists("PDO") && in_array("sqlite",\PDO::getAvailableDrivers())) {
return new DriverSQLite3PDO($data, $install);
} else {
throw new Exception("extMissing", self::driverName());
}
}
static public function driverName(): string {
return "SQLite 3";

2
lib/User.php

@ -28,7 +28,7 @@ class User {
public function __construct(\JKingWeb\NewsSync\RuntimeData $data) {
$this->data = $data;
$driver = $data->conf->userDriver;
$this->u = $driver::create($data);
$this->u = new $driver($data);
$this->authzSupported = $this->u->driverFunctions("authorize");
}

2
lib/User/Driver.php

@ -14,7 +14,7 @@ Interface Driver {
const RIGHTS_GLOBAL_ADMIN = 100; // is completely unrestricted
// returns an instance of a class implementing this interface. Implemented as a static method for consistency with database classes
static function create(\JKingWeb\NewsSync\RuntimeData $data): Driver;
function __construct(\JKingWeb\NewsSync\RuntimeData $data);
// returns a human-friendly name for the driver (for display in installer, for example)
static function driverName(): string;
// returns an array (or single queried member of same) of methods defined by this interface and whether the class implements the internal function or a custom version

Loading…
Cancel
Save