/**
  * Factory create UserAgentHeader from string representation.
  *
  * @param string $headerLine
  *
  * @return $this
  */
 public static function fromString($headerLine)
 {
     list($fieldName, $fieldValue) = GenericHeader::splitHeaderLine($headerLine);
     $fieldName = str_replace(array(' ', '_', '.'), '-', $fieldName);
     GenericHeader::assertHeaderFieldName('User-Agent', $fieldName);
     return new static($fieldValue);
 }
Example #2
0
 /**
  * @param string $headerLine
  * @return HeaderInterface|static
  * @throws InvalidArgumentException
  */
 public static function fromString($headerLine)
 {
     list($name, $value) = GenericHeader::splitHeaderLine($headerLine);
     // check to ensure proper header type for this factory
     if (strtolower($name) !== 'dkimsignature') {
         throw new InvalidArgumentException('Invalid header line for DKIM-Signature string');
     }
     $header = new static($value);
     return $header;
 }
Example #3
0
 public static function fromString($headerLine)
 {
     $decodedLine = iconv_mime_decode($headerLine, ICONV_MIME_DECODE_CONTINUE_ON_ERROR, 'UTF-8');
     list($name, $value) = GenericHeader::splitHeaderLine($decodedLine);
     $header = new static($name, $value);
     if ($decodedLine != $headerLine) {
         $header->setEncoding('UTF-8');
     }
     return $header;
 }
Example #4
0
 /**
  * Create Age header from string
  *
  * @param string $headerLine
  * @return Age
  * @throws Exception\InvalidArgumentException
  */
 public static function fromString($headerLine)
 {
     $header = new static();
     list($name, $value) = GenericHeader::splitHeaderLine($headerLine);
     // check to ensure proper header type for this factory
     if (strtolower($name) !== 'age') {
         throw new Exception\InvalidArgumentException('Invalid header line for Age string: "' . $name . '"');
     }
     $header->deltaSeconds = (int) $value;
     return $header;
 }
Example #5
0
 public static function fromString($headerLine)
 {
     $header = new static();
     list($name, $value) = GenericHeader::splitHeaderLine($headerLine);
     // check to ensure proper header type for this factory
     if (strtolower($name) !== 'accept-ranges') {
         throw new Exception\InvalidArgumentException('Invalid header line for Accept-Ranges string');
     }
     $header->rangeUnit = trim($value);
     return $header;
 }
Example #6
0
 public static function fromString($headerLine)
 {
     list($name, $value) = GenericHeader::splitHeaderLine($headerLine);
     // check to ensure proper header type for this factory
     if (str_replace(array('_', ' ', '.'), '-', strtolower($name)) !== 'user-agent') {
         throw new Exception\InvalidArgumentException('Invalid header line for User-Agent string: "' . $name . '"');
     }
     // @todo implementation details
     $header = new static($value);
     return $header;
 }
Example #7
0
 public static function fromString($headerLine)
 {
     list($name, $value) = GenericHeader::splitHeaderLine($headerLine);
     // check to ensure proper header type for this factory
     if (strtolower($name) !== 'message-id') {
         throw new Exception\InvalidArgumentException('Invalid header line for Message-ID string');
     }
     $header = new static();
     $header->setId($value);
     return $header;
 }
Example #8
0
 /**
  * @param $headerLine
  * @return Connection
  * @throws Exception\InvalidArgumentException
  */
 public static function fromString($headerLine)
 {
     $header = new static();
     list($name, $value) = GenericHeader::splitHeaderLine($headerLine);
     // check to ensure proper header type for this factory
     if (strtolower($name) !== 'connection') {
         throw new Exception\InvalidArgumentException('Invalid header line for Connection string: "' . $name . '"');
     }
     $header->setValue(trim($value));
     return $header;
 }
