Request::getRequestFormat PHP Method

getRequestFormat() public static method

Here is the process to determine the format: * format defined by the user (with setRequestFormat()) * _format request attribute * $default
public static getRequestFormat ( string $default = 'html' ) : string
$default string The default format
return string The request format
        public static function getRequestFormat($default = 'html')
        {
            //Method inherited from \Symfony\Component\HttpFoundation\Request
            return \Illuminate\Http\Request::getRequestFormat($default);
        }

Usage Example

Example #1
0
 public function prepare(Request $request)
 {
     $headers = $this->headers;
     if ($this->isInformational() || in_array($this->statusCode, array(204, 304))) {
         $this->setContent(null);
     }
     // Content-type based on the Request
     if (!$headers->has('Content-Type')) {
         $format = $request->getRequestFormat();
         if (null !== $format && ($mimeType = $request->getMimeType($format))) {
             $headers->set('Content-Type', $mimeType);
         }
     }
     // Fix Content-Type
     $charset = $this->charset ?: 'UTF-8';
     if (!$headers->has('Content-Type')) {
         $headers->set('Content-Type', 'text/html; charset=' . $charset);
     } elseif (0 === strpos($headers->get('Content-Type'), 'text/') && false === strpos($headers->get('Content-Type'), 'charset')) {
         // add the charset
         $headers->set('Content-Type', $headers->get('Content-Type') . '; charset=' . $charset);
     }
     // Fix Content-Length
     if ($headers->has('Transfer-Encoding')) {
         $headers->remove('Content-Length');
     }
     if ('HEAD' === $request->getMethod()) {
         // cf. RFC2616 14.13
         $length = $headers->get('Content-Length');
         $this->setContent(null);
         if ($length) {
             $headers->set('Content-Length', $length);
         }
     }
     return $this;
 }
All Usage Examples Of Request::getRequestFormat