]> git.andy128k.dev Git - ipf-legacy-orm.git/commitdiff
properly initialize db
authorAndrey Kutejko <andy128k@gmail.com>
Wed, 20 Mar 2019 21:32:12 +0000 (22:32 +0100)
committerAndrey Kutejko <andy128k@gmail.com>
Wed, 20 Mar 2019 21:32:12 +0000 (22:32 +0100)
src/app.php
src/middleware.php [deleted file]
src/orm/manager.php

index 2e574cbb7e0519f14ff765d68af53f950b33cb01..e8579efb9174e420cdfd4b1f5347fbb352f490b1 100644 (file)
@@ -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 (file)
index 5fc3db0..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-<?php
-
-class IPF_ORM_Middleware extends IPF_Middleware
-{
-    function processRequest($request)
-    {
-        $pdo = $this->container['db']->getWrappedConnection();
-        IPF_ORM_Manager::getInstance()->setConnection($pdo);
-        return false;
-    }
-}
index 1bb530d3e75159bbaf137b39a9217a6bddb96d67..677563d3ee169c069c212cb1f99afb03bc4a50cf 100644 (file)
@@ -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 "<pre>\nIPF_ORM_Manager\n</pre>";
     }
 }
-