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

Breadcrumb

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

function Cookie::withSameSite

Creates a cookie copy with SameSite attribute.

Parameters

self::SAMESITE_*|''|null $sameSite:

File

vendor/symfony/http-foundation/Cookie.php, line 221

Class

Cookie
Represents a cookie.

Namespace

Symfony\Component\HttpFoundation

Code

public function withSameSite(?string $sameSite) : static {
    if ('' === $sameSite) {
        $sameSite = null;
    }
    elseif (null !== $sameSite) {
        $sameSite = strtolower($sameSite);
    }
    if (!\in_array($sameSite, [
        self::SAMESITE_LAX,
        self::SAMESITE_STRICT,
        self::SAMESITE_NONE,
        null,
    ], true)) {
        throw new \InvalidArgumentException('The "sameSite" parameter value is not valid.');
    }
    $cookie = clone $this;
    $cookie->sameSite = $sameSite;
    return $cookie;
}

API Navigation

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