Esempio n. 1
0
 /**
  * Splits the header line in `name` and `value` parts.
  *
  * @param string $headerLine
  * @return string[] `name` in the first index and `value` in the second.
  * @throws Exception\InvalidArgumentException If header does not match with the format ``name:value``
  */
 public static function splitHeaderLine($headerLine, $throwExceptionOnInvalid = false)
 {
     $parts = explode(':', $headerLine, 2);
     if (count($parts) !== 2) {
         throw new Exception\InvalidArgumentException('Header must match with the format "name:value"');
     }
     if (!HeaderName::isValid($parts[0])) {
         if ($throwExceptionOnInvalid === true) {
             throw new Exception\InvalidArgumentException('Invalid header name detected');
         }
         $parts[0] = HeaderName::filter($parts[0]);
     }
     if (!HeaderValue::isValid($parts[1])) {
         if ($throwExceptionOnInvalid === true) {
             throw new Exception\InvalidArgumentException('Invalid header value detected');
         }
         $parts[1] = HeaderValue::filter($parts[1]);
     }
     $parts[0] = $parts[0];
     $parts[1] = ltrim($parts[1]);
     return $parts;
 }