Symfony\Component\HttpFoundation\Request::setFormat PHP Method

setFormat() public method

Associates a format with mime types.
public setFormat ( string $format, string | array $mimeTypes )
$format string The format
$mimeTypes string | array The associated mime types (the preferred one must be the first as it will be used as the content type)
    public function setFormat($format, $mimeTypes)
    {
        if (null === static::$formats) {
            static::initializeFormats();
        }

        static::$formats[$format] = is_array($mimeTypes) ? $mimeTypes : array($mimeTypes);
    }

Usage Example

 /**
  * Tests the getContentType() method when a priority format is found.
  *
  * @dataProvider priorityFormatProvider
  * @covers ::getContentType
  */
 public function testAPriorityFormatIsFound($priority, $format)
 {
     $request = new Request();
     $request->setFormat($format['format'], $format['mime_type']);
     $request->headers->set('Accept', sprintf('%s,application/json', $format['mime_type']));
     $this->assertSame($priority, $this->contentNegotiation->getContentType($request));
 }
All Usage Examples Of Symfony\Component\HttpFoundation\Request::setFormat