/**
  * Returns the "best match" of the given $priorities. Will return null in case
  * no match could be identified or a string containing the best matching Accept
  * header.
  *
  * @param MessageInterface $request
  * @param array $priorities A set of priorities.
  * @return null|string
  */
 public function getBestMatch(MessageInterface $request, array $priorities = array())
 {
     if (!$request->hasHeader('Accept')) {
         return null;
     }
     $header = $this->negotiator->getBest(implode(',', $request->getHeader('Accept')), $priorities);
     if ($header instanceof AcceptHeader) {
         return $header->getValue();
     }
     return null;
 }
Esempio n. 2
0
 /**
  * Asserts that the given header exists.
  *
  * If provided with a value, the value of the header will also be compared.
  *
  * @param MessageInterface $message
  * @param string $name
  * @param string|array|null $value
  */
 public function assertHasHeader(MessageInterface $message, $name, $value = null)
 {
     $this->assertTrue($message->hasHeader($name), "The message does not contain the header {$name}.");
     if (!is_null($value)) {
         $header = $message->getHeader($name);
         if (count($header) === 1 && is_string($value)) {
             $this->assertEquals($value, array_shift($header), "The message contains the header {$name}, but with the wrong value.");
         } else {
             $this->assertEquals($value, $header, "The message contains the header {$name}, but with the wrong value.");
         }
     }
 }
Esempio n. 3
0
 /**
  * {@inheritdoc}
  */
 public function getHeader($header)
 {
     return $this->message->getHeader($header);
 }
 public function testGetHeaderReturnsAnEmptyArrayWhenHeaderDoesNotExist()
 {
     $this->assertSame([], $this->message->getHeader('X-Foo-Bar'));
 }
Esempio n. 5
0
 public function get($header)
 {
     return $this->request->getHeader($header)[0];
 }