Releases: phpro/http-tools
Version 2.5.0
What's Changed
Full Changelog: 2.4.0...2.5.0
Version 2.4.0
What's Changed
ℹ️
Bump to PSL 3 implies bumping PHP to >8.2
People on 8.1 can still use older versions of this package. (it's all pretty stable right now)
Full Changelog: 2.3.0...2.4.0
Version 2.3.0
Version 2.2.0
What's Changed
- Added method romFormData to BinaryDownloadPreset to easily use with form data/requests by @stefliekens in #38
Full Changelog: 2.1.2...2.2.0
Version 2.1.2
Version 2.1.1
Version 2.1.0
What's Changed
- Introduce a BinaryFile decoder by @veewee in #32
- Introduce multipart encoder by @veewee in #33
- Improve error handling of optional dependencies by @veewee in #34
- Add uploads/downloads docs by @veewee in #35
This release focusses on uploading and downloading files;
Download
use Phpro\HttpTools\Encoding\Binary\BinaryFile;
use Phpro\HttpTools\Transport\Presets\BinaryDownloadPreset;
$transport = BinaryDownloadPreset::create($client, $uriBuilder);
$binaryFile = $transport(
new YourDownloadRequest('GET', '/some/file'),
);
assert($binaryFile instanceof BinaryFile);
var_dump(
$binaryFile->stream(),
$binaryFile->fileSizeInBytes(),
$binaryFile->hash(),
$binaryFile->extension(),
$binaryFile->mimeType(),
$binaryFile->fileName(),
);
This decoder will try to parse some information from the Response headers and stream:
- The stream body can be used to tell the size in bytes of the response or to calculate an MD5 (or other algorithm's) hash.
Content-Type
: could be used to guess the mime-typeContent-Disposistion
: could result in guessing the filename, extension and/or mime-type.Content-Length
: could be used to guess the size in bytes of the response.
The decoder is highly configurable, meaning you can alter the way it guesses specific properties or opt-out on intenser logic like calculating a md5 hash.
Upload
use Phpro\HttpTools\Encoding\Json\JsonDecoder;
use Phpro\HttpTools\Encoding\Mime\MultiPartEncoder;
use Phpro\HttpTools\Transport\EncodedTransportFactory;
use Symfony\Component\Mime\Part\DataPart;
use Symfony\Component\Mime\Part\Multipart\FormDataPart;
use Phpro\HttpTools\Request\Request;
$transport = EncodedTransportFactory::create(
$client,
$uriBuilder,
MultiPartEncoder::createWithAutodiscoveredPsrFactories(),
JsonDecoder::createWithAutodiscoveredPsrFactories()
);
$jsonData = $transport(
new YourUploadRequest('POST', '/some/endpoint', new FormDataPart([
'name' => 'Jos bos',
'profile-pic' => DataPart::fromPath('/my-profile-pic.jpg')
])),
);
Note: If you wish not to use symfony/mime
for uploading files, you could use guzzle/psr7
's MultipartStream
with the existing StreamEncoder
option:
use GuzzleHttp\Psr7\MultipartStream;
use Phpro\HttpTools\Encoding\Json\JsonDecoder;
use Phpro\HttpTools\Encoding\Stream\StreamEncoder;
use Phpro\HttpTools\Transport\EncodedTransportFactory;
use Symfony\Component\Mime\Part\DataPart;
use Symfony\Component\Mime\Part\Multipart\FormDataPart;
use Phpro\HttpTools\Request\Request;
$transport = EncodedTransportFactory::create(
$client,
$uriBuilder,
StreamEncoder::createWithAutodiscoveredPsrFactories(),
JsonDecoder::createWithAutodiscoveredPsrFactories()
);
$multiPartStream = new MultipartStream($parts)
$jsonData = $transport(
new YourUploadRequest('POST', '/some/endpoint', $multiPartStream),
);
Full Changelog: 2.0.0...2.1.0
Version 2.0.0
Upgrading
This new version removes the async implementation around amp v2 and httplug promises.
The new suggested way of performing async calls is by using a fiber based PSR-18 HTTP client.
Upgrading async transports
Your async transports and handlers can be transformed to regular sync
implementations.
You will need to provide a fiber based PSR-18 client as documented.
This client can then be used to run HTTP calls in parallel, using either reactphp or amphp v3.
$client = new AsyncPsr18Browser(new Browser());
$transport = JsonPreset::create($client, new TemplatedUriBuilder());
$handler = new FetchSomething($transport);
$run = fn($id) => async(fn () => $handler(new FetchRequest($id)));
$things = await(parallel([
$run(1),
$run(2),
$run(3),
]));
Upgrading sync transports
Previously, all presets had both a sync()
and async()
named constructor.
Since this package now doesn't distinguish this anymore, there is only one create()
named constructor.
You'll need to replace all occurences.
For example:
- JsonTransport::sync(...);
+ JsonTransport::create(...);
- JsonTransport::async(...);
+ JsonTransport::create(...);
- RawTransport::async(...);
+ RawTransport::create(...);
- RawTransport::async(...);
+ RawTransport::create(...);
What's Changed
Full Changelog: 1.4.1...2.0.0
Version 1.4.1
Version 1.4.0
What's Changed
Full Changelog: 1.3.0...1.4.0