/** * Detects and returns the requested content type from supported formats. * @param Http\HttpRequestInterface $request * @return string|null Supported format in string, or null if no supported format found */ protected function detectSupportedContentType(HttpRequestInterface $request) { // TODO: maybe a better way to detect which format to use? $formats = $this->getOptions()->getSupportedFormats(); $contentType = null; // Look for content type in query string // e.g. /?format=application/json if (in_array($request->get('format'), $formats)) { $contentType = $request->get('format'); } // Suppress the query string from Accept header // e.g. Accept: text/html,application/json foreach ($request->getAcceptableContentTypes() as $format) { if (in_array($format, $formats)) { $contentType = $format; break; } } // if nothing found in query string and Accept header, // then use default format if */* present if ($contentType === null) { if (in_array('*/*', $request->getAcceptableContentTypes())) { $contentType = $this->getOptions()->getDefaultFormat(); } } return $contentType; }
/** * @test */ public function fetch_get_from_super_globals_should_return_the_same_value_as_super_globals() { $_GET['var1'] = 'var1'; $this->assertEquals($_GET['var1'], $this->request->get('var1')); }