Creates cookie from raw header string.

@param string $cookie
@param bool   $decode

@return static
518335
public static function fromString($cookie, $decode = false)
    {
        $data = array(
            'expires' => 0,
            'path' => '/',
            'domain' => null,
            'secure' => false,
            'httponly' => true,
            'raw' => !$decode,
            'samesite' => null,
        );
        foreach (explode(';', $cookie) as $part) {
            if (false === strpos($part, '=')) {
                $key = trim($part);
                $value = true;
            } else {
                list($key, $value) = explode('=', trim($part), 2);
                $key = trim($key);
                $value = trim($value);
            }
            if (!isset($data['name'])) {
                $data['name'] = $decode ? urldecode($key) : $key;
                $data['value'] = true === $value ? null : ($decode ? urldecode($value) : $value);
                continue;
            }
            switch ($key = strtolower($key)) {
            case 'name':
            case 'value':
                break;
            case 'max-age':
                $data['expires'] = time() + (int) $value;
                break;
            default:
                $data[$key] = $value;
                break;
            }
        }

        return new static($data['name'], $data['value'], $data['expires'], $data['path'], $data['domain'], $data['secure'], $data['httponly'], $data['raw'], $data['samesite']);
    }
848071
public function applyCookies($cookies)
    {
        $headers = $this->headers();

        foreach ($cookies as $cookie) {
            $headers['Set-Cookie'][] = $cookie->toString();
        }
        return $this;
    }
26865
private function readFromCookie($cookie = true)
    {
        if ($cookie) {
            if (isset($_COOKIE[$this->_sessionName . "_SessionID"])) {
                $this->_session = $_COOKIE[$this->_sessionName . "_SessionID"];
                return true;
            }
        }

        return false;
    }
994774
function setcookies()
    {
        for ($x = 0; $x < count($this->headers); $x++) {
            if (preg_match('/^set-cookie:[\s]+([^=]+)=([^;]+)/i', $this->headers[$x], $match))
                $this->cookies[$match[1]] = urldecode($match[2]);
        }
        return $this;
    }
1021509
public static function parse(string $cookieString) : self
    {
        /* @var Cookie $cookie */

        foreach (explode('; ', $cookieString) as $i => $param) {
            $explode = explode('=', $param);

            if ($i == 0) {
                $cookie = new self($explode[0], $explode[1]);
                $cookie->setHttpOnly(false);
            } else {
                switch ($explode[0]) {
                    case 'expires':
                        $cookie->setExpire(new DateTime($explode[1]));
                        break;
                    case 'path':
                        $cookie->setPath($explode[1]);
                        break;
                    case 'domain':
                        $cookie->setDomain($explode[1]);
                        break;
                    case 'secure':
                        $cookie->setSecure(true);
                        break;
                    case 'httponly':
                        $cookie->setHttpOnly(true);
                        break;
                }
            }
        }

        return $cookie;
    }
824593
public function addCookie(Cookie $cookie)
    {
        if (!$this->hasCookie($cookie)) {
            $cookies = $this->getMatchingCookies($cookie);

            foreach ($cookies as $matchingCookie) {
                if ($cookie->getValue() !== $matchingCookie->getValue() || $cookie->getMaxAge() > $matchingCookie->getMaxAge()) {
                    $this->removeCookie($matchingCookie);

                    continue;
                }
            }

            if ($cookie->hasValue()) {
                $this->cookies->attach($cookie);
            }
        }
    }
1089638
public function set(\BearFramework\App\Response\Cookie $cookie): self
    {
        $this->data[$cookie->name] = $cookie;
        return $this;
    }
1225165
public function setCookie($cookies = [])
    {
        $this->cookies = $cookies;
        $this->debug->info(__FUNCTION__, 'setCookie: ', $this->cookies);

        return $this;
    }
982232
function(cookieHeader) {
            // Returns an object of form { $cookieKey: $cookieValue, $optionalCookieAttributeName: $""value, ... }
            var parsedCookieObject = CookieHandler.parse(cookieHeader);
            var cookie = {};

            // This gets the first key value pair into an object and just repeatedly returns thereafter
            utils.forEach(parsedCookieObject, function(cookieValue, cookieKey) {
                if(cookie.key) {
                    return;
                }
                cookie.key = cookieKey;
                cookie.value = cookieValue;
            });

            return cookie;
        }
