From 09b51d0db7e6688e8de2282e9995db75f13c8fdb Mon Sep 17 00:00:00 2001 From: Sieciech Date: Fri, 26 Feb 2021 23:50:11 +0100 Subject: [PATCH] refactor --- index.php | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/index.php b/index.php index 063a87f..3a86230 100644 --- a/index.php +++ b/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);