diff --git a/index.php b/index.php index 2e90ff3..063a87f 100644 --- a/index.php +++ b/index.php @@ -22,18 +22,21 @@ class ConnectionManager { } } abstract class BaseModel { - protected static $sql; + protected static $sql = null; public function __construct(ISqlBase $sql) { self::$sql = $sql; } public static function Get(int $id) { + self::Initialize(); return ConnectionManager::Query( self::$sql->Get(), [], get_called_class()); } + + abstract private static function Initialize(); } class JobSql implements ISqlBase { @@ -47,13 +50,19 @@ class Job extends BaseModel { 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); echo " "; -echo Job::Get(10); +var_dump(Job::Get(10)); echo " "; \ No newline at end of file