What’s new in 3.5
Version 3.5 only contains fixes. Streams now read as PSR-7 specifies, route paths match their literal text exactly, and the HTTP client sends request bodies it previously dropped.
Some of these fixes change a behavior your project may rely on. To upgrade, follow Upgrading from version 3.4 to 3.5.
Streams read from the cursor
getContents() now returns what remains after the cursor, instead of the whole stream. To read the whole body of a
seekable stream, cast it to a string:
$stream = (new \Berlioz\Http\Message\HttpFactory())->createStream('abcdef');
$stream->read(2); // 'ab'
$stream->getContents(); // 'cdef'
(string) $stream; // 'abcdef'
A stream created from a string now starts at position zero: an immediate write() replaces its first bytes.
See Reading a stream.
Exact route paths
The literal text of a route path now matches exactly: /sitemap.xml no longer matches /sitemap-xml, and
/catalogue/C++ matches the URL it generates. Regular expressions are only interpreted inside placeholders:
$route = new \Berlioz\Router\Route('/sitemap.xml');
$route = new \Berlioz\Router\Route('/files/{type:css|js}/app');
See Route attributes.
Non-seekable request bodies
The HTTP client now sends a request whose body cannot be rewound, such as a socket or a pipe. It copies the body
first, so the Content-Length header matches and the body is sent again on a retry:
use Berlioz\Http\Client\Client;
use Berlioz\Http\Message\Request;
use Berlioz\Http\Message\Stream;
$body = new Stream(fopen('php://stdin', 'r'));
$request = new Request('POST', 'https://example.com/upload', $body);
$response = (new Client())->sendRequest($request);
See Non-seekable request bodies.
Other changes
- HTTP client: A
201 Createdresponse is returned as received, without following itsLocationheader. See Redirect security. - HTTP client:
getCode()returns the cURL error number when the cURL adapter reports the failure. See Error code. - Queues: The metadata of each deleted Redis job now expires on its own,
deletedJobsTtlseconds after the deletion. See RedisQueue.