public function testAcceptLanguageBasics() { $this->request->setHeader('Accept-Language', 'da, en-gb;q=0.8, en;q=0.7'); $this->assertEquals('da', $this->negotiate->language(['da', 'en'])); $this->assertEquals('en-gb', $this->negotiate->language(['en-gb', 'en'])); $this->assertEquals('en', $this->negotiate->language(['en'])); }
/** * Provides a convenient way to work with the Negotiate class * for content negotiation. * * @param string $type * @param array $supported * @param bool $strictMatch * * @return mixed */ public function negotiate(string $type, array $supported, bool $strictMatch = false) { if (is_null($this->negotiate)) { $this->negotiate = Services::negotiator($this, true); } switch (strtolower($type)) { case 'media': return $this->negotiate->media($supported, $strictMatch); break; case 'charset': return $this->negotiate->charset($supported); break; case 'encoding': return $this->negotiate->encoding($supported); break; case 'language': return $this->negotiate->language($supported); break; } throw new \InvalidArgumentException($type . ' is not a valid negotiation type.'); }