@param string $string Valid Set-Cookie header line.

@return self

@throws \Icicle\Http\Exception\InvalidValueException Thrown if the string format is invalid.
18130
public static function fromHeader(string $string): Cookie
    {
        $parts = array_filter(array_map('trim', explode(';', $string)));

        if (empty($parts) || !strpos($parts[0], '=')) {
            throw new InvalidValueException('Invalid cookie format.');
        }

        list($name, $value) = array_map('trim', explode('=', array_shift($parts), 2));

        $expires = 0;
        $path = '';
        $domain = '';
        $secure = false;
        $httpOnly = false;

        foreach ($parts as $part) {
            $pieces = array_map('trim', explode('=', $part, 2));
            $key = strtolower($pieces[0]);

            if (1 === count($pieces)) {
                switch ($key) {
                    case 'secure':
                        $secure = true;
                        break;

                    case 'httponly':
                        $httpOnly = true;
                        break;
                }
            } else {
                switch ($key) {
                    case 'expires':
                        $time = \DateTime::createFromFormat('D, j M Y G:i:s T', $pieces[1]);
                        if (false === $time) {
                            break;
                        }

                        $time = $time->getTimestamp();
                        $expires = 0 === $expires ? $time : min($time, $expires);
                        break;

                    case 'max-age':
                        $time = trim($pieces[1]);
                        if (ctype_digit($time)) {
                            break;
                        }

                        $time = time() + (int) $time;
                        $expires = 0 === $expires ? $time : min($time, $expires);
                        break;

                    case 'path':
                        $path = $pieces[1];
                        break;

                    case 'domain':
                        $domain = $pieces[1];
                        break;
                }
            }
        }

        return new self($name, $value, $expires, $path, $domain, $secure, $httpOnly);
    }
1040653
public static function fromString($string)
    {
        $okay = strlen($string) < 256;
        Assertion::true($okay, 'StreamId cannot be greater than 255 chars.', 'StreamId');
        if (!preg_match(self::VALID_PATTERN, $string, $matches)) {
            throw new InvalidArgumentException(
                sprintf(
                    'StreamId [%s] is invalid.  It must match the pattern [%s].',
                    $string,
                    self::VALID_PATTERN
                )
            );
        }

        return new self(
            $matches[1],
            isset($matches[3]) ? $matches[3] : null,
            isset($matches[5]) ? $matches[5] : null
        );
    }
370117
public static function listFromCookieString(string $string) : array
    {
        $cookies = StringUtil::splitOnAttributeDelimiter($string);

        return array_map(function ($cookiePair) {
            return static::oneFromCookiePair($cookiePair);
        }, $cookies);
    }
34035
public static function fromString($string)
    {
        list($lat, $long) = explode(',', $string);
        return new self($lat, $long);
    }
108714
protected function _set($values, $prepend = false)
    {
        $header = $this->_classes['header'];
        $headers = is_string($values) ? explode("\n", $values) : $values;
        $headers = $headers ? $headers : [];

        foreach ($headers as $key => $value) {
            if (!is_numeric($key)) {
                if ($value instanceof $header) {
                    $value->name($key);
                } elseif (is_array($value)) {
                    $value = "{$key}: " . join(', ', $value);
                } else {
                    $value = "{$key}: {$value}";
                }
            }

            if (is_string($value)) {
                $value = trim($value);
            }

            if (!$value) {
                continue;
            }

            if ($value instanceof $header) {
                $parsed = $value;
            } elseif (!$parsed = $header::parse($value)) {
                throw new NetException("Invalid header: `'{$value}'`.");
            }

            $name = strtolower($parsed->name());
            if (!$name) {
                throw new Exception("Error, invalid header name, can't be empty.");
            }

            if ($name === 'set-cookie' && isset($this->_data[$name])) {
                $previsous = $this->_data[$name];
                $previsous[] = $parsed->value();
                $parsed = $previsous;
            }
            if ($prepend) {
                $this->_data = [$name => $parsed] + $this->_data;
            } else {
                $this->_data = array_merge($this->_data, [$name => $parsed]);
            }
        }
        return $this;
    }
311096
public function unserialize($string)
    {
        if (version_compare($this->productMetadata->getVersion(), '2.2.0', '>=')) {
            $objManager = \Magento\Framework\App\ObjectManager::getInstance();
            /** @var \Magento\Framework\Serialize\Serializer\Json $serializer */
            $serializer = $objManager->create('Magento\Framework\Serialize\Serializer\Json');
            return $serializer->unserialize($string);
        }

        $result = json_decode($string, true);
        if (json_last_error() !== JSON_ERROR_NONE) {
            throw new \InvalidArgumentException('Unable to unserialize value.');
        }
        return $result;
    }
804033
public function setReplacement($string): self
    {
        $this->_replacement = (string) $string;

        $this->_initNeverAllowedStr();

        return $this;
    }
1019659
public static function valueOf($char): self
    {
        if (\is_string($char) || $char instanceof self) {
            return new static((string) $char);
        }

        throw new InvalidArgumentException('Unsupported character type!');
    }
447794
public function append($string)
    {
        $this->value = Character::ensureTrailing($string, $this->value);

        return $this;
    }
74471
public static function validateTrimmed($string)
    {
        if (SetupHelper::trim($string) === $string) {
            return (string)$string;
        }

        throw new InvalidArgumentException(
            sprintf(
                'Provided string "%1$s" was not trimmed.',
                $string
            )
        );
    }
1237437
public static function validateURL($string)
    {
        if (filter_var($string, FILTER_VALIDATE_URL)) {
            return (string)$string;
        }

        throw new InvalidArgumentException(
            sprintf(
                'Provided string "%1$s" was not a valid URL.',
                $string
            )
        );
    }
865299
public static function validate($string)
    {
        try {
            if (is_numeric($string) && (int)$string == $string) {
                $date = new DateTime('@' . $string);
            } else {
                $date = self::parse($string);
            }
        } catch (Exception $ex) {
            return false;
        }

        // String is empty or not a valid date
        if (empty($string) || $date === false) {
            return false;

            // String is a valid date
        } else {
            return true;
        }
    }
797121
public function expire($expire = 0)
    {
        $var = null;
        $var = substr($expire, 0, 1);

        if (in_array($var, ['+', '-'])) {
            $this->expire = strtotime($expire);

            if ($this->expire === false) {
                throw new \InvalidCookieException(
                    'Cookie->setExpire was passed a string it could not parse - "'.$expire.'"'
                );
            }

            return $this;
        }

        $this->expire = 0;

        return $this;
    }
269134
public function prepend($string)
	{
		ArgumentValidator::validateScalar($string);
		$this->string = (string)$string . $this->string;
		return $this;
	}
1101056
public function set($string)
    {
        $this->clear();

        fwrite($this->stream, $string);
        rewind($this->stream);
    }
618379
static function fromString(string $string): self
    {
        $string = str_replace("/", "\\", $string);
        $string = preg_replace("#(\\\\){2,}#", "\\", $string);
        if (substr($string, -1, 1) == "\\") {
            $string = substr($string, 0, -1);
        }
        
        return new self($string);
    }
899292
public function setGetfield($string)
    {
        if (!is_null($this->getPostfields())) 
        { 
            throw new Exception('You can only choose get OR post fields.'); 
        }
        
        $search = array('#', ',', '+', ':');
        $replace = array('%23', '%2C', '%2B', '%3A');
        $string = str_replace($search, $replace, $string);  
        
        $this->getfield = $string;
        
        return $this;
    }