Request::getContentType PHP Method

getContentType() public static method

Gets the format associated with the request.
public static getContentType ( ) : string | null
return string | null The format (null if no content type is present)
        public static function getContentType()
        {
            //Method inherited from \Symfony\Component\HttpFoundation\Request
            return \Illuminate\Http\Request::getContentType();
        }

Usage Example

Example #1
0
 /**
  * @param Request $request
  * @return void
  * @throws RendererException
  */
 public function render(Request $request)
 {
     $response = $request->getResponse();
     $contentType = $request->getContentType();
     if ('json' === $contentType) {
         $renderer = new JsonRenderer();
     } else {
         if ('xml' === $contentType) {
             $renderer = new XmlRenderer();
         } else {
             if ('rss' === $contentType) {
                 $renderer = new RssRenderer();
             } else {
                 if ('html' === $contentType) {
                     $renderer = new HtmlRenderer();
                 } else {
                     $renderer = new HtmlRenderer();
                     $e = new RendererException('Content type missing or invalid', Response::NOT_FOUND);
                     $response->setException($e);
                 }
             }
         }
     }
     $body = $renderer->render($request, $response);
     $response->sendHeaders();
     exit($body);
 }
All Usage Examples Of Request::getContentType