]> git.andy128k.dev Git - ipf-legacy-orm.git/commitdiff
add configuration middleware
authorAndrey Kutejko <andy128k@gmail.com>
Fri, 15 Mar 2019 00:04:07 +0000 (01:04 +0100)
committerAndrey Kutejko <andy128k@gmail.com>
Fri, 15 Mar 2019 00:04:07 +0000 (01:04 +0100)
src/middleware.php [new file with mode: 0644]
src/orm/manager.php

diff --git a/src/middleware.php b/src/middleware.php
new file mode 100644 (file)
index 0000000..5fc3db0
--- /dev/null
@@ -0,0 +1,11 @@
+<?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 570de3379e61ea6606ca7ce6dead21c84a0d5fdb..1bb530d3e75159bbaf137b39a9217a6bddb96d67 100644 (file)
@@ -46,12 +46,13 @@ class IPF_ORM_Manager extends IPF_ORM_Configurable
         return IPF_ORM_Manager::getInstance()->getCurrentConnection();
     }
 
+    public function setConnection(PDO $pdo)
+    {
+        $this->_connection = new IPF_ORM_Connection_Mysql($this, $pdo);
+    }
+
     public function getCurrentConnection()
     {
-        if (!$this->_connection) {
-            $pdo = \PFF\Container::databaseConnection();
-            $this->_connection = new IPF_ORM_Connection_Mysql($this, $pdo);
-        }
         return $this->_connection;
     }