From: Andrey Kutejko Date: Wed, 20 Mar 2019 21:32:12 +0000 (+0100) Subject: properly initialize db X-Git-Url: https://git.andy128k.dev/?a=commitdiff_plain;h=f76f70db7d3f7ade7c761b041e9a58fa418c8986;p=ipf-legacy-orm.git properly initialize db --- diff --git a/src/app.php b/src/app.php index 2e574cb..e8579ef 100644 --- a/src/app.php +++ b/src/app.php @@ -9,6 +9,7 @@ class IPF_Legacy_ORM_App extends IPF_Application { $this->container = $container; $this->project_root = $container['settings']->get('project_root'); + IPF_ORM_Manager::getInstance()->setContainer($container); } private static $appModels = array(); diff --git a/src/middleware.php b/src/middleware.php deleted file mode 100644 index 5fc3db0..0000000 --- a/src/middleware.php +++ /dev/null @@ -1,11 +0,0 @@ -container['db']->getWrappedConnection(); - IPF_ORM_Manager::getInstance()->setConnection($pdo); - return false; - } -} diff --git a/src/orm/manager.php b/src/orm/manager.php index 1bb530d..677563d 100644 --- a/src/orm/manager.php +++ b/src/orm/manager.php @@ -5,6 +5,7 @@ class IPF_ORM_Manager extends IPF_ORM_Configurable protected $_connection = null; protected $_queryRegistry; public $dbListeners = array(); + private $_container = null; private function __construct() { @@ -46,13 +47,17 @@ class IPF_ORM_Manager extends IPF_ORM_Configurable return IPF_ORM_Manager::getInstance()->getCurrentConnection(); } - public function setConnection(PDO $pdo) + public function setContainer($container) { - $this->_connection = new IPF_ORM_Connection_Mysql($this, $pdo); + $this->_container = $container; } public function getCurrentConnection() { + if ($this->_connection === null) { + $pdo = $this->_container['db']->getWrappedConnection(); + $this->_connection = new IPF_ORM_Connection_Mysql($this, $pdo); + } return $this->_connection; } @@ -61,4 +66,3 @@ class IPF_ORM_Manager extends IPF_ORM_Configurable return "
\nIPF_ORM_Manager\n
"; } } -