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

Breadcrumb

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

function Cookie::fromString

Same name in this branch
  1. 11.1.x vendor/symfony/browser-kit/Cookie.php \Symfony\Component\BrowserKit\Cookie::fromString()

Creates cookie from raw header string.

2 calls to Cookie::fromString()
HttpFoundationFactory::createResponse in vendor/symfony/psr-http-message-bridge/Factory/HttpFoundationFactory.php
Creates a Symfony Response instance from a PSR-7 one.
ResponseHeaderBag::set in vendor/symfony/http-foundation/ResponseHeaderBag.php
Sets a header by name.

File

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

Class

Cookie
Represents a cookie.

Namespace

Symfony\Component\HttpFoundation

Code

public static function fromString(string $cookie, bool $decode = false) : static {
    $data = [
        'expires' => 0,
        'path' => '/',
        'domain' => null,
        'secure' => false,
        'httponly' => false,
        'raw' => !$decode,
        'samesite' => null,
        'partitioned' => false,
    ];
    $parts = HeaderUtils::split($cookie, ';=');
    $part = array_shift($parts);
    $name = $decode ? urldecode($part[0]) : $part[0];
    $value = isset($part[1]) ? $decode ? urldecode($part[1]) : $part[1] : null;
    $data = HeaderUtils::combine($parts) + $data;
    $data['expires'] = self::expiresTimestamp($data['expires']);
    if (isset($data['max-age']) && ($data['max-age'] > 0 || $data['expires'] > time())) {
        $data['expires'] = time() + (int) $data['max-age'];
    }
    return new static($name, $value, $data['expires'], $data['path'], $data['domain'], $data['secure'], $data['httponly'], $data['raw'], $data['samesite'], $data['partitioned']);
}

API Navigation

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