コード例 #1
0
 public function testAcceptLanguageToStringReturnsHeaderFormattedString()
 {
     $this->markTestIncomplete('AcceptLanguage needs to be completed');
     $acceptLanguageHeader = new AcceptLanguage();
     // @todo set some values, then test output
     $this->assertEmpty('Accept-Language: xxx', $acceptLanguageHeader->toString());
 }
コード例 #2
0
ファイル: Locale.php プロジェクト: gridguyz/zork
 /**
  * Parse header
  *
  * @param   null|\Zend\Http\Header\AcceptLanguage   $header
  * @return  array
  */
 public function parseHeader($header)
 {
     $locales = array();
     $controller = $this->getController();
     if ($controller instanceof ServiceLocatorAwareInterface) {
         $availables = $controller->getServiceLocator()->get('Locale')->getAvailableLocales();
     } else {
         $availables = array(IntlLocale::getDefault());
     }
     if ($header instanceof AcceptLanguage) {
         foreach ($header->getPrioritized() as $part) {
             if ($part instanceof LanguageFieldValuePart) {
                 $locale = IntlLocale::parseLocale($part->getLanguage());
                 $key = $locale['language'];
                 if (isset($locale['region'])) {
                     $key .= '_' . $locale['region'];
                 }
                 if ($availables) {
                     $key = IntlLocale::lookup($availables, $key, false, '');
                 }
                 if ($key) {
                     $locales[$key] = max($part->getPriority(), empty($locales[$key]) ? 0 : $locales[$key]);
                 }
             }
         }
     }
     return $locales;
 }
コード例 #3
0
 public function testWildcharLanguage()
 {
     $acceptHeader = new AcceptLanguage();
     $acceptHeader->addLanguage('da', 0.8)->addLanguage('*', 0.4);
     $this->assertTrue($acceptHeader->hasLanguage('da'));
     $this->assertTrue($acceptHeader->hasLanguage('en'));
     $this->assertEquals('Accept-Language: da;q=0.8,*;q=0.4', $acceptHeader->toString());
 }
コード例 #4
0
 public function testWildcards()
 {
     $accept = AcceptLanguage::fromString('*, en-*, en-us');
     $res = $accept->getPrioritized();
     $this->assertEquals('en-us', $res[0]->getLanguage());
     $this->assertEquals('en', $res[0]->getPrimaryTag());
     $this->assertEquals('us', $res[0]->getSubTag());
     $this->assertEquals('en-*', $res[1]->getLanguage());
     $this->assertEquals('en', $res[1]->getPrimaryTag());
     $this->assertTrue($accept->hasLanguage('nl'));
 }
コード例 #5
0
 public function testSelectsLanguageViaLocaleLookup()
 {
     $strategy = $this->strategy;
     $event = $this->event;
     $header = new AcceptLanguage();
     $header->addLanguage('de-DE', 1);
     $header->addLanguage('en-US', 0.8);
     $header->addLanguage('en', 0.6);
     $event->getRequest()->getHeaders()->addHeader($header);
     $event->setSupported(array('en', 'de'));
     $locale = $strategy->detect($event);
     $this->assertEquals('de', $locale);
 }
コード例 #6
0
 public function testSelectsOnlyLanguageFromSupportedList()
 {
     $strategy = $this->strategy;
     $event = $this->event;
     $header = new AcceptLanguage();
     $header->addLanguage('foo', 1);
     $header->addLanguage('bar', 0.8);
     $header->addLanguage('baz', 0.6);
     $event->getRequest()->getHeaders()->addHeader($header);
     $event->setSupported(array('bar'));
     $locale = $strategy->detect($event);
     $this->assertEquals('bar', $locale);
 }