Example #9
0
 public static function fromString($headerLine)
 {
     list($name, $value) = GenericHeader::splitHeaderLine($headerLine);
     $value = HeaderWrap::mimeDecodeValue($value);
     // check to ensure proper header type for this factory
     if (strtolower($name) !== 'date') {
         throw new Exception\InvalidArgumentException('Invalid header line for Date string');
     }
     $header = new static($value);
     return $header;
 }
 public static function fromString($headerLine)
 {
     list($name, $value) = GenericHeader::splitHeaderLine($headerLine);
     // check to ensure proper header type for this factory
     if (strtolower($name) !== 'content-language') {
         throw new Exception\InvalidArgumentException('Invalid header line for Content-Language string: "' . $name . '"');
     }
     // @todo implementation details
     $header = new static($value);
     return $header;
 }
 public static function fromString($headerLine)
 {
     list($name, $value) = GenericHeader::splitHeaderLine($headerLine);
     // check to ensure proper header type for this factory
     if (strtolower($name) !== 'content-transfer-encoding') {
         throw new Exception\InvalidArgumentException(sprintf('Invalid header line for Content-Transfer-Encoding string: "%s"', $name));
     }
     // @todo implementation details
     $header = new static(strtolower($value));
     return $header;
 }
Example #12
0
 public static function fromString($headerLine)
 {
     list($name, $value) = GenericHeader::splitHeaderLine($headerLine);
     // check to ensure proper header type for this factory
     if (strtolower($name) !== 'proxy-authenticate') {
         throw new Exception\InvalidArgumentException(sprintf('Invalid header line for Proxy-Authenticate string: "%s"', $name));
     }
     // @todo implementation details
     $header = new static($value);
     return $header;
 }
Example #13
0
 /**
  * Creates a CacheControl object from a headerLine
  *
  * @param string $headerLine
  * @throws Exception\InvalidArgumentException
  * @return CacheControl
  */
 public static function fromString($headerLine)
 {
     $header = new static();
     list($name, $value) = GenericHeader::splitHeaderLine($headerLine);
     // check to ensure proper header type for this factory
     if (strtolower($name) !== 'cache-control') {
         throw new Exception\InvalidArgumentException('Invalid header line for Cache-Control string: "' . $name . '"');
     }
     // @todo implementation details
     $header->directives = static::parseValue($value);
     return $header;
 }
Example #14
0
 public static function fromString($headerLine)
 {
     $header = new static();
     list($name, $value) = GenericHeader::splitHeaderLine($headerLine);
     // check to ensure proper header type for this factory
     if (strtolower($name) !== 'transfer-encoding') {
         throw new Exception\InvalidArgumentException('Invalid header line for Transfer-Encoding string: "' . $name . '"');
     }
     // @todo implementation details
     $header->value = $value;
     return $header;
 }
Example #15
0
 public static function fromString($headerLine)
 {
     $headerLine = iconv_mime_decode($headerLine, ICONV_MIME_DECODE_CONTINUE_ON_ERROR, 'UTF-8');
     list($name, $value) = GenericHeader::splitHeaderLine($headerLine);
     // check to ensure proper header type for this factory
     if (strtolower($name) !== 'content-transfer-encoding') {
         throw new Exception\InvalidArgumentException('Invalid header line for Content-Transfer-Encoding string');
     }
     $header = new static();
     $header->setTransferEncoding($value);
     return $header;
 }
 public static function fromString($headerLine)
 {
     list($fieldName, $fieldValue) = GenericHeader::splitHeaderLine($headerLine);
     $fieldValue = HeaderWrap::mimeDecodeValue($fieldValue);
     if (strpos($fieldValue, ',')) {
         $headers = [];
         foreach (explode(',', $fieldValue) as $multiValue) {
             $headers[] = new static($fieldName, $multiValue);
         }
         return $headers;
     }
     return new static($fieldName, $fieldValue);
 }
Example #17
0
 public static function fromString($headerLine)
 {
     list($name, $value) = GenericHeader::splitHeaderLine($headerLine);
     // check to ensure proper header type for this factory
     if (strtolower($name) !== 'mime-version') {
         throw new Exception\InvalidArgumentException('Invalid header line for MIME-Version string');
     }
     // Check for version, and set if found
     $header = new static();
     if (preg_match('/^(?P<version>\\d+\\.\\d+)$/', $value, $matches)) {
         $header->setVersion($matches['version']);
     }
     return $header;
 }
