Creates a cookie from the contents of a Set-Cookie header.

@param string $string

@return Cookie The cookie.

@throws \InvalidArgumentException If the cookie string is not valid.
486414
public static function parse(string $string) : Cookie
    {
        $parts = preg_split('/;\s*/', $string);
        $nameValue = explode('=', array_shift($parts), 2);

        if (count($nameValue) !== 2) {
            throw new \InvalidArgumentException('The cookie string is not valid.');
        }

        [$name, $value] = $nameValue;

        if ($name === '') {
            throw new \InvalidArgumentException('The cookie string is not valid.');
        }

        if ($value === '') {
            throw new \InvalidArgumentException('The cookie string is not valid.');
        }

        $value = rawurldecode($value);
        $expires = 0;
        $path = null;
        $domain = null;
        $secure = false;
        $httpOnly = false;

        foreach ($parts as $part) {
            switch (strtolower($part)) {
                case 'secure':
                    $secure = true;
                    break;

                case 'httponly':
                    $httpOnly = true;
                    break;

                default:
                    $elements = explode('=', $part, 2);
                    if (count($elements) === 2) {
                        switch (strtolower($elements[0])) {
                            case 'expires':
                                // Using @ to suppress the timezone warning, might not be the best thing to do.
                                if (is_int($time = @ strtotime($elements[1]))) {
                                    $expires = $time;
                                }
                                break;

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

                            case 'domain':
                                $domain = strtolower(ltrim($elements[1], '.'));
                        }
                    }
            }
        }

        return (new Cookie($name, $value))
            ->setExpires($expires)
            ->setPath($path)
            ->setDomain($domain)
            ->setSecure($secure)
            ->setHttpOnly($httpOnly);
    }
138633
public static function fromString(string $string): self
    {
        if (1 !== \preg_match('/^(?>\r\n|\n|\r)$/', $string)) {
            throw Exception\InvalidNewLineStringException::fromString($string);
        }

        return new self($string);
    }
472745
public function setName(string $name) : self
    {
        // from PHP source code
        if (preg_match("/[=,; \t\r\n\013\014]/", $name)) {
            throw new \InvalidArgumentException(sprintf('The cookie name "%s" contains invalid characters.', $name));
        }

        if (empty($name)) {
            throw new \InvalidArgumentException('The cookie name cannot be empty.');
        }

        $this->name = $name;

        return $this;
    }
487700
public static function createFromString(string $string): CurrencyPairContract
    {
        $matches = [];
        if (!preg_match('#^([A-Z0-9]{3,})\/([A-Z0-9]{3,})$#', $string, $matches)) {
            throw new \InvalidArgumentException('The currency pair must be in the form "EUR/USD".');
        }

        $parts = explode('/', $string);

        return new self($parts[0], $parts[1]);
    }
218191
public static function decode($string)
    {
        if (!is_string($string)) {
            throw new \InvalidArgumentException(sprintf(
                'Accept only string argument but got: "%s"',
                is_object($string) ? get_class($string) : gettype($string)
            ));
        }

        // PHP7 fix - empty string and null cause syntax error
        if (empty($string)) {
            return null;
        }

        $decoded = json_decode($string, true);
        if (JSON_ERROR_NONE !== json_last_error()) {
            throw new \InvalidArgumentException(sprintf(
                'The malformed json given. Error %s and message %s',
                json_last_error(),
                json_last_error_msg()
            ));
        }

        return $decoded;
    }
1235497
public function initString($string)
    {
        if (empty($this->cal)) {
            $lines = explode(PHP_EOL, $string);

            $this->initLines($lines);
        } else {
            trigger_error('ICal::initString: Calendar already initialised in constructor', E_USER_NOTICE);
        }

        return $this;
    }
750489
public static function fromString($timeString)
    {
        try {
            return static::fromDateTime(new DateTime($timeString));
        } catch (Exception $e) {
            throw new InvalidArgumentValue('$timeString', $timeString, __CLASS__, $e);
        }
    }
