function HeaderBag::set
Sets a header by name.
Parameters
string|string[]|null $values The value or an array of values:
bool $replace Whether to replace the actual value or not (true by default):
6 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 - 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 130
Class
- HeaderBag
- HeaderBag is a container for HTTP headers.
Namespace
Symfony\Component\HttpFoundationCode
public function set(string $key, string|array|null $values, bool $replace = true) : void {
$key = strtr($key, self::UPPER, self::LOWER);
if (\is_array($values)) {
$values = array_values($values);
if (true === $replace || !isset($this->headers[$key])) {
$this->headers[$key] = $values;
}
else {
$this->headers[$key] = array_merge($this->headers[$key], $values);
}
}
else {
if (true === $replace || !isset($this->headers[$key])) {
$this->headers[$key] = [
$values,
];
}
else {
$this->headers[$key][] = $values;
}
}
if ('cache-control' === $key) {
$this->cacheControl = $this->parseCacheControl(implode(', ', $this->headers[$key]));
}
}