This commit is contained in:
Michał Sieciechowicz 2021-02-26 22:39:06 +01:00
parent f03431dc70
commit 73c7f7f587
1 changed files with 11 additions and 2 deletions

View File

@ -22,18 +22,21 @@ class ConnectionManager {
} }
} }
abstract class BaseModel { abstract class BaseModel {
protected static $sql; protected static $sql = null;
public function __construct(ISqlBase $sql) { public function __construct(ISqlBase $sql) {
self::$sql = $sql; self::$sql = $sql;
} }
public static function Get(int $id) { public static function Get(int $id) {
self::Initialize();
return ConnectionManager::Query( return ConnectionManager::Query(
self::$sql->Get(), self::$sql->Get(),
[], [],
get_called_class()); get_called_class());
} }
abstract private static function Initialize();
} }
class JobSql implements ISqlBase { class JobSql implements ISqlBase {
@ -47,13 +50,19 @@ class Job extends BaseModel {
public function __construct() { public function __construct() {
parent::__construct( new JobSql() ); 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'; $dns = 'pgsql:host=localhost;port=5432;dbname=dynamic_dev;user=test;password=pass123';
ConnectionManager::Connect($dns); ConnectionManager::Connect($dns);
echo " echo "
"; ";
echo Job::Get(10); var_dump(Job::Get(10));
echo " echo "
"; ";