init
This commit is contained in:
		
							parent
							
								
									f03431dc70
								
							
						
					
					
						commit
						73c7f7f587
					
				
							
								
								
									
										13
									
								
								index.php
								
								
								
								
							
							
						
						
									
										13
									
								
								index.php
								
								
								
								
							|  | @ -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 " | ||||||
| 
 | 
 | ||||||
| ";
 | ";
 | ||||||
		Loading…
	
		Reference in New Issue