public function testAttribute()
 {
     $item = new AcceptHeaderItem('value', array());
     $this->assertEquals(array(), $item->getAttributes());
     $this->assertFalse($item->hasAttribute('test'));
     $this->assertNull($item->getAttribute('test'));
     $this->assertEquals('default', $item->getAttribute('test', 'default'));
     $item->setAttribute('test', 'value');
     $this->assertEquals(array('test' => 'value'), $item->getAttributes());
     $this->assertTrue($item->hasAttribute('test'));
     $this->assertEquals('value', $item->getAttribute('test'));
     $this->assertEquals('value', $item->getAttribute('test', 'default'));
 }
Пример #2
0
 /**
  * Returns Accept-Language header from headers.
  *
  * @param Headers $headers
  *
  * @return string
  */
 protected function getAcceptLanguageHeader(Headers $headers)
 {
     $header = $headers->get('Accept-Language');
     if ($header === false) {
         return '';
     } elseif (!$header instanceof \ArrayIterator) {
         $header = new \ArrayIterator([$header]);
     }
     $items = [];
     $header->rewind();
     while ($header->valid()) {
         $items[] = AcceptHeaderItem::fromString($header->current()->getFieldValue());
         $header->next();
     }
     $acceptHeader = new AcceptHeader($items);
     return $acceptHeader->__toString();
 }