public static function deriveFromRequest(Request $request) { //build an empty header $headers = new Headers(); //analyze each possible acceptable encoding foreach ($request->getHeader('Accept') as $acceptable) { if (in_array($acceptable, ['text/yaml', 'text/x-yaml', 'application/yaml', 'application/x-yaml', 'application/xml', 'text/xml', 'application/json'])) { //select (and store) the content type $headers->set('Content-Type', $acceptable); //the content-type has been selected break; } } //build and return the response return new self(200, $headers); }
/** * Fullfill the request made by the client. */ public function FulfillRequest() { //get current request... $currentRequest = Request::createFromEnvironment(self::$currentEnvironment); //...and serve it $response = new Response(); try { //trigger the exception if data is malformed! $currentRequest->getDeserializedBody(); //include the list of routes (if it exists) if (file_exists(APPLICATION_DIR . 'routes.php')) { include APPLICATION_DIR . 'routes.php'; } //...and serve it $response = Route::run($currentRequest); } catch (\RuntimeException $ex) { $response = $response->withStatus(400); $response = $response->write($ex->getMessage()); } //send response to the client $response->send(); }