azjezz/psl
PSL is a modern, well-typed standard library for PHP 8.4+, inspired by HHVM’s HSL. It offers safer, predictable APIs for async, collections, networking, I/O, crypto, terminal UI, and robust data validation—replacing brittle built-ins with consistent alternatives.
The MIME component implements the Multipurpose Internet Mail Extensions (RFC 2045-2049) and related standards. It provides media type parsing, MIME part construction, multipart body streaming, content sniffing, S/MIME cryptography, and DKIM signing - all without filesystem coupling or temporary files.
MediaType is an immutable value object representing a MIME media type like application/json or text/html; charset=utf-8. Type and subtype are always lowercased. Structured syntax suffixes and registration trees are extracted automatically.
@example('protocols/mime-media-type.php')
MediaPreferences parses HTTP Accept headers and negotiates the best media type per RFC 9110.
@example('protocols/mime-negotiation.php')
Parts are the building blocks of MIME messages. Every part implements PartInterface, which exposes $mediaType, $headers, and body().
@example('protocols/mime-parts.php')
Multipart types compose multiple parts into a single body, delimited by a boundary string. All multipart types implement MultiPartInterface (which extends PartInterface), so they nest naturally.
@example('protocols/mime-multipart.php')
Form builds multipart/form-data bodies per RFC 7578, for HTML form submissions and file uploads.
@example('protocols/mime-form.php')
The streaming parser yields parts lazily from a read handle, with configurable limits to prevent abuse.
@example('protocols/mime-parser.php')
Sign, verify, encrypt, and decrypt using CMS (RFC 5652) - entirely in-memory without temporary files or openssl_pkcs7_* functions.
@example('protocols/mime-smime.php')
Sign raw MIME messages with DKIM (RFC 6376) using RSA-SHA256 or Ed25519-SHA256 (RFC 8463). RSA keys below 1024 bits are rejected per RFC 8301.
@example('protocols/mime-dkim.php')
Detect MIME types from content bytes using magic signatures, RIFF sub-formats, ISO BMFF brands, and text heuristics. Works on raw byte strings or seekable read handles.
| RFC | Coverage |
|---|---|
| RFC 2045 | Media types, parameters, transfer encoding |
| RFC 2046 | Multipart bodies, boundary rules |
| RFC 2183 | Content-Disposition with safe filename |
| RFC 2231 | Parameter encoding with continuations and charset |
| RFC 2387 | multipart/related |
| RFC 2392 | Content-ID parsing and generation |
| RFC 5322 | Header line folding |
| RFC 5652 | CMS signing, verification, encryption, decryption |
| RFC 6376 | DKIM signing with simple/relaxed canonicalization |
| RFC 6838 | Media type registration, suffix/tree extraction |
| RFC 7578 | multipart/form-data |
| RFC 8301 | DKIM minimum key size enforcement |
| RFC 8463 | Ed25519-SHA256 DKIM signing |
| RFC 8551 | S/MIME 4.0 message specification |
| RFC 9110 | Content negotiation (Accept header) |
See src/Psl/MIME/ for the full API.
How can I help you explore Laravel packages today?