From ceea88fbcbc45cbc557b656d7a706c268e65f972 Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Thu, 4 Feb 2016 20:02:12 +0100 Subject: [PATCH] - [x] Module Dispatcher - [x] Module Request Refactor et operationnel, mais a opti --- automate.php | 2 +- config/modules.json | 4 ++-- manager/ModuleDispatcher.php | 12 ++++++++++++ manager/ModuleRequest.php | 22 ++++++++++++++++++++++ manager/module/firstModule.php | 20 ++++++++++++++++++++ todo.md | 2 +- 6 files changed, 58 insertions(+), 4 deletions(-) create mode 100644 manager/module/firstModule.php diff --git a/automate.php b/automate.php index afbb932..5c5ed16 100644 --- a/automate.php +++ b/automate.php @@ -69,7 +69,7 @@ */ function testModuleDispatcher(){ - $req1 = new manager\ModuleRequest('firstModule/a', array('id_user' => 10) ); + $req1 = new manager\ModuleRequest('firstModule/returnvar', array('id_user' => 10) ); $req2 = manager\ModuleRequest::fromString('{"path": "firstModule/a", "data": [{"id_user":10}]}'); diff --git a/config/modules.json b/config/modules.json index c80e321..48b5a1f 100755 --- a/config/modules.json +++ b/config/modules.json @@ -3,8 +3,8 @@ "a", "b", "c", - "d", - "e" + "returnvar", + "printvar" ], "secondModule" : [ diff --git a/manager/ModuleDispatcher.php b/manager/ModuleDispatcher.php index 937603a..fddd406 100644 --- a/manager/ModuleDispatcher.php +++ b/manager/ModuleDispatcher.php @@ -35,7 +35,19 @@ if( !($request instanceof ModuleRequest) ) // Si c'est pas une instance de return false; // On retourne FALSE, si erreur + /* [2] Execution de la methode specifiee + =========================================================*/ + try{ + $result = call_user_func_array($request->getFunctionCaller(), $request->getData() ); + var_dump('result = '.$result); + + // Si erreur, on retourne une exception + }catch(Exception $e){ + var_dump('erreur de fonction'); + return false; + } + return true; diff --git a/manager/ModuleRequest.php b/manager/ModuleRequest.php index bf8ebb2..66c9312 100644 --- a/manager/ModuleRequest.php +++ b/manager/ModuleRequest.php @@ -150,6 +150,28 @@ + + + /* RENVOI LE CHEMIN D'AMORCAGE DE LA METHODE + * + * @return path Retourne le chemin d'amorcage de la requete + * + */ + public function getFunctionCaller(){ + return 'manager\\module\\'.$this->path['module'].'::'.$this->path['method']; + } + + /* RENVOI LES DONNEES + * + * @return data Retourne les donnees de la requete + * + */ + public function getData(){ + return $this->data; + } + + + } ?> \ No newline at end of file diff --git a/manager/module/firstModule.php b/manager/module/firstModule.php new file mode 100644 index 0000000..b5d496a --- /dev/null +++ b/manager/module/firstModule.php @@ -0,0 +1,20 @@ + \ No newline at end of file diff --git a/todo.md b/todo.md index 0a84817..355c308 100755 --- a/todo.md +++ b/todo.md @@ -14,7 +14,7 @@ # EN COURS # ############ - [ ] Conception du systeme de delegation des managers - - [.] Module Dispatcher + - [x] Module Dispatcher - [x] Module Request - [ ] Module Answer