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; }
public function getFieldValue($format = HeaderInterface::FORMAT_RAW) { $emails = []; $encoding = $this->getEncoding(); foreach ($this->getAddressList() as $address) { $email = $address->getEmail(); $name = $address->getName(); if (empty($name)) { $emails[] = $email; continue; } if (false !== strstr($name, ',')) { $name = sprintf('"%s"', $name); } if ($format === HeaderInterface::FORMAT_ENCODED && 'ASCII' !== $encoding) { $name = HeaderWrap::mimeEncodeValue($name, $encoding); } $emails[] = sprintf('%s <%s>', $name, $email); } // Ensure the values are valid before sending them. if ($format !== HeaderInterface::FORMAT_RAW) { foreach ($emails as $email) { HeaderValue::assertValid($email); } } return implode(',' . Headers::FOLDING, $emails); }
/** * 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; }
public function getFieldValue($format = HeaderInterface::FORMAT_RAW) { $emails = []; $encoding = $this->getEncoding(); foreach ($this->getAddressList() as $address) { $email = $address->getEmail(); $name = $address->getName(); if (!empty($name) && false !== strstr($name, ',')) { $name = sprintf('"%s"', $name); } if ($format === HeaderInterface::FORMAT_ENCODED && 'ASCII' !== $encoding) { if (!empty($name)) { $name = HeaderWrap::mimeEncodeValue($name, $encoding); } if (preg_match('/^(.+)@([^@]+)$/', $email, $matches)) { $localPart = $matches[1]; $hostname = $this->idnToAscii($matches[2]); $email = sprintf('%s@%s', $localPart, $hostname); } } if (empty($name)) { $emails[] = $email; } else { $emails[] = sprintf('%s <%s>', $name, $email); } } // Ensure the values are valid before sending them. if ($format !== HeaderInterface::FORMAT_RAW) { foreach ($emails as $email) { HeaderValue::assertValid($email); } } return implode(',' . Headers::FOLDING, $emails); }