You are here

public function Cookie::__construct in Zircon Profile 8

Same name in this branch
  1. 8 vendor/symfony/http-foundation/Cookie.php \Symfony\Component\HttpFoundation\Cookie::__construct()
  2. 8 vendor/symfony/browser-kit/Cookie.php \Symfony\Component\BrowserKit\Cookie::__construct()
  3. 8 vendor/jcalderonzumba/gastonjs/src/Cookie.php \Zumba\GastonJS\Cookie::__construct()
  4. 8 core/modules/user/src/Authentication/Provider/Cookie.php \Drupal\user\Authentication\Provider\Cookie::__construct()
Same name and namespace in other branches
  1. 8.0 vendor/symfony/browser-kit/Cookie.php \Symfony\Component\BrowserKit\Cookie::__construct()

Sets a cookie.

Parameters

string $name The cookie name:

string $value The value of the cookie:

string $expires The time the cookie expires:

string $path The path on the server in which the cookie will be available on:

string $domain The domain that the cookie is available:

bool $secure Indicates that the cookie should only be transmitted over a secure HTTPS connection from the client:

bool $httponly The cookie httponly flag:

bool $encodedValue Whether the value is encoded or not:

File

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

Class

Cookie
Cookie represents an HTTP cookie.

Namespace

Symfony\Component\BrowserKit

Code

public function __construct($name, $value, $expires = null, $path = null, $domain = '', $secure = false, $httponly = true, $encodedValue = false) {
  if ($encodedValue) {
    $this->value = urldecode($value);
    $this->rawValue = $value;
  }
  else {
    $this->value = $value;
    $this->rawValue = urlencode($value);
  }
  $this->name = $name;
  $this->path = empty($path) ? '/' : $path;
  $this->domain = $domain;
  $this->secure = (bool) $secure;
  $this->httponly = (bool) $httponly;
  if (null !== $expires) {
    $timestampAsDateTime = \DateTime::createFromFormat('U', $expires);
    if (false === $timestampAsDateTime) {
      throw new \UnexpectedValueException(sprintf('The cookie expiration time "%s" is not valid.', $expires));
    }
    $this->expires = $timestampAsDateTime
      ->getTimestamp();
  }
}