/** * @group single */ public function testAcceptCharsetMatchesBasics() { $this->request->setHeader('Accept-Charset', 'iso-8859-5, unicode-1-1;q=0.8'); $this->assertEquals('iso-8859-5', $this->negotiate->charset(['iso-8859-5', 'unicode-1-1'])); $this->assertEquals('unicode-1-1', $this->negotiate->charset(['utf-8', 'unicode-1-1'])); // No match will default to utf-8 $this->assertEquals('utf-8', $this->negotiate->charset(['iso-8859', 'unicode-1-2'])); }
/** * 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.'); }