You are here

public function HeaderBag::set in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 vendor/symfony/http-foundation/HeaderBag.php \Symfony\Component\HttpFoundation\HeaderBag::set()

Sets a header by name.

Parameters

string $key The key:

string|array $values The value or an array of values:

bool $replace Whether to replace the actual value or not (true by default):

5 calls to HeaderBag::set()
HeaderBag::add in vendor/symfony/http-foundation/HeaderBag.php
Adds new headers the current HTTP headers set.
HeaderBag::addCacheControlDirective in vendor/symfony/http-foundation/HeaderBag.php
Adds a custom Cache-Control directive.
HeaderBag::removeCacheControlDirective in vendor/symfony/http-foundation/HeaderBag.php
Removes a Cache-Control directive.
HeaderBag::__construct in vendor/symfony/http-foundation/HeaderBag.php
Constructor.
ResponseHeaderBag::set in vendor/symfony/http-foundation/ResponseHeaderBag.php
Sets a header by name.
1 method overrides HeaderBag::set()
ResponseHeaderBag::set in vendor/symfony/http-foundation/ResponseHeaderBag.php
Sets a header by name.

File

vendor/symfony/http-foundation/HeaderBag.php, line 138

Class

HeaderBag
HeaderBag is a container for HTTP headers.

Namespace

Symfony\Component\HttpFoundation

Code

public function set($key, $values, $replace = true) {
  $key = strtr(strtolower($key), '_', '-');
  $values = array_values((array) $values);
  if (true === $replace || !isset($this->headers[$key])) {
    $this->headers[$key] = $values;
  }
  else {
    $this->headers[$key] = array_merge($this->headers[$key], $values);
  }
  if ('cache-control' === $key) {
    $this->cacheControl = $this
      ->parseCacheControl($values[0]);
  }
}