// dispatcher :)

This commit is contained in:
fBrignoli
2011-06-15 16:38:56 +00:00
parent 1bb4a61a42
commit 381ac0c2b2
+39
View File
@@ -0,0 +1,39 @@
<?php
class DispatcherCore
{
public $controllers;
function __construct()
{
$this->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';
}
}