|
|
@@ -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;
|
|
|
+ }
|
|
|
}
|