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

[Symfony] Guzzle to HttpClient #1614

Closed
TomasVotruba opened this issue Jun 14, 2019 · 10 comments
Closed

[Symfony] Guzzle to HttpClient #1614

TomasVotruba opened this issue Jun 14, 2019 · 10 comments

Comments

@TomasVotruba
Copy link
Member

@stloyd
Copy link
Contributor

stloyd commented Jun 15, 2019

Replacing automatically Guzzle may be hard/impossible, mostly cause it allows creating middlewares etc. so it's really split along the codebase.

Personally I would probably vote for replacing file_get_contents('http(s)://') etc. calls to that new client.

@TomasVotruba
Copy link
Member Author

TomasVotruba commented Jun 15, 2019

Replacing automatically Guzzle may be hard/impossible, mostly cause it allows creating middlewares etc. so it's really split along the codebase.

That's a challange then :) the point is to automate whan can be automized.

Personally I would probably vote for replacing file_get_contents('http(s)://') etc. calls to that new client.

I'm not sure what you mean. Could you share a diff?

@stloyd
Copy link
Contributor

stloyd commented Jun 15, 2019

I.e. from:

$data = file_get_contents('https://api.github.com/repos/symfony/symfony-docs');

Into:

$response = (HttpClient::create())
    ->request('GET', 'https://api.github.com/repos/symfony/symfony-docs');

$data = $response->getContent();

@stloyd
Copy link
Contributor

stloyd commented Jun 15, 2019

Or i.e. POST:

        $result = file_get_contents('https://github.com/', false, stream_context_create(['http' => [
            'method' => 'POST',
            'header' => 'Content-type: application/x-www-form-urlencoded',
            'content' => $postData,
        ]]));

Into:

        $result = (HttpClient::create())->request('POST', 'https://github.com/', [
            'body' => $postData,
        ])->getContent();

@TomasVotruba
Copy link
Member Author

I see. So plain PHP to Symfony/HttpClient?

How would the second code would look like with creation of the client?

@stloyd
Copy link
Contributor

stloyd commented Jun 15, 2019

Can be exactly same as in first :)

@TomasVotruba
Copy link
Member Author

Does it make sense to create new object per call thought? I don't know how you use it, so I need more examples from you to understand it better

@stloyd
Copy link
Contributor

stloyd commented Jun 15, 2019

TBH. I dont really think I have such case currently in code (meaning file_get_* used via HTTP), so those above are more abstraction examples ;)

But for Guzzle, we use it, a lot, but I'm not sure how to help you with example to do some replacement ;)

@TomasVotruba
Copy link
Member Author

Oh, I thought you need it :)
In that case I'm alright

@TomasVotruba
Copy link
Member Author

Closing as too broad, needs specific project

TomasVotruba added a commit that referenced this issue Jan 2, 2022
rectorphp/rector-src@b76243b BinaryOpConditionsCollector: Add tests and fix edge case (#1614)
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

No branches or pull requests

2 participants