replace() public method

Replaces the current HTTP headers by a new set.
public replace ( array $headers = [] )
$headers array An array of HTTP headers
Example #1
0
 /**
  * @covers Symfony\Component\HttpFoundation\HeaderBag::replace
  */
 public function testReplace()
 {
     $bag = new HeaderBag(array('foo' => 'bar'));
     $bag->replace(array('NOPE' => 'BAR'));
     $this->assertEquals(array('nope' => array('BAR')), $bag->all(), '->replace() replaces the input with the argument');
     $this->assertFalse($bag->has('foo'), '->replace() overrides previously set the input');
 }
 public function testCacheControlDirectiveOverrideWithReplace()
 {
     $bag = new HeaderBag(array('cache-control' => 'private, max-age=100'));
     $bag->replace(array('cache-control' => 'public, max-age=10'));
     $this->assertTrue($bag->hasCacheControlDirective('public'));
     $this->assertTrue($bag->getCacheControlDirective('public'));
     $this->assertTrue($bag->hasCacheControlDirective('max-age'));
     $this->assertEquals(10, $bag->getCacheControlDirective('max-age'));
 }
Example #3
0
 /**
  * {@inheritdoc}
  *
  * @api
  */
 public function replace(array $headers = array())
 {
     $this->headerNames = array();
     parent::replace($headers);
 }