OPTIONS DIE*****" ); die(); } //$request = service('request'); // what is the endpoint $uri = urldecode(current_url(true)); $findme = '?'; $pos = strpos($uri, $findme); if ($pos > 5) { $uri = substr($uri, 0, $pos); } log_message('critical', "API-GATE URI -> ".$uri ); $pieces = explode('/', $uri); $psc = count($pieces); $endpoint = $psc > 0 ? $pieces[$psc - 1] : ''; log_message('critical', "Enpoint-> ".$endpoint ); $endpoints = $this->endPointList(); $out = array(); $res1 = []; if (array_key_exists($endpoint, $endpoints)) { } else { http_response_code(404); // tell the user product does not exist return json_encode([ 'message' => 'Endpoint not found.', 'URI' => $uri, ]); } // echo "EXYTACT INPUT DATA HERE"; $raw_json = file_get_contents('php://input'); $raw_array = json_decode($raw_json, true); $local_out =[]; if ($_SERVER["REQUEST_METHOD"] == "POST") { // if upload lets modify all the data if (isset($_FILES) && is_array($_FILES) && count($_FILES)>0) { $raw_array = array_merge($_POST,$_FILES); } } if ($_SERVER['REQUEST_METHOD'] == 'GET') { log_message('critical', "Enpoint LOC2 HERE -> ".$endpoint ); $get_param = $_GET['reqData'] ?? null; $raw_array = ($get_param!=null) ? json_decode($get_param, true):[]; } //$in = $raw_array; log_message('critical', "WrenchNotifications-CALL RAW DATA".serialize($raw_array) ); //-- move to another module start $in = $raw_array; $in["loc"] = $_SERVER["REMOTE_ADDR"]; switch ($endpoint){ case 'mynotifications': $call_backend = false; $local_out = $this->dummyData(); break; } $in["loc"] = $_SERVER["REMOTE_ADDR"]; log_message('critical', "wrenchboard_api-CALL PREPARE DATA".serialize($in) ); if ( $call_backend == true && $in["action"] !='' ){ $wrenchboard = new \App\Models\BackendModel(); $ret = $wrenchboard->wrenchboard_api($in, $out); $out['internal_return'] = $ret; } else { $out = $local_out; } $this->doCacheStep($in, $out); return json_encode( ( new \App\Models\ResultFormatter() )->processOutJson($in, $out)); return $this->response->setJson($response); } private function dummyData(){ $ic =['alert.svg','message.svg','phone.svg','sms.svg']; $total = rand(5,25); for ($i = 0; $i < $total; $i++) { $key = sprintf("%05d", $i); $data["result_list"][] = array( "icon" => $ic[rand(0,3)], "title" => "This is faq title dummy text ".$key, "date" => "10-10-2025 12:30PM", ); } return $data; } }