Example #18
0
 public static function fromString($headerLine)
 {
     list($fieldName, $fieldValue) = GenericHeader::splitHeaderLine($headerLine);
     if (strpos($fieldValue, ',')) {
         $headers = array();
         foreach (explode(',', $fieldValue) as $multiValue) {
             $headers[] = new static($fieldName, $multiValue);
         }
         return $headers;
     } else {
         $header = new static($fieldName, $fieldValue);
         return $header;
     }
 }
 /**
  * Creates a CacheControl object from a headerLine
  *
  * @param string $headerLine
  * @throws Exception\InvalidArgumentException
  * @return CacheControl
  */
 public static function fromString($headerLine)
 {
     list($name, $value) = GenericHeader::splitHeaderLine($headerLine);
     // check to ensure proper header type for this factory
     if (strtolower($name) !== 'cache-control') {
         throw new Exception\InvalidArgumentException(sprintf('Invalid header line for Cache-Control string: ""', $name));
     }
     $directives = static::parseValue($value);
     // @todo implementation details
     $header = new static();
     foreach ($directives as $key => $value) {
         $header->addDirective($key, $value);
     }
     return $header;
 }
Example #20
0
 /**
  * Create Retry-After header from string
  *
  * @param  string $headerLine
  * @return RetryAfter
  * @throws Exception\InvalidArgumentException
  */
 public static function fromString($headerLine)
 {
     $dateHeader = new static();
     list($name, $date) = GenericHeader::splitHeaderLine($headerLine);
     // check to ensure proper header type for this factory
     if (strtolower($name) !== strtolower($dateHeader->getFieldName())) {
         throw new Exception\InvalidArgumentException('Invalid header line for "' . $dateHeader->getFieldName() . '" header string');
     }
     if (is_numeric($date)) {
         $dateHeader->setDeltaSeconds($date);
     } else {
         $dateHeader->setDate($date);
     }
     return $dateHeader;
 }
Example #21
0
 public static function fromString($headerLine)
 {
     $decodedLine = iconv_mime_decode($headerLine, ICONV_MIME_DECODE_CONTINUE_ON_ERROR, 'UTF-8');
     list($fieldName, $fieldValue) = GenericHeader::splitHeaderLine($decodedLine);
     if (strpos($fieldValue, ',')) {
         $headers = array();
         $encoding = $decodedLine != $headerLine ? 'UTF-8' : 'ASCII';
         foreach (explode(',', $fieldValue) as $multiValue) {
             $header = new static($fieldName, $multiValue);
             $headers[] = $header->setEncoding($encoding);
         }
         return $headers;
     } else {
         $header = new static($fieldName, $fieldValue);
         if ($decodedLine != $headerLine) {
             $header->setEncoding('UTF-8');
         }
         return $header;
     }
 }
 /**
  * Create Content Security Policy header from a given header line
  *
  * @param string $headerLine The header line to parse.
  * @return self
  * @throws Exception\InvalidArgumentException If the name field in the given header line does not match.
  */
 public static function fromString($headerLine)
 {
     $header = new static();
     $headerName = $header->getFieldName();
     list($name, $value) = GenericHeader::splitHeaderLine($headerLine);
     // Ensure the proper header name
     if (strcasecmp($name, $headerName) != 0) {
         throw new Exception\InvalidArgumentException(sprintf('Invalid header line for %s string: "%s"', $headerName, $name));
     }
     // As per http://www.w3.org/TR/CSP/#parsing
     $tokens = explode(';', $value);
     foreach ($tokens as $token) {
         $token = trim($token);
         if ($token) {
             list($directiveName, $directiveValue) = explode(' ', $token, 2);
             if (!isset($header->directives[$directiveName])) {
                 $header->directives[$directiveName] = $directiveValue;
             }
         }
     }
     return $header;
 }
Example #23
0
 /**
  * Factory to generate a header object from a string
  *
  * @static
  * @param string $headerLine
  * @return GenericHeader
  */
 public static function fromString($headerLine)
 {
     list($fieldName, $fieldValue) = GenericHeader::splitHeaderLine($headerLine);
     $header = new static($fieldName, $fieldValue);
     return $header;
 }
 /**
  * Set header value.
  *
  * @param string $value
  *
  * @return $this
  */
 public function set($value)
 {
     GenericHeader::assertHeaderValue($value);
     $this->value = $value;
     return $this;
 }