|
|
@@ -5,35 +5,39 @@
|
|
|
*/
|
|
|
|
|
|
/**
|
|
|
- * Le Dispatcher s'occupe d'initialiser le Controller et d'executer l'action
|
|
|
- * déterminée dans la Request
|
|
|
- * C'est un singleton
|
|
|
+ * The Dispatcher is in charge of initialising the Controller and exectue the action as specified in the Request object.
|
|
|
+ * It is a singleton.
|
|
|
*/
|
|
|
class Minz_Dispatcher {
|
|
|
|
|
|
- /* singleton */
|
|
|
- private static $instance = null;
|
|
|
+ /**
|
|
|
+ * Singleton
|
|
|
+ * @var Minz_Dispatcher|null
|
|
|
+ */
|
|
|
+ private static $instance;
|
|
|
+ /** @var bool */
|
|
|
private static $needsReset;
|
|
|
- private static $registrations = array();
|
|
|
-
|
|
|
+ /** @var array<string,string> */
|
|
|
+ private static $registrations = [];
|
|
|
+ /** @var Minz_ActionController */
|
|
|
private $controller;
|
|
|
|
|
|
/**
|
|
|
- * Récupère l'instance du Dispatcher
|
|
|
+ * Retrieves the Dispatcher instance
|
|
|
*/
|
|
|
- public static function getInstance () {
|
|
|
+ public static function getInstance(): Minz_Dispatcher {
|
|
|
if (self::$instance === null) {
|
|
|
- self::$instance = new Minz_Dispatcher ();
|
|
|
+ self::$instance = new Minz_Dispatcher();
|
|
|
}
|
|
|
return self::$instance;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Lance le controller indiqué dans Request
|
|
|
- * Remplit le body de Response à partir de la Vue
|
|
|
+ * Launches the controller specified in Request
|
|
|
+ * Fills the Response body from the View
|
|
|
* @throws Minz_Exception
|
|
|
*/
|
|
|
- public function run () {
|
|
|
+ public function run(): void {
|
|
|
do {
|
|
|
self::$needsReset = false;
|
|
|
|
|
|
@@ -63,19 +67,19 @@ class Minz_Dispatcher {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Informe le contrôleur qu'il doit recommancer car la requête a été modifiée
|
|
|
+ * Informs the controller that it must restart because the request has been modified
|
|
|
*/
|
|
|
- public static function reset() {
|
|
|
+ public static function reset(): void {
|
|
|
self::$needsReset = true;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Instancie le Controller
|
|
|
- * @param string $base_name le nom du controller à instancier
|
|
|
- * @throws Minz_ControllerNotExistException le controller n'existe pas
|
|
|
- * @throws Minz_ControllerNotActionControllerException controller n'est pas une instance de ActionController
|
|
|
+ * Instantiates the Controller
|
|
|
+ * @param string $base_name the name of the controller to instantiate
|
|
|
+ * @throws Minz_ControllerNotExistException the controller does not exist
|
|
|
+ * @throws Minz_ControllerNotActionControllerException controller is not an instance of ActionController
|
|
|
*/
|
|
|
- private function createController ($base_name) {
|
|
|
+ private function createController(string $base_name): void {
|
|
|
if (self::isRegistered($base_name)) {
|
|
|
self::loadController($base_name);
|
|
|
$controller_name = 'FreshExtension_' . $base_name . '_Controller';
|
|
|
@@ -99,11 +103,11 @@ class Minz_Dispatcher {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Lance l'action sur le controller du dispatcher
|
|
|
- * @param string $action_name le nom de l'action
|
|
|
- * @throws Minz_ActionException si on ne peut pas exécuter l'action sur le controller
|
|
|
+ * Launch the action on the dispatcher’s controller
|
|
|
+ * @param string $action_name the name of the action
|
|
|
+ * @throws Minz_ActionException if the action cannot be executed on the controller
|
|
|
*/
|
|
|
- private function launchAction ($action_name) {
|
|
|
+ private function launchAction(string $action_name): void {
|
|
|
if (!is_callable (array (
|
|
|
$this->controller,
|
|
|
$action_name
|
|
|
@@ -126,7 +130,7 @@ class Minz_Dispatcher {
|
|
|
* @param string $base_name the base name of the controller (i.e. ./?c=<base_name>)
|
|
|
* @param string $base_path the base path where we should look into to find info.
|
|
|
*/
|
|
|
- public static function registerController($base_name, $base_path) {
|
|
|
+ public static function registerController(string $base_name, string $base_path): void {
|
|
|
if (!self::isRegistered($base_name)) {
|
|
|
self::$registrations[$base_name] = $base_path;
|
|
|
}
|
|
|
@@ -138,7 +142,7 @@ class Minz_Dispatcher {
|
|
|
* @param string $base_name the base name of the controller.
|
|
|
* @return boolean true if the controller has been registered, false else.
|
|
|
*/
|
|
|
- public static function isRegistered($base_name) {
|
|
|
+ public static function isRegistered(string $base_name) {
|
|
|
return isset(self::$registrations[$base_name]);
|
|
|
}
|
|
|
|
|
|
@@ -147,14 +151,9 @@ class Minz_Dispatcher {
|
|
|
*
|
|
|
* @param string $base_name the base name of the controller.
|
|
|
*/
|
|
|
- private static function loadController($base_name) {
|
|
|
+ private static function loadController(string $base_name): void {
|
|
|
$base_path = self::$registrations[$base_name];
|
|
|
$controller_filename = $base_path . '/Controllers/' . $base_name . 'Controller.php';
|
|
|
include_once $controller_filename;
|
|
|
}
|
|
|
-
|
|
|
- private static function setViewPath($controller, $base_name) {
|
|
|
- $base_path = self::$registrations[$base_name];
|
|
|
- $controller->view()->setBasePathname($base_path);
|
|
|
- }
|
|
|
}
|