diff --git a/Controleurs/ControleurHelloworld.php b/Controleurs/ControleurHelloworld.php deleted file mode 100644 index 68019a1..0000000 --- a/Controleurs/ControleurHelloworld.php +++ /dev/null @@ -1,19 +0,0 @@ - $O_helloworld->donneMessage())); - - } - - public function testformAction(Array $A_parametres = null, Array $A_postParams = null) - { - - Vue::montrer('helloworld/testform', array('formData' => $A_postParams)); - - } - -} \ No newline at end of file diff --git a/Controllers/HelloworldController.php b/Controllers/HelloworldController.php new file mode 100644 index 0000000..448a2c8 --- /dev/null +++ b/Controllers/HelloworldController.php @@ -0,0 +1,19 @@ + $O_helloworld->donneMessage())); + + } + + public function testformAction(Array $A_urlParams = null, Array $A_postParams = null) + { + + View::show('helloworld/testform', array('formData' => $A_postParams)); + + } + +} \ No newline at end of file diff --git a/Kernel/AutoLoad.php b/Kernel/AutoLoad.php new file mode 100644 index 0000000..230177e --- /dev/null +++ b/Kernel/AutoLoad.php @@ -0,0 +1,54 @@ +_A_urlParts['controller'] = array_shift($_A_urlParts); + $this->_A_urlParts['action'] = array_shift($_A_urlParts); + + $this->_A_urlParametres = $_A_urlParts; + + $this->_A_postParams = $A_postParams; + + + } + + // Execute the controller and action deduced + + public function execute() + { + if (!class_exists($this->_A_urlParts['controller'])) { + throw new ControllerException("Controller " . $this->_A_urlParts['controller'] . " is not valid."); + } + + if (!method_exists($this->_A_urlParts['controller'], $this->_A_urlParts['action'])) { + throw new ControllerException("Action " . $this->_A_urlParts['action'] . " of controller " . + $this->_A_urlParts['controller'] . " is not valid."); + } + + + $B_called = call_user_func_array(array(new $this->_A_urlParts['controller'], + $this->_A_urlParts['action']), array($this->_A_urlParams, $this->_A_postParams )); + + if (false === $B_called) { + throw new ControllerException("Action " . $this->_A_urlParts['action'] . + " of controller " . $this->_A_urlParts['controller'] . " failed."); + } + } +} \ No newline at end of file diff --git a/Kernel/Exceptions/ControllerException.php b/Kernel/Exceptions/ControllerException.php new file mode 100644 index 0000000..b529795 --- /dev/null +++ b/Kernel/Exceptions/ControllerException.php @@ -0,0 +1,3 @@ +_A_urlDecortique['controleur'] = array_shift($A_urlDecortique); // on recupere le contrôleur - $this->_A_urlDecortique['action'] = array_shift($A_urlDecortique); // puis l'action - - // ...on stocke ces éventuels parametres dans la variable d'instance qui leur est réservée - $this->_A_urlParametres = $A_urlDecortique; - - // On s'occupe du tableau $A_postParams - $this->_A_postParams = $A_postParams; - - - } - - // On exécute notre triplet - - public function executer() - { - if (!class_exists($this->_A_urlDecortique['controleur'])) { - throw new ControleurException($this->_A_urlDecortique['controleur'] . " n'est pas un controleur valide."); - } - - if (!method_exists($this->_A_urlDecortique['controleur'], $this->_A_urlDecortique['action'])) { - throw new ControleurException($this->_A_urlDecortique['action'] . " du contrôleur " . - $this->_A_urlDecortique['controleur'] . " n'est pas une action valide."); - } - - $B_called = call_user_func_array(array(new $this->_A_urlDecortique['controleur'], - $this->_A_urlDecortique['action']), array($this->_A_urlParametres, $this->_A_postParams )); - - if (false === $B_called) { - throw new ControleurException("L'action " . $this->_A_urlDecortique['action'] . - " du contrôleur " . $this->_A_urlDecortique['controleur'] . " a rencontré une erreur."); - } - } -} \ No newline at end of file diff --git a/Noyau/Exceptions/ControleurException.php b/Noyau/Exceptions/ControleurException.php deleted file mode 100644 index 045e712..0000000 --- a/Noyau/Exceptions/ControleurException.php +++ /dev/null @@ -1,3 +0,0 @@ -

Titre

'; +

Titre

'; diff --git a/Vues/helloworld/testform.php b/Views/helloworld/testform.php similarity index 100% rename from Vues/helloworld/testform.php rename to Views/helloworld/testform.php diff --git a/Views/helloworld/view.php b/Views/helloworld/view.php new file mode 100644 index 0000000..8749713 --- /dev/null +++ b/Views/helloworld/view.php @@ -0,0 +1,3 @@ +" . $A_view['helloworld'] . "

"; diff --git a/Vues/gabarit.php b/Views/html.php similarity index 57% rename from Vues/gabarit.php rename to Views/html.php index fb18d10..6f8891d 100644 --- a/Vues/gabarit.php +++ b/Views/html.php @@ -1,12 +1,12 @@ - - - - - My sweet MVC - - - - - - + + + + + My sweet MVC + + + + + + \ No newline at end of file diff --git a/Vues/helloworld/voir.php b/Vues/helloworld/voir.php deleted file mode 100644 index b8fdb6b..0000000 --- a/Vues/helloworld/voir.php +++ /dev/null @@ -1,3 +0,0 @@ -" . $A_vue['helloworld'] . "

"; diff --git a/index.php b/index.php index 57665cc..f0c3424 100644 --- a/index.php +++ b/index.php @@ -1,46 +1,28 @@ load(); - $S_urlADecortiquer = isset($_GET['url']) ? $_GET['url'] : null; + $S_url = isset($_GET['url']) ? $_GET['url'] : null; $A_postParams = isset($_POST) ? $_POST : null; - Vue::ouvrirTampon(); // on ouvre le tampon d'affichage, les contrôleurs qui appellent des vues les mettront dedans + View::openBuffer(); try { - $O_controleur = new Controleur($S_urlADecortiquer, $A_postParams); - $O_controleur->executer(); + $O_controller = new Controller($S_url, $A_postParams); + $O_controller->execute(); } catch (ControleurException $O_exception) { - echo ('Une erreur s\'est produite : ' . $O_exception->getMessage()); + echo ('An error occured: ' . $O_exception->getMessage()); } - // Les différentes sous-vues ont été "crachées" dans le tampon d'affichage, on les récupère - $contenuPourAffichage = Vue::recupererContenuTampon(); + $content = View::closeBuffer(); - // On affiche le contenu dans la partie body du gabarit général - Vue::montrer('gabarit', array('body' => $contenuPourAffichage)); \ No newline at end of file + View::show('html', array('body' => $content)); \ No newline at end of file