function processRequest() { try { $resource = $this->getResource(); $api = new Models\Api($resource); return $api->process(); } catch (\PDOException $e) { $this->_response($e->getMessage(), 500); } catch (\HttpException $e) { $this->_response($e->getMessage(), 405); } catch (\Exception $e) { $this->_response($e->getMessage(), 404); } }
$config = $configPath . 'config.php'; $autoLoad = $configPath . 'autoload.php'; $routes = $configPath . 'routes.php'; use Models\Api; try { $app = new Application\Micro(); // Record any php warnings/errors set_error_handler(['Utilities\\Debug\\PhpError', 'errorHandler']); // Setup App (dependency injector, configuration variables and autoloading resources/classes) $app->setAutoload($autoLoad, $appDir); $app->setConfig($config); // Get Authentication Headers $clientId = $app->request->getHeader('API_ID'); $time = $app->request->getHeader('API_TIME'); $hash = $app->request->getHeader('API_HASH'); $privateKey = Api::findFirst($clientId)->private_key; $data = ${"_" . $_SERVER['REQUEST_METHOD']}; $message = new \Micro\Messages\Auth($clientId, $time, $hash, $data); // Setup HMAC Authentication callback to validate user before routing message // Failure to validate will stop the process before going to proper Restful Route $app->setEvents(new \Events\Api\HmacAuthenticate($message, $privateKey)); // Setup RESTful Routes $app->setRoutes($routes); // Boom, Run $app->run(); } catch (Exception $e) { // Do Something I guess, return Server Error message $app->response->setStatusCode(500, "Server Error"); $app->response->setContent($e->getMessage()); $app->response->send(); }