Api: Route action param can be Callable ([$obj, $method])
This commit is contained in:
16
application/Api/v1/Preorder/Preorder_Cif.php
Normal file
16
application/Api/v1/Preorder/Preorder_Cif.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
class Preorder_Cif {
|
||||
|
||||
public function providerSetCif($code) {
|
||||
return mfResponse::Ok(["message" => "in providerSetCif($code)"]);
|
||||
}
|
||||
|
||||
public function getCifData() {
|
||||
return mfResponse::Ok(["message" => "in getCifData()"]);
|
||||
}
|
||||
|
||||
public function userSetCif() {
|
||||
return mfResponse::Ok(["message" => "in userSetCif()"]);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
require_once(APPDIR."/Api/v1/Preorder/Preorder_Cif.php");
|
||||
|
||||
class PreorderApicontroller extends mfBaseApicontroller {
|
||||
//private $filter_gemeinde_ids = [];
|
||||
//private $campaign;
|
||||
@@ -19,10 +21,17 @@ class PreorderApicontroller extends mfBaseApicontroller {
|
||||
protected function init() {
|
||||
$db = $this->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;
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user