Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
5 / 5 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| Encoding | |
100.00% |
5 / 5 |
|
100.00% |
2 / 2 |
4 | |
100.00% |
1 / 1 |
| toHeaderValue | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
3 | |||
| fromHeaderValue | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | declare(strict_types=1); |
| 3 | /** |
| 4 | * Pop PHP Framework (https://www.popphp.org/) |
| 5 | * |
| 6 | * @link https://github.com/popphp/popphp-framework |
| 7 | * @author Nick Sagona, III <dev@noladev.com> |
| 8 | * @copyright Copyright (c) 2009-2027 NOLA Interactive, LLC. |
| 9 | * @license https://www.popphp.org/license New BSD License |
| 10 | */ |
| 11 | |
| 12 | /** |
| 13 | * @namespace |
| 14 | */ |
| 15 | namespace Pop\Mime\Part\Body; |
| 16 | |
| 17 | /** |
| 18 | * MIME part body encoding enum |
| 19 | * |
| 20 | * @category Pop |
| 21 | * @package Pop\Mime |
| 22 | * @author Nick Sagona, III <dev@noladev.com> |
| 23 | * @copyright Copyright (c) 2009-2027 NOLA Interactive, LLC. |
| 24 | * @license https://www.popphp.org/license New BSD License |
| 25 | * @version 3.0.0 |
| 26 | */ |
| 27 | enum Encoding: string |
| 28 | { |
| 29 | case BASE64 = 'base64'; |
| 30 | case QUOTED_PRINTABLE = 'quoted-printable'; |
| 31 | case URL = 'URL'; |
| 32 | case RAW_URL = 'RAW_URL'; |
| 33 | case BINARY = 'binary'; |
| 34 | case _7BIT = '7bit'; |
| 35 | case _8BIT = '8bit'; |
| 36 | |
| 37 | /** |
| 38 | * Map to the Content-Transfer-Encoding wire token, or null for encodings |
| 39 | * that aren't a real MIME transfer encoding (URL/RAW_URL are used for |
| 40 | * HTTP form-field encoding, not message wire format). |
| 41 | * |
| 42 | * @return ?string |
| 43 | */ |
| 44 | public function toHeaderValue(): ?string |
| 45 | { |
| 46 | return match ($this) { |
| 47 | self::URL, self::RAW_URL => null, |
| 48 | default => $this->value, |
| 49 | }; |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * Map a Content-Transfer-Encoding header value (case-insensitive) back |
| 54 | * to its Encoding case, or null if unrecognized. |
| 55 | * |
| 56 | * @param string $value |
| 57 | * @return ?self |
| 58 | */ |
| 59 | public static function fromHeaderValue(string $value): ?self |
| 60 | { |
| 61 | return self::tryFrom(strtolower($value)); |
| 62 | } |
| 63 | } |