From d4f35691c033645ceb16408f47054de11cb514b9 Mon Sep 17 00:00:00 2001 From: Stricted Date: Sun, 17 Jul 2016 07:54:51 +0200 Subject: [PATCH] small change for later --- lib/system/DNS.class.php | 17 +++++++++++- lib/system/RequestHandler.class.php | 42 ++++++++++++++++++----------- 2 files changed, 43 insertions(+), 16 deletions(-) diff --git a/lib/system/DNS.class.php b/lib/system/DNS.class.php index a38dc6a..0679754 100644 --- a/lib/system/DNS.class.php +++ b/lib/system/DNS.class.php @@ -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); + } + } } } diff --git a/lib/system/RequestHandler.class.php b/lib/system/RequestHandler.class.php index 1877b48..724a5df 100644 --- a/lib/system/RequestHandler.class.php +++ b/lib/system/RequestHandler.class.php @@ -11,32 +11,44 @@ use Zend\Mvc\Router\SimpleRouteStack; * @license GNU Lesser General Public License * @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\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\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; -- 2.20.1