. # # ***** END LICENSE BLOCK ***** /** * La classe FrontController est le Dispatcher du framework, elle lance l'application * Elle est appelée en général dans le fichier index.php à la racine du serveur */ class Minz_FrontController { protected $dispatcher; /** * Constructeur * Initialise le dispatcher, met à jour la Request */ public function __construct () { try { Minz_Configuration::init (); 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(); } /** * Retourne un tableau représentant l'url passée par la barre d'adresses * @return tableau représentant l'url */ private function buildUrl() { $url = array (); $url['c'] = Minz_Request::fetchGET ( 'c', Minz_Request::defaultControllerName () ); $url['a'] = Minz_Request::fetchGET ( 'a', Minz_Request::defaultActionName () ); $url['params'] = Minz_Request::fetchGET (); // post-traitement unset ($url['params']['c']); unset ($url['params']['a']); return $url; } /** * Démarre l'application (lance le dispatcher et renvoie la réponse) */ public function run () { try { $this->dispatcher->run(); } catch (Minz_Exception $e) { try { Minz_Log::error($e->getMessage()); } catch (Minz_PermissionDeniedException $e) { $this->killApp ($e->getMessage ()); } if ($e instanceof Minz_FileNotExistException || $e instanceof Minz_ControllerNotExistException || $e instanceof Minz_ControllerNotActionControllerException || $e instanceof Minz_ActionException) { Minz_Error::error ( 404, array ('error' => array ($e->getMessage ())), true ); } else { $this->killApp (); } } } /** * Permet d'arrêter le programme en urgence */ private function killApp ($txt = '') { if ($txt == '') { $txt = 'See logs files'; } exit ('### Application problem ###
'."\n".$txt); } }