try to switch to DI
authorStricted <info@stricted.net>
Thu, 21 Jul 2016 07:40:38 +0000 (09:40 +0200)
committerStricted <info@stricted.net>
Thu, 21 Jul 2016 07:40:38 +0000 (09:40 +0200)
lib/system/DNS.class.php
lib/system/RequestHandler.class.php
lib/system/helper/IDatabase.class.php [new file with mode: 0644]
lib/system/helper/TDatabase.class.php [new file with mode: 0644]

index dcb641ea3d3696b7a42dfa71ec400bb82d4b8768..5b26c32dea52e446ade9ed5a818e9cc3c61402bf 100644 (file)
@@ -69,6 +69,7 @@ class DNS {
                AclHandler::getInstance();
                
                $requestHandler = RequestHandler::getInstance();
+               $requestHandler->setDB(self::getDB());
                $requestHandler->setRoutes($module);
                $requestHandler->handle();
        }
index 13c29010b5b7b12710f0bb7bedecf6402f1704b1..0e889e38cb1c686f6baf940fa01daab3e48e2fa4 100644 (file)
@@ -1,6 +1,8 @@
 <?php
 namespace dns\system;
 use dns\system\cache\builder\ControllerCacheBuilder;
+use dns\system\helper\IDatabase;
+use dns\system\helper\TDatabase;
 use dns\system\route\Request;
 use dns\system\route\Segment;
 use Zend\Router\Http\RouteMatch;
@@ -11,7 +13,9 @@ use Zend\Router\SimpleRouteStack;
  * @license     GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
  * @copyright   2013-2016 Jan Altensen (Stricted)
  */
-class RequestHandler extends SingletonFactory {
+class RequestHandler extends SingletonFactory implements IDatabase {
+       use TDatabase;
+       
        protected $router = null;
        protected $apiModule = false;
        
@@ -109,7 +113,10 @@ class RequestHandler extends SingletonFactory {
                        }
                        
                        try {
-                               new $className();
+                               $page = new $className();
+                               if ($page instanceof IDatabase) {
+                                       $page->setDB($this->db);
+                               }
                        }
                        catch (\Exception $e) {
                                if ($e->getCode() == 404) {
diff --git a/lib/system/helper/IDatabase.class.php b/lib/system/helper/IDatabase.class.php
new file mode 100644 (file)
index 0000000..e59858e
--- /dev/null
@@ -0,0 +1,6 @@
+<?php
+namespace dns\system\helper;
+
+interface IDatabase {
+       public function setDB ($database);
+}
diff --git a/lib/system/helper/TDatabase.class.php b/lib/system/helper/TDatabase.class.php
new file mode 100644 (file)
index 0000000..408e6d7
--- /dev/null
@@ -0,0 +1,10 @@
+<?php
+namespace dns\system\helper;
+
+trait TDatabase {
+       private $db = null;
+       
+       public function setDB ($database) {
+               $this->db = $database;
+       }
+}