Exemple #1
0
 public function __construct($value = '')
 {
     if (!HeaderValue::isValid($value)) {
         throw new Exception\InvalidArgumentException('Invalid Received value provided');
     }
     $this->value = $value;
 }
 /**
  * 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)
 {
     $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])) {
         throw new Exception\InvalidArgumentException('Invalid header name detected');
     }
     if (!HeaderValue::isValid($parts[1])) {
         throw new Exception\InvalidArgumentException('Invalid header value detected');
     }
     $parts[0] = $parts[0];
     $parts[1] = ltrim($parts[1]);
     return $parts;
 }
 /**
  * Add a parameter pair
  *
  * @param  string $name
  * @param  string $value
  * @return ContentType
  * @throws Exception\InvalidArgumentException for parameter names that do not follow RFC 2822
  * @throws Exception\InvalidArgumentException for parameter values that do not follow RFC 2822
  */
 public function addParameter($name, $value)
 {
     $name = strtolower($name);
     $value = (string) $value;
     if (!HeaderValue::isValid($name)) {
         throw new Exception\InvalidArgumentException('Invalid content-type parameter name detected');
     }
     if (!HeaderValue::isValid($value)) {
         throw new Exception\InvalidArgumentException('Invalid content-type parameter value detected');
     }
     $this->parameters[$name] = $value;
     return $this;
 }
 /**
  * Add a parameter pair
  *
  * @param  string $name
  * @param  string $value
  * @return ContentType
  * @throws Exception\InvalidArgumentException for parameter names that do not follow RFC 2822
  * @throws Exception\InvalidArgumentException for parameter values that do not follow RFC 2822
  */
 public function addParameter($name, $value)
 {
     $name = strtolower($name);
     $value = (string) $value;
     if (!HeaderValue::isValid($name)) {
         throw new Exception\InvalidArgumentException('Invalid content-type parameter name detected');
     }
     if (!HeaderWrap::canBeEncoded($value)) {
         throw new Exception\InvalidArgumentException('Parameter value must be composed of printable US-ASCII or UTF-8 characters.');
     }
     $this->parameters[$name] = $value;
     return $this;
 }