31010
public function setCookie(ResponseCookie $cookie)
    {
        $this->cookies[$cookie->getName()] = $cookie;
        $this->setHeadersFromCookies();
    }
709269
public static function createFromString($Line)
    {
        // explode the string into lines.
        $lines = explode("\n", $Line);

        // extract the method and uri
        list( $method, $uri ) = explode(' ', array_shift($lines));

        $headers = [];

        foreach ($lines as $line) {
            // clean the line
            $line = trim($line);

            if (strpos($line, ': ') !== false) {
                list( $key, $value ) = explode(': ', $line);
                $headers[$key] = $value;
            }
        }
        
        $reqBody = new \Sofi\HTTP\RequestBody();
        $headers = \Sofi\HTTP\Headers::createFromArray($headers);
        $cookies = \Sofi\HTTP\Cookies::parseHeader($headers->get('cookie'));
        
        return new static($method, new \Sofi\HTTP\message\Uri($uri), $headers, $cookies, $_SERVER, $reqBody);
    }
347306
public function createCookie($cookie = true)
    {
        if ($cookie) {
            $cookietime = time() + (60 * 60 * 24 * 365);
            setcookie($this->_sessionName . "_SessionID", $this->_session->SessionID, $cookietime);
            setcookie($this->_sessionName . "_Timestamp", $this->_session->Timestamp, $cookietime);
        }

        return $this;
    }
853858
public function setCookie(Cookie $cookie) : parent
    {
        if ($this->headerSent($file, $line)) {
            throw new \LogicException(sprintf("Headers is already sent in '%s:%s'", $file, $line));
        }

        return parent::setCookie($cookie);
    }
851357
private static function ang($cookie)
    {
        $data     = new \stdClass();
        $features = json_decode($cookie);

        var_dump($cookie, $features);exit;

        return $data;
    }
1088616
public static function forge($name, $cookie = null)
    {
        $factory = new SessionFactory();
        $cookie  = $cookie ?: $_COOKIE;
        $session = $factory->newInstance($cookie);
        $self    = new self($session);
        $self->start();

        return $self->withStorage($name);
    }
475926
public function setCookie(Cookie $cookie) : Response
    {
        $this->cookies[] = $cookie;
        $this->addHeader('Set-Cookie', (string) $cookie);

        return $this;
    }
526596
public static function fromString(string $rawCookieStr): self {
        if ($rawCookieStr === "") {
            throw new CookieFormatException(
                $rawCookieStr,
                "Empty cookie string"
            );
        }

        $parts = explode(';', trim($rawCookieStr));
        $nvPair = array_shift($parts);

        if (strpos($nvPair, '=') === false) {
            throw new CookieFormatException(
                $rawCookieStr,
                "Missing '=' to separate name and value"
            );
        }

        list($name, $value) = explode('=', $nvPair, 2);

        if (\trim($name) === "") {
            throw new CookieFormatException($rawCookieStr, "Empty name");
        }

        $attrStruct = [
            'expires' => null,
            'path' => '',
            'domain' => "",
            'secure' => false,
            'httponly' => false,
            'max-age' => null
        ];

        foreach ($parts as $part) {
            $part = \trim($part);
            if (0 === \stripos($part, 'secure')) {
                $attrStruct['secure'] = true;
                continue;
            } elseif (0 === \stripos($part, 'httponly')) {
                $attrStruct['httponly'] = true;
                continue;
            }

            if (\strpos($part, '=') === false) {
                $attr = $part;
                $attrValue = "1";
            } else {
                list($attr, $attrValue) = explode('=', $part, 2);
            }

            $attr = strtolower($attr);
            if (array_key_exists($attr, $attrStruct)) {
                $attrStruct[$attr] = trim($attrValue, "\"\t\n\r\0\x0B\x20");
            }
        }

        $attrStruct['httponly'] = (bool) $attrStruct['httponly'];
        $attrStruct['secure'] = (bool) $attrStruct['secure'];

        if (isset($attrStruct['max-age']) && intval($attrStruct['max-age']) == $attrStruct['max-age']) {
            $attrStruct['expires'] = time() + $attrStruct['max-age'];
        } elseif ($attrStruct['expires']) {
            $attrStruct['expires'] = self::parseDate($attrStruct['expires']);
        }

        return new self(
            \trim($name),
            \trim($value),
            $attrStruct['expires'],
            $attrStruct['path'],
            $attrStruct['domain'],
            $attrStruct['secure'],
            $attrStruct['httponly']
        );
    }