/** * Récupère l'instance du Dispatcher */ public static function getInstance($router) { if (self::$instance === null) { self::$instance = new Minz_Dispatcher($router); } return self::$instance; }
/** * Constructeur * Initialise le dispatcher, met à jour la Request */ public function __construct() { try { Minz_Configuration::register('system', DATA_PATH . '/config.php', DATA_PATH . '/config.default.php'); $this->setReporting(); Minz_Request::init(); $url = $this->buildUrl(); $url['params'] = array_merge($url['params'], Minz_Request::fetchPOST()); Minz_Request::forward($url); } catch (Minz_Exception $e) { Minz_Log::error($e->getMessage()); $this->killApp($e->getMessage()); } $this->dispatcher = Minz_Dispatcher::getInstance(); }
/** * Constructeur * Initialise le router et le dispatcher */ public function __construct() { if (LOG_PATH === false) { $this->killApp('Path not found: LOG_PATH'); } try { Minz_Configuration::init(); Minz_Request::init(); $this->router = new Minz_Router(); $this->router->init(); } catch (Minz_RouteNotFoundException $e) { Minz_Log::record($e->getMessage(), Minz_Log::ERROR); Minz_Error::error(404, array('error' => array($e->getMessage()))); } catch (Minz_Exception $e) { Minz_Log::record($e->getMessage(), Minz_Log::ERROR); $this->killApp($e->getMessage()); } $this->dispatcher = Minz_Dispatcher::getInstance($this->router); }
/** * Register a controller in the Dispatcher. * * @param @base_name the base name of the controller. Final name will be: * FreshExtension_<base_name>_Controller. */ public function registerController($base_name) { Minz_Dispatcher::registerController($base_name, $this->path); }
/** * Relance une requête * @param $url l'url vers laquelle est relancée la requête * @param $redirect si vrai, force la redirection http * > sinon, le dispatcher recharge en interne */ public static function forward($url = array(), $redirect = false) { if (!is_array($url)) { header('Location: ' . $url); exit; } $url = Minz_Url::checkUrl($url); if ($redirect) { header('Location: ' . Minz_Url::display($url, 'php')); exit; } else { self::_controllerName($url['c']); self::_actionName($url['a']); self::_params(array_merge(self::$params, $url['params'])); Minz_Dispatcher::reset(); } }
/** * Informe le contrôleur qu'il doit recommancer car la requête a été modifiée */ public static function reset() { self::$needsReset = true; }