PSL 5.5.0
IO: Bounded Reads
Reader::readUntilBounded() reads from a handle until a suffix is found, just like readUntil(), but enforces a maximum byte limit. If the suffix is not encountered within $max_bytes, an IO\Exception\OverflowException is thrown.
This is essential when reading from untrusted sources. for example, capping HTTP header lines so a malicious client cannot exhaust memory by sending an endless line:
use Psl\IO;
$reader = new IO\Reader($connection);
// Read a header line, but never buffer more than 8KB
$line = $reader->readUntilBounded("\r\n", max_bytes: 8192);Type: Type\json_decoded() and Type\nullish()
Two new type coercions from @veewee:
-
Type\json_decoded(TypeInterface $inner): accepts a JSON string and transparently decodes it, then coerces the result through$inner. Useful for APIs and form fields that pass structured data as JSON strings. -
Type\nullish(TypeInterface $inner): matchesnull, the absence of a key (for shape fields), and the inner type. Ideal for optional-and-nullable shape fields where "missing" and "null" should be treated the same.
Documentation: psl.carthage.software/ | IO | Type
Full Changelog: 5.4.0...5.5.0