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

Breadcrumb

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

function Cookie::__toString

Same name in this branch
  1. 11.1.x vendor/symfony/http-foundation/Cookie.php \Symfony\Component\HttpFoundation\Cookie::__toString()

Returns the HTTP representation of the Cookie.

File

vendor/symfony/browser-kit/Cookie.php, line 89

Class

Cookie
Cookie represents an HTTP cookie.

Namespace

Symfony\Component\BrowserKit

Code

public function __toString() : string {
    $cookie = \sprintf('%s=%s', $this->name, $this->rawValue);
    if (null !== $this->expires) {
        $dateTime = \DateTimeImmutable::createFromFormat('U', $this->expires, new \DateTimeZone('GMT'));
        $cookie .= '; expires=' . str_replace('+0000', '', $dateTime->format(self::DATE_FORMATS[0]));
    }
    if ('' !== $this->domain) {
        $cookie .= '; domain=' . $this->domain;
    }
    if ($this->path) {
        $cookie .= '; path=' . $this->path;
    }
    if ($this->secure) {
        $cookie .= '; secure';
    }
    if ($this->httponly) {
        $cookie .= '; httponly';
    }
    if (null !== $this->samesite) {
        $cookie .= '; samesite=' . $this->samesite;
    }
    return $cookie;
}

API Navigation

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