コード例 #1
0
 /**
  * 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;
 }
コード例 #2
0
 /**
  * @test
  */
 public function getBaseUrl_in_cli_should_return_value_defaults_to_localhost()
 {
     $this->assertEquals('http://localhost/', $this->request->getBaseUrl());
 }