8000 [HttpClient] Remove implementing `Http\Message\RequestFactory` from `HttplugClient` by nicolas-grekas · Pull Request #50862 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[HttpClient] Remove implementing Http\Message\RequestFactory from HttplugClient #50862

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 GitHu 8000 b”, 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

Merged
merged 1 commit into from
Jul 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions UPGRADE-7.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ HttpFoundation
* Remove `Request::getContentType()`, use `Request::getContentTypeFormat()` instead
* Throw an `InvalidArgumentException` when calling `Request::create()` with a malformed URI

HttpClient
----------

* Remove implementing `Http\Message\RequestFactory` from `HttplugClient`

HttpKernel
----------

Expand Down
5 changes: 5 additions & 0 deletions src/Symfony/Component/HttpClient/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
CHANGELOG
=========

7.0
---

* Remove implementing `Http\Message\RequestFactory` from `HttplugClient`

6.4
---

Expand Down
60 changes: 6 additions & 54 deletions src/Symfony/Component/HttpClient/HttplugClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
use Psr\Http\Message\UriFactoryInterface;
use Psr\Http\Message\UriInterface;
use Symfony\Component\HttpClient\Internal\HttplugWaitLoop;
use Symfony\Component\HttpClient\Internal\LegacyHttplugInterface;
use Symfony\Component\HttpClient\Response\HttplugPromise;
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface;
Expand All @@ -57,7 +56,7 @@
*
* @author Nicolas Grekas <p@tchwork.com>
*/
final class HttplugClient implements ClientInterface, HttpAsyncClient, RequestFactoryInterface, StreamFactoryInterface, UriFactoryInterface, ResetInterface, LegacyHttplugInterface
final class HttplugClient implements ClientInterface, HttpAsyncClient, RequestFactoryInterface, StreamFactoryInterface, UriFactoryInterface, ResetInterface
{
private HttpClientInterface $client;
private ResponseFactoryInterface $responseFactory;
Expand Down Expand Up @@ -150,14 +149,10 @@ public function wait(float $maxDuration = null, float $idleTimeout = null): int
}

/**
* @param string $method
* @param UriInterface|string $uri
*/
public function createRequest($method, $uri, array $headers = [], $body = null, $protocolVersion = '1.1'): RequestInterface
public function createRequest(string $method, $uri = ''): RequestInterface
{
if (2 < \func_num_args()) {
trigger_deprecation('symfony/http-client', '6.2', 'Passing more than 2 arguments to "%s()" is deprecated.', __METHOD__);
}
if ($this->responseFactory instanceof RequestFactoryInterface) {
$request = $this->responseFactory->createRequest($method, $uri);
} elseif (class_exists(Psr17FactoryDiscovery::class)) {
Expand All @@ -168,44 +163,12 @@ public function createRequest($method, $uri, array $headers = [], $body = null,
throw new \LogicException(sprintf('You cannot use "%s()" as no PSR-17 factories have been found. Try running "composer require php-http/discovery psr/http-factory-implementation:*".', __METHOD__));
}

$request = $request
->withProtocolVersion($protocolVersion)
->withBody($this->create 10000 Stream($body ?? ''))
;

foreach ($headers as $name => $value) {
$request = $request->withAddedHeader($name, $value);
}

return $request;
}

/**
* @param string $content
*/
public function createStream($content = ''): StreamInterface
public function createStream(string $content = ''): StreamInterface
{
if (!\is_string($content)) {
trigger_deprecation('symfony/http-client', '6.2', 'Passing a "%s" to "%s()" is deprecated, use "createStreamFrom*()" instead.', get_debug_type($content), __METHOD__);
}

if ($content instanceof StreamInterface) {
return $content;
}

if (\is_string($content ?? '')) {
$stream = $this->streamFactory->createStream($content ?? '');
} elseif (\is_resource($content)) {
$stream = $this->streamFactory->createStreamFromResource($content);
} else {
throw new \InvalidArgumentException(sprintf('"%s()" expects string, resource or StreamInterface, "%s" given.', __METHOD__, get_debug_type($content)));
}

if ($stream->isSeekable()) {
$stream->seek(0);
}

return $stream;
return $this->streamFactory->createStream($content);
}

public function createStreamFromFile(string $filename, string $mode = 'r'): StreamInterface
Expand All @@ -218,25 +181,14 @@ public function createStreamFromResource($resource): StreamInterface
return $this->streamFactory->createStreamFromResource($resource);
}

/**
* @param string $uri
*/
public function createUri($uri = ''): UriInterface
public function createUri(string $uri = ''): UriInterface
{
if (!\is_string($uri)) {
trigger_deprecation('symfony/http-client', '6.2', 'Passing a "%s" to "%s()" is deprecated, pass a string instead.', get_debug_type($uri), __METHOD__);
}

if ($uri instanceof UriInterface) {
return $uri;
}

if ($this->responseFactory instanceof UriFactoryInterface) {
return $this->responseFactory->createUri($uri);
}

if (class_exists(Psr17FactoryDiscovery::class)) {
return Psr17FactoryDiscovery::findUrlFactory()->createUri($uri);
return Psr17FactoryDiscovery::findUriFactory()->createUri($uri);
}

if (class_exists(Uri::class)) {
Expand Down

This file was deleted.

1 change: 0 additions & 1 deletion src/Symfony/Component/HttpClient/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
"require": {
"php": ">=8.2",
"psr/log": "^1|^2|^3",
"symfony/deprecation-contracts": "^2.5|^3",
"symfony/http-client-contracts": "^3",
"symfony/service-contracts": "^2.5|^3"
},
Expand Down
0