summaryrefslogtreecommitdiff
path: root/lib/minz/Dispatcher.php
diff options
context:
space:
mode:
authorGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2013-12-15 03:30:24 +0100
committerGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2013-12-15 03:30:24 +0100
commit878e96202e8a22e4857b98e29b0a1fce68eccbc9 (patch)
treef9233c3b48a0cd6e0ac2536ddcc1897201595ad4 /lib/minz/Dispatcher.php
parent4af233e1f736eb2256e5e1696418635165467855 (diff)
Grosse refactorisation pour permettre le chargement automatique des classes
C'est parti de changements pour https://github.com/marienfressinaud/FreshRSS/issues/255 et finalement j'ai continué la refactorisation... Ajout de préfixes FreshRSS_ et Minz_ sur le modèle de SimplePie_. Toutes les classes sont maintenant en chargement automatique (devrait améliorer les performances en évitant de charger plein de classes inutilisées, et faciliter la maintenance). Suppression de set_include_path(). Si souhaité, certaines classes de Minz pourraient être déplacées dans un sous-répertoire, par exemple les exceptions. Tests et relecture nécessaires.
Diffstat (limited to 'lib/minz/Dispatcher.php')
-rw-r--r--lib/minz/Dispatcher.php54
1 files changed, 20 insertions, 34 deletions
diff --git a/lib/minz/Dispatcher.php b/lib/minz/Dispatcher.php
index 0cfdd8e75..2898b5f00 100644
--- a/lib/minz/Dispatcher.php
+++ b/lib/minz/Dispatcher.php
@@ -9,8 +9,8 @@
* déterminée dans la Request
* C'est un singleton
*/
-class Dispatcher {
- const CONTROLLERS_PATH_NAME = '/controllers';
+class Minz_Dispatcher {
+ const CONTROLLERS_PATH_NAME = '/Controllers';
/* singleton */
private static $instance = null;
@@ -23,7 +23,7 @@ class Dispatcher {
*/
public static function getInstance ($router) {
if (is_null (self::$instance)) {
- self::$instance = new Dispatcher ($router);
+ self::$instance = new Minz_Dispatcher ($router);
}
return self::$instance;
}
@@ -38,7 +38,7 @@ class Dispatcher {
/**
* Lance le controller indiqué dans Request
* Remplit le body de Response à partir de la Vue
- * @exception MinzException
+ * @exception Minz_Exception
*/
public function run () {
$cache = new Minz_Cache();
@@ -53,29 +53,25 @@ class Dispatcher {
$cache->render ();
$text = ob_get_clean();
} else {
- while (Request::$reseted) {
- Request::$reseted = false;
+ while (Minz_Request::$reseted) {
+ Minz_Request::$reseted = false;
try {
- $this->createController (
- Request::controllerName ()
- . 'Controller'
- );
-
+ $this->createController ('FreshRSS_' . Minz_Request::controllerName () . '_Controller');
$this->controller->init ();
$this->controller->firstAction ();
$this->launchAction (
- Request::actionName ()
+ Minz_Request::actionName ()
. 'Action'
);
$this->controller->lastAction ();
- if (!Request::$reseted) {
+ if (!Minz_Request::$reseted) {
ob_start ();
$this->controller->view ()->build ();
$text = ob_get_clean();
}
- } catch (MinzException $e) {
+ } catch (Minz_Exception $e) {
throw $e;
}
}
@@ -85,14 +81,12 @@ class Dispatcher {
}
}
- Response::setBody ($text);
+ Minz_Response::setBody ($text);
}
/**
* Instancie le Controller
* @param $controller_name le nom du controller à instancier
- * @exception FileNotExistException le fichier correspondant au
- * > controller n'existe pas
* @exception ControllerNotExistException le controller n'existe pas
* @exception ControllerNotActionControllerException controller n'est
* > pas une instance de ActionController
@@ -101,26 +95,18 @@ class Dispatcher {
$filename = APP_PATH . self::CONTROLLERS_PATH_NAME . '/'
. $controller_name . '.php';
- if (!file_exists ($filename)) {
- throw new FileNotExistException (
- $filename,
- MinzException::ERROR
- );
- }
- require_once ($filename);
-
if (!class_exists ($controller_name)) {
- throw new ControllerNotExistException (
+ throw new Minz_ControllerNotExistException (
$controller_name,
- MinzException::ERROR
+ Minz_Exception::ERROR
);
}
$this->controller = new $controller_name ($this->router);
- if (! ($this->controller instanceof ActionController)) {
- throw new ControllerNotActionControllerException (
+ if (! ($this->controller instanceof Minz_ActionController)) {
+ throw new Minz_ControllerNotActionControllerException (
$controller_name,
- MinzException::ERROR
+ Minz_Exception::ERROR
);
}
}
@@ -129,18 +115,18 @@ class Dispatcher {
* Lance l'action sur le controller du dispatcher
* @param $action_name le nom de l'action
* @exception ActionException si on ne peut pas exécuter l'action sur
- * > le controller
+ * le controller
*/
private function launchAction ($action_name) {
- if (!Request::$reseted) {
+ if (!Minz_Request::$reseted) {
if (!is_callable (array (
$this->controller,
$action_name
))) {
- throw new ActionException (
+ throw new Minz_ActionException (
get_class ($this->controller),
$action_name,
- MinzException::ERROR
+ Minz_Exception::ERROR
);
}
call_user_func (array (