Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. HeaderBag.php

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.

... See full list

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\HttpFoundation

Code

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]));
    }
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal