Use Http\Client\HttpClient service instead of HttplugClient explicitly

This commit is contained in:
Kevin Kaniaburka 2023-04-13 16:01:49 +02:00
parent 352b7464c1
commit b15cd4c1db
No known key found for this signature in database
GPG key ID: 8DB4C54474F3FD72
8 changed files with 95 additions and 7 deletions

View file

@ -23,6 +23,7 @@
"Behat\\Testwork\\Tester\\Setup\\Teardown",
"Doctrine\\DBAL\\Platforms\\MySqlPlatform",
"Doctrine\\DBAL\\Platforms\\MySQLPlatform",
"Http\\Client\\HttpClient",
"HWI\\Bundle\\OAuthBundle\\Connect\\AccountConnectorInterface",
"HWI\\Bundle\\OAuthBundle\\OAuth\\Response\\UserResponseInterface",
"HWI\\Bundle\\OAuthBundle\\Security\\Core\\User\\OAuthAwareUserProviderInterface",

View file

@ -59,6 +59,7 @@
"league/flysystem-bundle": "^2.4",
"lexik/jwt-authentication-bundle": "^2.11",
"liip/imagine-bundle": "^2.10",
"nyholm/psr7": "^1.6",
"pagerfanta/pagerfanta": "^3.0",
"payum/payum": "^1.7.2",
"payum/payum-bundle": "^2.5",

View file

@ -0,0 +1,21 @@
services:
# Register nyholm/psr7 services for autowiring with PSR-17 (HTTP factories)
Psr\Http\Message\RequestFactoryInterface: '@nyholm.psr7.psr17_factory'
Psr\Http\Message\ResponseFactoryInterface: '@nyholm.psr7.psr17_factory'
Psr\Http\Message\ServerRequestFactoryInterface: '@nyholm.psr7.psr17_factory'
Psr\Http\Message\StreamFactoryInterface: '@nyholm.psr7.psr17_factory'
Psr\Http\Message\UploadedFileFactoryInterface: '@nyholm.psr7.psr17_factory'
Psr\Http\Message\UriFactoryInterface: '@nyholm.psr7.psr17_factory'
# Register nyholm/psr7 services for autowiring with HTTPlug factories
Http\Message\MessageFactory: '@nyholm.psr7.httplug_factory'
Http\Message\RequestFactory: '@nyholm.psr7.httplug_factory'
Http\Message\ResponseFactory: '@nyholm.psr7.httplug_factory'
Http\Message\StreamFactory: '@nyholm.psr7.httplug_factory'
Http\Message\UriFactory: '@nyholm.psr7.httplug_factory'
nyholm.psr7.psr17_factory:
class: Nyholm\Psr7\Factory\Psr17Factory
nyholm.psr7.httplug_factory:
class: Nyholm\Psr7\Factory\HttplugFactory

View file

@ -82,10 +82,10 @@
<tag name="twig.extension" />
</service>
<service id="sylius.http_client" class="Symfony\Component\HttpClient\HttplugClient" public="false" />
<service id="sylius.http_client" alias="Http\Client\HttpClient" public="false" />
<service id="sylius.http_message_factory" class="Http\Message\MessageFactory\GuzzleMessageFactory" public="false">
<deprecated package="sylius/admin-bundle" version="1.13">The "%service_id%" service is deprecated since 1.13 and will be removed in 2.0. Use "sylius.http_request_factory" instead.</deprecated>
</service>
<service id="sylius.http_request_factory" class="Symfony\Component\HttpClient\HttplugClient" public="false" />
<service id="sylius.http_request_factory" alias="Http\Client\HttpClient" public="false" />
</services>
</container>

View file

@ -13,16 +13,18 @@ declare(strict_types=1);
namespace Sylius\Bundle\PayumBundle\HttpClient;
use Http\Client\HttpClient as BaseHttpClientInterface;
use Payum\Core\HttpClientInterface;
use Psr\Http\Message\RequestInterface;
use Symfony\Component\HttpClient\HttplugClient;
final class HttpClient implements HttpClientInterface
{
public function __construct(private BaseHttpClientInterface $client)
{
}
public function send(RequestInterface $request)
{
$client = new HttplugClient();
return $client->sendRequest($request);
return $this->client->sendRequest($request);
}
}

View file

@ -28,7 +28,9 @@
<services>
<defaults public="true" />
<service id="sylius.payum.http_client" class="Sylius\Bundle\PayumBundle\HttpClient\HttpClient" />
<service id="sylius.payum.http_client" class="Sylius\Bundle\PayumBundle\HttpClient\HttpClient">
<argument type="service" id="Http\Client\HttpClient" />
</service>
<service id="sylius.form_registry.payum_gateway_config" class="Sylius\Bundle\ResourceBundle\Form\Registry\FormTypeRegistry" />
</services>
</container>

View file

@ -0,0 +1,49 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace spec\Sylius\Bundle\PayumBundle\HttpClient;
use Psr\Http\Client\ClientInterface;
use Payum\Core\HttpClientInterface;
use PhpSpec\ObjectBehavior;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Sylius\Bundle\PayumBundle\HttpClient\HttpClient;
final class HttpClientSpec extends ObjectBehavior
{
function let(ClientInterface $client): void
{
$this->beConstructedWith($client);
}
function it_is_initializable(): void
{
$this->shouldHaveType(HttpClient::class);
}
function it_implements_http_client_interface(): void
{
$this->shouldImplement(HttpClientInterface::class);
}
function it_sends_a_request(
ClientInterface $client,
RequestInterface $request,
ResponseInterface $response
): void {
$client->sendRequest($request)->willReturn($response);
$this->send($request)->shouldReturn($response);
}
}

View file

@ -367,6 +367,18 @@
"nikic/php-parser": {
"version": "v4.6.0"
},
"nyholm/psr7": {
"version": "1.6",
"recipe": {
"repo": "github.com/symfony/recipes",
"branch": "main",
"version": "1.0",
"ref": "0cd4d2d0e7f646fda75f9944f747a56e6ed13d4c"
},
"files": [
"config/packages/nyholm_psr7.yaml"
]
},
"openlss/lib-array2xml": {
"version": "1.0.0"
},