small change for later
authorStricted <info@stricted.net>
Sun, 17 Jul 2016 05:54:51 +0000 (07:54 +0200)
committerStricted <info@stricted.net>
Sun, 17 Jul 2016 05:54:51 +0000 (07:54 +0200)
lib/system/DNS.class.php
lib/system/RequestHandler.class.php

index a38dc6a3da0b8c2b9f72c63ecb30ea0c9fadf5eb..0679754ec79922e86cb2ad00838a5a24fbbb02f7 100644 (file)
@@ -65,7 +65,10 @@ class DNS {
                $this->initSession();
                $this->initLanguage();
                $this->initTPL();
-               new RequestHandler(self::$module);
+               
+               $requestHandler = RequestHandler::getInstance();
+               $requestHandler->setRoutes($module);
+               $requestHandler->handle();
        }
        
        /**
@@ -120,6 +123,18 @@ class DNS {
                                        require_once($classPath);
                                }
                        }
+                       else if ($abbreviation == "Zend") {
+                               $classPath = DNS_DIR.'/vendor/Zend/'.implode('/', $namespaces).'.php';
+                               if (file_exists($classPath)) {
+                                       require_once($classPath);
+                               }
+                       }
+                       else if ($abbreviation == "Interop") {
+                               $classPath = DNS_DIR.'/vendor/Interop/'.implode('/', $namespaces).'.php';
+                               if (file_exists($classPath)) {
+                                       require_once($classPath);
+                               }
+                       }
                }
        }
        
index 1877b484c46fed36c33cb75da0013a77d80546b3..724a5df74518153da5565f96ea18876fdf1a1187 100644 (file)
@@ -11,32 +11,44 @@ use Zend\Mvc\Router\SimpleRouteStack;
  * @license     GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
  * @copyright   2013-2016 Jan Altensen (Stricted)
  */
-class RequestHandler {
-       protected $pattern = "";
-       protected $routeData = array();
+class RequestHandler extends SingletonFactory {
+       protected $router = null;
        
        /**
         * init RequestHandler
         */
-       public function __construct ($module = '') {
+       protected function init () {
+               $this->router = new SimpleRouteStack();
                if (DNS::getSession()->username !== null) {
                        DNS::getTPL()->assign(array("username" => DNS::getSession()->username));
                }
                else {
                        DNS::getTPL()->assign(array("username" => ''));
                }
+       }
+       
+       public function setRoutes($module='') {
+               if ($module == 'api') {
+                       //api routes
+               }
                
-               $router = new SimpleRouteStack();
-               
-               $router->addRoute('', Literal::factory([ 'route' => '', 'defaults' => [ 'controller' => 'dns\page\IndexPage' ] ]));
-               $router->addRoute('Index', Literal::factory([ 'route' => 'Index', 'defaults' => [ 'controller' => 'dns\page\IndexPage' ] ]));
-               $router->addRoute('Login', Literal::factory([ 'route' => 'Login', 'defaults' => [ 'controller' => 'dns\page\LoginPage' ] ]));
-               $router->addRoute('Logout', Literal::factory([ 'route' => 'Logout', 'defaults' => [ 'controller' => 'dns\page\LogoutPage' ] ]));
-               $router->addRoute('DomainList', Literal::factory([ 'route' => 'DomainList', 'defaults' => [ 'controller' => 'dns\page\DomainListPage' ] ]));
-               $router->addRoute('DomainAdd', Literal::factory([ 'route' => 'DomainAdd', 'defaults' => [ 'controller' => 'dns\page\DomainAddPage' ] ]));
-               //$router->addRoute('DomainEdit', Regex::factory([ 'regex' => 'DomainEdit/(?P<id>\d+)(/)?', 'defaults' => [ 'controller' => 'dns\page\DomainEditPage' ], 'spec' => '/DomainEdit/%id%' ]));
-               
-               $match = $router->match(new Request());
+               // default routes
+               $this->router->addRoute('', Literal::factory([ 'route' => '', 'defaults' => [ 'controller' => 'dns\page\IndexPage' ] ]));
+               $this->router->addRoute('Index', Literal::factory([ 'route' => 'Index', 'defaults' => [ 'controller' => 'dns\page\IndexPage' ] ]));
+               $this->router->addRoute('Login', Literal::factory([ 'route' => 'Login', 'defaults' => [ 'controller' => 'dns\page\LoginPage' ] ]));
+               $this->router->addRoute('Logout', Literal::factory([ 'route' => 'Logout', 'defaults' => [ 'controller' => 'dns\page\LogoutPage' ] ]));
+               $this->router->addRoute('DomainList', Literal::factory([ 'route' => 'DomainList', 'defaults' => [ 'controller' => 'dns\page\DomainListPage' ] ]));
+               $this->router->addRoute('DomainAdd', Literal::factory([ 'route' => 'DomainAdd', 'defaults' => [ 'controller' => 'dns\page\DomainAddPage' ] ]));
+               $this->router->addRoute('DomainEdit', Regex::factory([ 'regex' => 'DomainEdit/(?P<id>\d+)(/)?', 'defaults' => [ 'controller' => 'dns\page\DomainEditPage' ], 'spec' => '/DomainEdit/%id%' ]));
+       }       
+       
+       public function getRoutes() {
+               $this->router->getRoutes();
+       }
+       
+       public function handle () {
+               $match = $this->router->match(new Request());
+               var_dump($this->router->getRoutes());
                if ($match !== null) {
                        foreach ($match->getParams() as $key => $value) {
                                $_GET[$key] = $value;