diff --git a/classes/Dispatcher.php b/classes/Dispatcher.php new file mode 100644 index 000000000..13dee936d --- /dev/null +++ b/classes/Dispatcher.php @@ -0,0 +1,39 @@ +loadControllers(); + } + + public function dispatch() + { + $requested_controller = $this->getController(); + + $controller = $this->controllers[str_replace('-', '', strtolower($requested_controller))]; + ControllerFactory::getController($controller)->run(); + } + + protected function loadControllers() + { + $controller_files = scandir(_PS_ROOT_DIR_.DIRECTORY_SEPARATOR.'controllers'); + foreach($controller_files as $controller_filename) + { + if (substr($controller_filename, -14, 14) == 'Controller.php') + $this->controllers[strtolower(substr($controller_filename, 0, -14))] = basename($controller_filename, '.php'); + } + + // add default controller + $this->controllers['index'] = 'IndexController'; + $this->controllers['authentication'] = $this->controllers['auth']; + } + + public function getController() + { + return (isset($_GET['controller'])) ? $_GET['controller'] : 'index'; + } +} +