From 2230dd4e6b148346c0ec596b9e3e12996a762ed8 Mon Sep 17 00:00:00 2001 From: Frédéric Guillot Date: Thu, 22 May 2014 12:28:28 -0400 Subject: Code refactoring (add autoloader and change files organization) --- core/router.php | 66 --------------------------------------------------------- 1 file changed, 66 deletions(-) delete mode 100644 core/router.php (limited to 'core/router.php') diff --git a/core/router.php b/core/router.php deleted file mode 100644 index 56a95e52..00000000 --- a/core/router.php +++ /dev/null @@ -1,66 +0,0 @@ -registry = $registry; - $this->controller = empty($_GET['controller']) ? $controller : $_GET['controller']; - $this->action = empty($_GET['action']) ? $controller : $_GET['action']; - } - - /** - * @param string $default_value - */ - public function sanitize($value, $default_value) - { - return ! ctype_alpha($value) || empty($value) ? $default_value : strtolower($value); - } - - /** - * @param string $filename - * @param string $class - */ - public function load($filename, $class, $method) - { - if (file_exists($filename)) { - - require $filename; - - if (! method_exists($class, $method)) return false; - - $instance = new $class($this->registry); - $instance->request = new Request; - $instance->response = new Response; - $instance->session = new Session; - $instance->template = new Template; - $instance->beforeAction($this->controller, $this->action); - $instance->$method(); - - return true; - } - - return false; - } - - public function execute() - { - $this->controller = $this->sanitize($this->controller, 'app'); - $this->action = $this->sanitize($this->action, 'index'); - - if (! $this->load('controllers/'.$this->controller.'.php', '\Controller\\'.$this->controller, $this->action)) { - die('Page not found!'); - } - } -} -- cgit v1.2.3