/** * Factory create header from string. * * @param string $headerLine * * @return $this */ public static function fromString($headerLine) { if (null === ($headerName = static::getHeaderName())) { GenericHeader::assertEmptyHeaderFieldName($headerName); } list($fieldName, $fieldValue) = GenericHeader::splitHeaderLine($headerLine); return static::create($fieldName, $fieldValue); }
/** * Factory create CookieHeader from string representation. * * @param string $headerLine * * @return $this */ public static function fromString($headerLine) { list($fieldName, $fieldValue) = GenericHeader::splitHeaderLine($headerLine); GenericHeader::assertHeaderFieldName('Cookie', $fieldName); $cookies = array(); foreach (explode(';', $fieldValue) as $item) { $parts = explode('=', $item, 2); if (2 !== count($parts)) { throw new InvalidHeaderValueException(sprintf('Malformed Cookie header found on "%s".', $item)); } list($key, $value) = $parts; $cookies[$key] = urldecode($value); } return new static($cookies); }
/** * Factory create AllowHeader from string representation. * * @param string $headerLine * * @return $this */ public static function fromString($headerLine) { list($fieldName, $fieldValue) = GenericHeader::splitHeaderLine($headerLine); GenericHeader::assertHeaderFieldName('Allow', $fieldName); if ($fieldValue !== null) { $fieldValue = array_filter(explode(',', $fieldValue), 'trim'); $fieldValue = array_map('trim', $fieldValue); } return new static($fieldValue); }
/** * Factory create ContentLengthHeader from string representation. * * @param string $headerLine * * @return $this */ public static function fromString($headerLine) { list($fieldName, $fieldValue) = GenericHeader::splitHeaderLine($headerLine); GenericHeader::assertHeaderFieldName('Content-Length', $fieldName); return new static($fieldValue); }
/** * Factory create AgeHeader from string. * * @param string $headerLine * * @return $this */ public static function fromString($headerLine) { list($fieldName, $fieldValue) = GenericHeader::splitHeaderLine($headerLine); GenericHeader::assertHeaderFieldName('Age', $fieldName); return new static($fieldValue !== null ? $fieldValue : null); }