refactor
This commit is contained in:
parent
73c7f7f587
commit
09b51d0db7
17
index.php
17
index.php
|
@ -24,10 +24,6 @@ class ConnectionManager {
|
|||
abstract class BaseModel {
|
||||
protected static $sql = null;
|
||||
|
||||
public function __construct(ISqlBase $sql) {
|
||||
self::$sql = $sql;
|
||||
}
|
||||
|
||||
public static function Get(int $id) {
|
||||
self::Initialize();
|
||||
return ConnectionManager::Query(
|
||||
|
@ -36,7 +32,11 @@ abstract class BaseModel {
|
|||
get_called_class());
|
||||
}
|
||||
|
||||
abstract private static function Initialize();
|
||||
private static function Initialize() {
|
||||
if (self::$sql === null) {
|
||||
throw new Exception('sql not inited');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class JobSql implements ISqlBase {
|
||||
|
@ -47,15 +47,10 @@ class JobSql implements ISqlBase {
|
|||
}
|
||||
|
||||
class Job extends BaseModel {
|
||||
private $sql = new JobSql();
|
||||
public function __construct() {
|
||||
parent::__construct( new JobSql() );
|
||||
}
|
||||
|
||||
private static function Initialize() {
|
||||
if (self::$sql === null) {
|
||||
self::$sql = new JobSql();
|
||||
}
|
||||
}
|
||||
}
|
||||
$dns = 'pgsql:host=localhost;port=5432;dbname=dynamic_dev;user=test;password=pass123';
|
||||
ConnectionManager::Connect($dns);
|
||||
|
|
Loading…
Reference in New Issue