diff --git a/UPGRADE-1.13.md b/UPGRADE-1.13.md
index 51d6aa0249..cebe051bd4 100644
--- a/UPGRADE-1.13.md
+++ b/UPGRADE-1.13.md
@@ -53,7 +53,6 @@
to `Sylius\Bundle\CoreBundle\Validator\Constraints\HasEnabledEntityValidator`
as the second argument is deprecated.
-<<<<<<< HEAD
1. Class `\Sylius\Bundle\ShopBundle\Calculator\OrderItemsSubtotalCalculator` has been deprecated. Order items subtotal calculation
is now available on the Order model `\Sylius\Component\Core\Model\Order::getItemsSubtotal`.
@@ -68,11 +67,25 @@
To add more data per variant create a service implementing the `Sylius\Component\Core\Provider\ProductVariantMap\ProductVariantMapProviderInterface` and tag it with `sylius.product_variant_data_map_provider`.
-1. Using Guzzle has been deprecated in favor of Symfony HTTP Client. Therefore, passing `GuzzleHttp\ClientInterface`
-=======
-1. Using Guzzle has been deprecated in favor of Symfony HTTP Client. Therefore, passing Guzzle 6 `GuzzleHttp\ClientInterface`
- or any other HTTP Client that does not implement `Psr\Http\Client\ClientInterface`
->>>>>>> 577914fa71 ([Admin] Improve deprecations in NotificationController)
- to `Sylius\Bundle\AdminBundle\Controller\NotificationController` as a second argument is deprecated.
+1. Using Guzzle 6 has been deprecated in favor of Symfony HTTP Client.
+ Therefore, the constructor of `Sylius\Bundle\AdminBundle\Controller\NotificationController` has been changed:
-1. The `sylius.http_message_factory` service has been deprecated. Use `sylius.http_request_factory` instead.
+ ```diff
+ public function __construct(
+ - private ClientInterface $client,
+ - private MessageFactory $messageFactory,
+ + private ClientInterface|DeprecatedClientInterface $client,
+ + private RequestFactoryInterface|MessageFactory $requestFactory,
+ private string $hubUri,
+ private string $environment,
+ + private ?StreamFactoryInterface $streamFactory = null,
+ ) {
+ ...
+ }
+ ```
+
+1. The `sylius.http_message_factory` service has been deprecated. Use `Psr\Http\Message\RequestFactoryInterface` instead.
+
+1. The `sylius.http_client` has become an alias to `psr18.http_client` service.
+
+1. The `sylius.payum.http_client` has become a service ID of newly created `Sylius\Bundle\PayumBundle\HttpClient\HttpClient`.
diff --git a/composer-require-checker.json b/composer-require-checker.json
index 20c18f98b3..2bcc0f08e4 100644
--- a/composer-require-checker.json
+++ b/composer-require-checker.json
@@ -30,6 +30,8 @@
"League\\Flysystem\\FilesystemOperator",
"Symfony\\Component\\Security\\Core\\Encoder\\EncoderFactoryInterface",
"PHPUnit\\Framework\\ExpectationFailedException",
+ "Psr\\Http\\Message\\RequestFactoryInterface",
+ "Psr\\Http\\Message\\StreamFactoryInterface",
"Stripe\\Stripe"
],
"php-core-extensions" : [
diff --git a/src/Sylius/Bundle/AdminBundle/Controller/NotificationController.php b/src/Sylius/Bundle/AdminBundle/Controller/NotificationController.php
index 6d457c6c0f..b747ae6b01 100644
--- a/src/Sylius/Bundle/AdminBundle/Controller/NotificationController.php
+++ b/src/Sylius/Bundle/AdminBundle/Controller/NotificationController.php
@@ -15,9 +15,12 @@ namespace Sylius\Bundle\AdminBundle\Controller;
use GuzzleHttp\ClientInterface as DeprecatedClientInterface;
use GuzzleHttp\Exception\GuzzleException;
-use Http\Message\RequestFactory;
+use Http\Message\MessageFactory;
+use Nyholm\Psr7\Stream;
use Psr\Http\Client\ClientExceptionInterface;
use Psr\Http\Client\ClientInterface;
+use Psr\Http\Message\RequestFactoryInterface;
+use Psr\Http\Message\StreamFactoryInterface;
use Sylius\Bundle\CoreBundle\SyliusCoreBundle;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
@@ -26,33 +29,43 @@ final class NotificationController
{
public function __construct(
private ClientInterface|DeprecatedClientInterface $client,
- private RequestFactory $requestFactory,
+ private RequestFactoryInterface|MessageFactory $requestFactory,
private string $hubUri,
private string $environment,
+ private ?StreamFactoryInterface $streamFactory = null,
) {
if (!$client instanceof ClientInterface) {
- trigger_deprecation('sylius/admin-bundle', '1.13', 'Using a service that does not implement "%s" is deprecated and will be prohibited in 2.0.', ClientInterface::class);
+ trigger_deprecation('sylius/admin-bundle', '1.13', 'Using a service that does not implement "%s" as a 1st argument of "%s" constructor is deprecated and will be prohibited in 2.0.', ClientInterface::class, self::class);
+ }
+
+ if (!$requestFactory instanceof RequestFactoryInterface) {
+ trigger_deprecation('sylius/admin-bundle', '1.13', 'Using a service that does not implement "%s" as a 2nd argument of "%s" constructor is deprecated and will be prohibited in 2.0.', RequestFactoryInterface::class, self::class);
+ }
+
+ if (null === $streamFactory) {
+ trigger_deprecation('sylius/admin-bundle', '1.13', 'Not passing a service that implements "%s" as a 5th argument of "%s" constructor is deprecated and will be prohibited in 2.0.', StreamFactoryInterface::class, self::class);
}
}
public function getVersionAction(Request $request): JsonResponse
{
- $content = [
+ $content = json_encode([
'version' => SyliusCoreBundle::VERSION,
'hostname' => $request->getHost(),
'locale' => $request->getLocale(),
'user_agent' => $request->headers->get('User-Agent'),
'environment' => $this->environment,
- ];
+ ]);
- $headers = ['Content-Type' => 'application/json'];
-
- $hubRequest = $this->requestFactory->createRequest(
- Request::METHOD_GET,
- $this->hubUri,
- $headers,
- json_encode($content),
- );
+ $hubRequest = $this->requestFactory
+ ->createRequest(Request::METHOD_GET, $this->hubUri)
+ ->withHeader('Content-Type', 'application/json')
+ ->withBody(
+ null === $this->streamFactory
+ ? Stream::create($content)
+ : $this->streamFactory->createStream($content)
+ )
+ ;
try {
if ($this->client instanceof DeprecatedClientInterface) {
diff --git a/src/Sylius/Bundle/AdminBundle/Resources/config/services.xml b/src/Sylius/Bundle/AdminBundle/Resources/config/services.xml
index 74836dc3bb..df9faace93 100644
--- a/src/Sylius/Bundle/AdminBundle/Resources/config/services.xml
+++ b/src/Sylius/Bundle/AdminBundle/Resources/config/services.xml
@@ -82,10 +82,9 @@
-
+
- The "%service_id%" service is deprecated since 1.13 and will be removed in 2.0. Use "sylius.http_request_factory" instead.
+ The "%service_id%" service is deprecated since 1.13 and will be removed in 2.0. Use "Psr\Http\Message\RequestFactoryInterface" instead.
-
diff --git a/src/Sylius/Bundle/AdminBundle/Resources/config/services/controller.xml b/src/Sylius/Bundle/AdminBundle/Resources/config/services/controller.xml
index 399b46134d..57e22fbaf4 100644
--- a/src/Sylius/Bundle/AdminBundle/Resources/config/services/controller.xml
+++ b/src/Sylius/Bundle/AdminBundle/Resources/config/services/controller.xml
@@ -90,9 +90,10 @@
-
+
%sylius.admin.notification.uri%
%kernel.environment%
+
diff --git a/src/Sylius/Bundle/AdminBundle/Tests/Controller/NotificationControllerTest.php b/src/Sylius/Bundle/AdminBundle/Tests/Controller/NotificationControllerTest.php
index 1547db9b35..35486060f2 100644
--- a/src/Sylius/Bundle/AdminBundle/Tests/Controller/NotificationControllerTest.php
+++ b/src/Sylius/Bundle/AdminBundle/Tests/Controller/NotificationControllerTest.php
@@ -16,14 +16,15 @@ namespace Sylius\Bundle\AdminBundle\Tests\Controller;
use GuzzleHttp\Exception\ConnectException;
use Http\Client\Exception\NetworkException;
use Http\Message\MessageFactory;
-use Http\Message\RequestFactory;
use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait;
use Prophecy\Prophecy\ObjectProphecy;
use Prophecy\Prophecy\ProphecyInterface;
+use Psr\Http\Message\RequestFactoryInterface;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
+use Psr\Http\Message\StreamFactoryInterface;
use Psr\Http\Message\StreamInterface;
use Sylius\Bundle\AdminBundle\Controller\NotificationController;
use Symfony\Component\HttpFoundation\JsonResponse;
@@ -41,6 +42,8 @@ final class NotificationControllerTest extends TestCase
private ObjectProphecy $messageFactory;
+ private ObjectProphecy $streamFactory;
+
private NotificationController $controller;
private NotificationController $legacyController;
@@ -50,9 +53,14 @@ final class NotificationControllerTest extends TestCase
/** @test */
public function it_returns_an_empty_json_response_upon_client_exception(): void
{
- $this->requestFactory->createRequest(Argument::cetera())
- ->willReturn($this->prophesize(RequestInterface::class)->reveal())
- ;
+ $requestInterface = $this->prophesize(RequestInterface::class);
+ $streamInterface = $this->prophesize(StreamInterface::class);
+
+ $this->streamFactory->createStream(Argument::cetera())->willReturn($streamInterface);
+
+ $this->requestFactory->createRequest(Argument::cetera())->willReturn($requestInterface);
+ $requestInterface->withHeader('Content-Type', 'application/json')->willReturn($requestInterface);
+ $requestInterface->withBody($streamInterface)->willReturn($requestInterface);
$this->client->sendRequest(Argument::cetera())->willThrow(NetworkException::class);
@@ -69,9 +77,11 @@ final class NotificationControllerTest extends TestCase
*/
public function it_returns_an_empty_json_response_upon_client_exception_deprecated(): void
{
- $this->messageFactory->createRequest(Argument::any(), Argument::cetera())
- ->willReturn($this->prophesize(RequestInterface::class)->reveal())
- ;
+ $requestInterface = $this->prophesize(RequestInterface::class);
+
+ $this->messageFactory->createRequest(Argument::cetera())->willReturn($requestInterface);
+ $requestInterface->withHeader('Content-Type', 'application/json')->willReturn($requestInterface);
+ $requestInterface->withBody(Argument::any())->willReturn($requestInterface);
$this->legacyClient->send(Argument::cetera())->willThrow(ConnectException::class);
@@ -86,9 +96,14 @@ final class NotificationControllerTest extends TestCase
{
$content = json_encode(['version' => '9001']);
- $this->requestFactory->createRequest(Argument::cetera())
- ->willReturn($this->prophesize(RequestInterface::class)->reveal())
- ;
+ $requestInterface = $this->prophesize(RequestInterface::class);
+ $streamInterface = $this->prophesize(StreamInterface::class);
+
+ $this->streamFactory->createStream(Argument::cetera())->willReturn($streamInterface);
+
+ $this->requestFactory->createRequest(Argument::cetera())->willReturn($requestInterface);
+ $requestInterface->withHeader('Content-Type', 'application/json')->willReturn($requestInterface);
+ $requestInterface->withBody($streamInterface)->willReturn($requestInterface);
/** @var ProphecyInterface|StreamInterface $stream */
$stream = $this->prophesize(StreamInterface::class);
@@ -115,9 +130,11 @@ final class NotificationControllerTest extends TestCase
{
$content = json_encode(['version' => '9001']);
- $this->messageFactory->createRequest(Argument::any(), Argument::cetera())
- ->willReturn($this->prophesize(RequestInterface::class)->reveal())
- ;
+ $requestInterface = $this->prophesize(RequestInterface::class);
+
+ $this->messageFactory->createRequest(Argument::cetera())->willReturn($requestInterface);
+ $requestInterface->withHeader('Content-Type', 'application/json')->willReturn($requestInterface);
+ $requestInterface->withBody(Argument::any())->willReturn($requestInterface);
/** @var ProphecyInterface|StreamInterface $stream */
$stream = $this->prophesize(StreamInterface::class);
@@ -139,14 +156,16 @@ final class NotificationControllerTest extends TestCase
{
$this->client = $this->prophesize(\Psr\Http\Client\ClientInterface::class);
$this->legacyClient = $this->prophesize(\GuzzleHttp\ClientInterface::class);
- $this->requestFactory = $this->prophesize(RequestFactory::class);
+ $this->requestFactory = $this->prophesize(RequestFactoryInterface::class);
$this->messageFactory = $this->prophesize(MessageFactory::class);
+ $this->streamFactory = $this->prophesize(StreamFactoryInterface::class);
$this->controller = new NotificationController(
$this->client->reveal(),
$this->requestFactory->reveal(),
self::$hubUri,
'environment',
+ $this->streamFactory->reveal(),
);
$this->legacyController = new NotificationController(
diff --git a/src/Sylius/Bundle/PayumBundle/HttpClient/HttpClient.php b/src/Sylius/Bundle/PayumBundle/HttpClient/HttpClient.php
index 148c2acd1e..1ef4ae90b9 100644
--- a/src/Sylius/Bundle/PayumBundle/HttpClient/HttpClient.php
+++ b/src/Sylius/Bundle/PayumBundle/HttpClient/HttpClient.php
@@ -13,13 +13,13 @@ declare(strict_types=1);
namespace Sylius\Bundle\PayumBundle\HttpClient;
-use Http\Client\HttpClient as BaseHttpClientInterface;
use Payum\Core\HttpClientInterface;
+use Psr\Http\Client\ClientInterface;
use Psr\Http\Message\RequestInterface;
final class HttpClient implements HttpClientInterface
{
- public function __construct(private BaseHttpClientInterface $client)
+ public function __construct(private ClientInterface $client)
{
}
diff --git a/src/Sylius/Bundle/PayumBundle/Resources/config/services.xml b/src/Sylius/Bundle/PayumBundle/Resources/config/services.xml
index 947963ddab..293ef42770 100644
--- a/src/Sylius/Bundle/PayumBundle/Resources/config/services.xml
+++ b/src/Sylius/Bundle/PayumBundle/Resources/config/services.xml
@@ -29,7 +29,7 @@
-
+