You are here

private function HttpFoundationFactory::createCookie in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/symfony/psr-http-message-bridge/Factory/HttpFoundationFactory.php \Symfony\Bridge\PsrHttpMessage\Factory\HttpFoundationFactory::createCookie()

Creates a Cookie instance from a cookie string.

Some snippets have been taken from the Guzzle project: https://github.com/guzzle/guzzle/blob/5.3/src/Cookie/SetCookie.php#L34

Parameters

string $cookie:

Return value

Cookie

Throws

\InvalidArgumentException

1 call to HttpFoundationFactory::createCookie()
HttpFoundationFactory::createResponse in vendor/symfony/psr-http-message-bridge/Factory/HttpFoundationFactory.php
Creates a Symfony Response instance from a PSR-7 one.

File

vendor/symfony/psr-http-message-bridge/Factory/HttpFoundationFactory.php, line 138

Class

HttpFoundationFactory
@author Kévin Dunglas <dunglas@gmail.com>

Namespace

Symfony\Bridge\PsrHttpMessage\Factory

Code

private function createCookie($cookie) {
  foreach (explode(';', $cookie) as $part) {
    $part = trim($part);
    $data = explode('=', $part, 2);
    $name = $data[0];
    $value = isset($data[1]) ? trim($data[1], " \n\r\t\0\v\"") : null;
    if (!isset($cookieName)) {
      $cookieName = $name;
      $cookieValue = $value;
      continue;
    }
    if ('expires' === strtolower($name) && null !== $value) {
      $cookieExpire = new \DateTime($value);
      continue;
    }
    if ('path' === strtolower($name) && null !== $value) {
      $cookiePath = $value;
      continue;
    }
    if ('domain' === strtolower($name) && null !== $value) {
      $cookieDomain = $value;
      continue;
    }
    if ('secure' === strtolower($name)) {
      $cookieSecure = true;
      continue;
    }
    if ('httponly' === strtolower($name)) {
      $cookieHttpOnly = true;
      continue;
    }
  }
  if (!isset($cookieName)) {
    throw new \InvalidArgumentException('The value of the Set-Cookie header is malformed.');
  }
  return new Cookie($cookieName, $cookieValue, isset($cookieExpire) ? $cookieExpire : 0, isset($cookiePath) ? $cookiePath : '/', isset($cookieDomain) ? $cookieDomain : null, isset($cookieSecure), isset($cookieHttpOnly));
}