From 5149869952461b3c0a6e13b19d50cbf359dff431 Mon Sep 17 00:00:00 2001 From: Synox Date: Fri, 23 Feb 2018 22:02:22 +0100 Subject: [PATCH] cleanup --- src/index.php | 2 +- src/router.php | 19 +++++++++---------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/index.php b/src/index.php index b2ef149..6373137 100644 --- a/src/index.php +++ b/src/index.php @@ -14,7 +14,7 @@ require_once './autolink.php'; require_once './pages.php'; require_once './router.php'; -$router = Router::init(); +$router = new Router($_SERVER['REQUEST_METHOD'], $_GET['action'] ?? NULL, $_GET, $_POST, $_SERVER['QUERY_STRING'], $config); $page = $router->route(); $page->invoke(); diff --git a/src/router.php b/src/router.php index 3aef6e5..39db024 100644 --- a/src/router.php +++ b/src/router.php @@ -20,22 +20,21 @@ class Router { $this->config = $config; } - static function init(): Router { - global $config; - return new Router($_SERVER['REQUEST_METHOD'], $_GET['action'] ?? NULL, $_GET, $_POST, $_SERVER['QUERY_STRING'], $config); - - } - function route(): Page { - // TODO: use $this->action - if ($this->action === "redirect" && isset($this->post_vars['username']) && isset($this->post_vars['domain'])) { + if ($this->action === "redirect" + && isset($this->post_vars['username']) + && isset($this->post_vars['domain'])) { return new RedirectToAddressPage($this->post_vars['username'], $this->post_vars['domain']); - } elseif ($this->action === "download_email" && isset($this->get_vars['download_email_id']) && isset($this->get_vars['address'])) { + } elseif ($this->action === "download_email" + && isset($this->get_vars['download_email_id']) + && isset($this->get_vars['address'])) { return new DownloadEmailPage($this->get_vars['download_email_id'], $this->get_vars['address'], $this->config['domains']); - } elseif ($this->action === "delete_email" && isset($this->get_vars['delete_email_id']) && isset($this->get_vars['address'])) { + } elseif ($this->action === "delete_email" + && isset($this->get_vars['delete_email_id']) + && isset($this->get_vars['address'])) { return new DeleteEmailPage($this->get_vars['delete_email_id'], $this->get_vars['address'], $this->config['domains']); } elseif ($this->action === 'random') {