A free, self-hostable news aggregator…
Give possibility to register a new Controller.
Marien Fressinaudf8aa66152fca
diff --git a/lib/Minz/Dispatcher.php b/lib/Minz/Dispatcher.phpindex f62a92911..66789a3d3 100644--- a/lib/Minz/Dispatcher.php+++ b/lib/Minz/Dispatcher.php@@ -15,6 +15,7 @@ class Minz_Dispatcher {/* singleton */private static $instance = null;private static $needsReset;+ private static $registrations = array();private $controller;@@ -38,7 +39,7 @@ class Minz_Dispatcher {self::$needsReset = false;try {- $this->createController ('FreshRSS_' . Minz_Request::controllerName () . '_Controller');+ $this->createController (Minz_Request::controllerName ());$this->controller->init ();$this->controller->firstAction ();if (!self::$needsReset) {@@ -73,8 +74,11 @@ class Minz_Dispatcher {* > pas une instance de ActionController*/private function createController ($controller_name) {- $filename = APP_PATH . self::CONTROLLERS_PATH_NAME . '/'- . $controller_name . '.php';+ if (self::isRegistered($controller_name)) {+ $controller_name = self::loadController($controller_name);+ } else {+ $controller_name = 'FreshRSS_' . $controller_name . '_Controller';+ }if (!class_exists ($controller_name)) {throw new Minz_ControllerNotExistException (@@ -114,4 +118,41 @@ class Minz_Dispatcher {$action_name));}++ /**+ * Register a controller file.+ *+ * @param $base_name the base name of the controller (i.e. ./?c=<base_name>)+ * @param $controller_name the name of the controller (e.g. HelloWorldController).+ * @param $filename the file which contains the controller.+ */+ public static function registerController($base_name, $controller_name, $filename) {+ if (file_exists($filename)) {+ self::$registrations[$base_name] = array(+ $controller_name,+ $filename,+ );+ }+ }++ /**+ * Return if a controller is registered.+ *+ * @param $base_name the base name of the controller.+ * @return true if the controller has been registered, false else.+ */+ public static function isRegistered($base_name) {+ return isset(self::$registrations[$base_name]);+ }++ /**+ * Load a controller file (include) and return its name.+ *+ * @param $base_name the base name of the controller.+ */+ private static function loadController($base_name) {+ list($controller_name, $filename) = self::$registrations[$base_name];+ include($filename);+ return $controller_name;+ }}diff --git a/lib/Minz/Extension.php b/lib/Minz/Extension.phpindex a1fdd659b..ad3465640 100644--- a/lib/Minz/Extension.php+++ b/lib/Minz/Extension.php@@ -136,4 +136,17 @@ class Minz_Extension {'&' . $mtime;return Minz_Url::display($url);}++ /**+ * 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) {+ $controller_name = 'FreshExtension_' . $base_name . '_Controller';+ $filename = $this->path . '/controllers/' . $base_name . 'Controller.php';++ Minz_Dispatcher::registerController($base_name, $controller_name, $filename);+ }}