parseAcceptHeader() public method

This method will return the acceptable values with their quality scores and the corresponding parameters as specified in the given Accept header. The array keys of the return value are the acceptable values, while the array values consisting of the corresponding quality scores and parameters. The acceptable values with the highest quality scores will be returned first. For example, php $header = 'text/plain; q=0.5, application/json; version=1.0, application/xml; version=2.0;'; $accepts = $request->parseAcceptHeader($header); print_r($accepts); displays: [ 'application/json' => ['q' => 1, 'version' => '1.0'], 'application/xml' => ['q' => 1, 'version' => '2.0'], 'text/plain' => ['q' => 0.5], ]
public parseAcceptHeader ( string $header ) : array
$header string the header to be parsed
return array the acceptable values ordered by their quality score. The values with the highest scores will be returned first.
Example #1
0
 public function testParseAcceptHeader()
 {
     $request = new Request();
     $this->assertEquals([], $request->parseAcceptHeader(' '));
     $this->assertEquals(['audio/basic' => ['q' => 1], 'audio/*' => ['q' => 0.2]], $request->parseAcceptHeader('audio/*; q=0.2, audio/basic'));
     $this->assertEquals(['application/json' => ['q' => 1, 'version' => '1.0'], 'application/xml' => ['q' => 1, 'version' => '2.0', 'x'], 'text/x-c' => ['q' => 1], 'text/x-dvi' => ['q' => 0.8], 'text/plain' => ['q' => 0.5]], $request->parseAcceptHeader('text/plain; q=0.5,
         application/json; version=1.0,
         application/xml; version=2.0; x,
         text/x-dvi; q=0.8, text/x-c'));
 }