Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce multipart encoder #33

Merged
merged 1 commit into from
Nov 9, 2023
Merged

Conversation

veewee
Copy link
Contributor

@veewee veewee commented Nov 9, 2023

Q A
Type feature
BC Break no
Fixed issues

Summary

This PR allows for sending multipart form messages, uploads, mixed multi-parts, ... based on the parts available inside symfony/mime.

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 Request('GET', '/some/file', [], new FormDataPart([
        'name' => 'Jos bos',
        'profile-pic' => DataPart::fromPath('/my-profile-pic.jpg')
    ])),
);

If you wish not to use symfony/mime for this, you could use guzzle/psr7's MultipartStream with the existing StreamEncoder option:

@veewee veewee requested a review from stefliekens November 9, 2023 12:04
@janvernieuwe
Copy link
Member

Nice! this will make some (crappy) api's a lot easier to use!

@veewee veewee merged commit 1f2eb53 into phpro:v2.x Nov 9, 2023
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants