From 1e7a5e12a4075bbfc2945e5cd722ef71b4818cb1 Mon Sep 17 00:00:00 2001 From: Frank Schubert Date: Thu, 30 Nov 2023 16:28:18 +0100 Subject: [PATCH] Api: Route action param can be Callable ([$obj, $method]) --- application/Api/v1/Preorder/Preorder_Cif.php | 16 ++++++++++++++++ application/Api/v1/PreorderApicontroller.php | 11 ++++++++++- lib/mvcfronk/mfBase/mfBaseApicontroller.php | 15 ++++++++++----- 3 files changed, 36 insertions(+), 6 deletions(-) create mode 100644 application/Api/v1/Preorder/Preorder_Cif.php diff --git a/application/Api/v1/Preorder/Preorder_Cif.php b/application/Api/v1/Preorder/Preorder_Cif.php new file mode 100644 index 000000000..9655b7083 --- /dev/null +++ b/application/Api/v1/Preorder/Preorder_Cif.php @@ -0,0 +1,16 @@ + "in providerSetCif($code)"]); + } + + public function getCifData() { + return mfResponse::Ok(["message" => "in getCifData()"]); + } + + public function userSetCif() { + return mfResponse::Ok(["message" => "in userSetCif()"]); + } +} \ No newline at end of file diff --git a/application/Api/v1/PreorderApicontroller.php b/application/Api/v1/PreorderApicontroller.php index 18ed36381..ca28321d9 100644 --- a/application/Api/v1/PreorderApicontroller.php +++ b/application/Api/v1/PreorderApicontroller.php @@ -1,5 +1,7 @@ db(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME); - $this->addRoute("/preorder/open", "getOpenPreorders", "GET"); + $cifObject = new Preorder_Cif(); + $this->addRoute("/preorder", "submitPreorder", "POST"); + $this->addRoute("/preorder/open", "getOpenPreorders", "GET"); + $this->addRoute("/preorder/customerInstallationFeedback", [$cifObject, "getCifData"], "GET"); + $this->addRoute("/preorder/customerInstallationFeedback", [$cifObject, "userSetCif"], "POST"); + $this->addRoute("/preorder/:code", "getPreorder", "GET"); $this->addRoute("/preorder/:code", "cancelPreorder", "DELETE"); + $this->addRoute("/preorder/:code/clientInstallationFinished", [$cifObject, "providerSetCif"], "GET"); + $this->addRoute("/preorder/:code/serviceActivated", "setServiceActive", "POST"); $this->allowMissingOrigin = true; } diff --git a/lib/mvcfronk/mfBase/mfBaseApicontroller.php b/lib/mvcfronk/mfBase/mfBaseApicontroller.php index 69c6fb79e..ec603f9c5 100644 --- a/lib/mvcfronk/mfBase/mfBaseApicontroller.php +++ b/lib/mvcfronk/mfBase/mfBaseApicontroller.php @@ -436,10 +436,9 @@ class mfBaseApicontroller { } //var_dump($params);exit; - $req_parts = explode("/", $params); $req_count = count($req_parts); - + foreach($this->routes as $route) { if($route['method'] != $this->http_method) { continue; @@ -499,11 +498,17 @@ class mfBaseApicontroller { } private function call($function, $params = []) { + $args = $params; + if(count($params) === 1) { - return $this->__call($function,reset($params)); - } else { - return $this->__call($function,$params); + $args = reset($params); } + + if(is_array($function)) { + return call_user_func($function, $args); + } + + return $this->__call($function,$args); } protected function addRoute($route, $action, $method) {