49728
private Cookie createCookie(String str) throws UnsupportedEncodingException {
    if (LOG.isDebugEnabled()) {
      LOG.debug("Cookie name = " + AUTH_COOKIE + " value = " + str);
    }
    Cookie cookie = new Cookie(AUTH_COOKIE, str);

    cookie.setMaxAge(cookieMaxAge);
    if (cookieDomain != null) {
      cookie.setDomain(cookieDomain);
    }
    if (cookiePath != null) {
      cookie.setPath(cookiePath);
    }
    cookie.setSecure(isCookieSecure);
    return cookie;
  }
1271726
public static function create($string): self
    {
        if ($string instanceof self) {
            return $string;
        }

        if (empty($string)) {
            throw new \InvalidArgumentException(
                    'Given string was null or empty, if you explicitly want to'
                    . ' create a Secret with value null use'
                    . ' Secret::forNull()'
            );
        }

        $self = new static();
        try {
            $encrypt = self::$encrypt;
            self::$store[$self->id] = ['payload' => $encrypt($string),
                                       'length'  => \iconv_strlen($string)
                                      ];
        } catch (\Throwable $t) {
            $t = null;
            // This intentionally catches *ALL* exceptions, in order not to fail
            // and produce a stacktrace containing arguments on the stack that
            // were supposed to be protected.
            unset(self::$store[$self->id]);
        }

        $string = str_repeat('*', strlen($string));
        $string = null;
        return $self;
    }
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);
    }
308528
public static function createFromString($uri)
    {
        if (!is_string($uri) && !method_exists($uri, '__toString')) {
            throw new InvalidArgumentException('Uri must be a string');
        }

        return self::createFromParse(parse_url($uri));
    }
1081117
public function setString($string)
    {
        if (null === $string) {
            throw new Exception('The string cannot be null.');
        }

        $this->hash = md5($string);

        $this->convertHashToArrayOfBoolean();

        return $this;
    }
564592
public function setCookie($name, $value)
	{
		if(!preg_match("'^[a-z_0-9\-\.]+$'i", $name))
		{
			throw new \InvalidArgumentException(sprintf('Invalid cookie name: "%s"', $name));
		}
			
		$this->cookies[$name] = $value;
		
		return $this;
	}
928300
public static function fromString($string)
	{
		if ( ! preg_match('/^(\d+):(\d+):(\d+)[:,\.]{1}(\d+)$/', $string, $matches))
		{
			throw new \InvalidArgumentException('Time string has an unsupported format.');
		}
		
		return new self($matches[1] * 3600 + $matches[2] + 60 + $matches[3] + ($matches[4] / 100));
	}
288327
protected function withString ($string, $name = 'query')
    {
        if (!is_string($string) && !method_exists($string, '__toString')) {
            throw new InvalidArgumentException('Uri fragment must be a string');
        }
        $string = ltrim((string) $string, '#');
        $clone = clone $this;
        $clone->$name = $this->filterQuery($string);

        return $clone;
    }
176502
public static function fromString($string)
    {
        $matches = array();
        $valid = \preg_match(
            '#^([-,\+])?([0-9]*[\.\/]?[0-9]*)([-,\+]){1}([0-9]*[\.\/]?[0-9]*)i$#',
            \trim($string),
            $matches
        );

        if ($valid !== 1) {
            throw new \InvalidArgumentException(
                'The string representation of the complex number is invalid.'
            );
        }

        $real = $matches[2];
        $imaginary = $matches[4];

        if ($matches[1] && $matches[1] == '-') {
            $real = '-' . $real;
        }
        if ($matches[3] && $matches[3] == '-') {
            $imaginary = '-' . $imaginary;
        }
        
        return self::create(self::convertType($real), self::convertType($imaginary));
    }
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;
    }