composer package updates
[openemr.git] / vendor / zendframework / zend-mail / src / Header / HeaderName.php
blobb802d8a73ea3fb24945b9bf6b6e7d40e6ba17e8f
1 <?php
2 /**
3 * @see https://github.com/zendframework/zend-mail for the canonical source repository
4 * @copyright Copyright (c) 2005-2018 Zend Technologies USA Inc. (https://www.zend.com)
5 * @license https://github.com/zendframework/zend-mail/blob/master/LICENSE.md New BSD License
6 */
8 namespace Zend\Mail\Header;
10 final class HeaderName
12 /**
13 * No public constructor.
15 private function __construct()
19 /**
20 * Filter the header name according to RFC 2822
22 * @see http://www.rfc-base.org/txt/rfc-2822.txt (section 2.2)
23 * @param string $name
24 * @return string
26 public static function filter($name)
28 $result = '';
29 $tot = strlen($name);
30 for ($i = 0; $i < $tot; $i += 1) {
31 $ord = ord($name[$i]);
32 if ($ord > 32 && $ord < 127 && $ord !== 58) {
33 $result .= $name[$i];
36 return $result;
39 /**
40 * Determine if the header name contains any invalid characters.
42 * @param string $name
43 * @return bool
45 public static function isValid($name)
47 $tot = strlen($name);
48 for ($i = 0; $i < $tot; $i += 1) {
49 $ord = ord($name[$i]);
50 if ($ord < 33 || $ord > 126 || $ord === 58) {
51 return false;
54 return true;
57 /**
58 * Assert that the header name is valid.
60 * Raises an exception if invalid.
62 * @param string $name
63 * @throws Exception\RuntimeException
64 * @return void
66 public static function assertValid($name)
68 if (! self::isValid($name)) {
69 throw new Exception\RuntimeException('Invalid header name detected');