/** * method: runService * * todo: write documentation */ public function runService() { // NOTE: This might be presumptuous to say every webservice will output it's data in JSON format // NOTE: obviously the webservice has an output format, we can detect session/json and set this appropriately Amslib_Shutdown::setMode("json"); $route = Amslib_Router::getRoute(); // NOTE: Perhaps die()'ing horribly like you just drove off a cliff in your // lamborghini with a martini in one hand, a hooker blowing you whilst // smoking an enormous cigar made of 100 dollar bills is NOT the best // way to handle failure? // NOTE: However, check all the route data is valid before using it if (!$route) { Amslib_Debug::log($m = __METHOD__ . ": route is invalid, check error log", $route); die($m); } if (!isset($route["group"]) || !strlen($route["group"])) { Amslib_Debug::log($m = __METHOD__ . ": route/group is invalid, check error log", $route); die($m); } if (!isset($route["name"]) || !strlen($route["name"])) { Amslib_Debug::log($m = __METHOD__ . ": route/name is invalid, check error log", $route); die($m); } if (!isset($route["handler"]) || !is_array($route["handler"]) || empty($route["handler"])) { Amslib_Debug::log($m = __METHOD__ . ": route/handler is invalid or empty, check error log", $route); die($m); } if (!isset($route["output"])) { Amslib_Debug::log($m = __METHOD__ . ": route/handler is invalid, there was no output specified", $route); die($m); } $this->api->setupService($route["group"], $route["name"]); $service = Amslib_Plugin_Service::getInstance(); $service->installHandlers($route["group"], $route["output"], $route["handler"]); $service->execute($route["optimise"]); }