Skip to content
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
* Copyright 2022 Adobe
* All Rights Reserved.
*/
declare(strict_types=1);

namespace Magento\TestModuleCatalogSearch\Model;

use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\TestFramework\Helper\Bootstrap;
use Magento\TestFramework\Helper\Curl;
use Magento\Framework\HTTP\Client\Curl;

/**
* Retrieve search engine version by curl request
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,34 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
* Copyright 2018 Adobe
* All Rights Reserved.
*/

declare(strict_types=1);

namespace Magento\TestFramework\Helper;

use Magento\Framework\HTTP\Client\Curl;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In line no. 53:

$this->curl = new Curl(); 

I suggest you add the parameter $curl as null and use ObjectManager to initialize it. Please refer to the $this->deploymentConfig

use Magento\Framework\App\DeploymentConfig;

/**
* Helper class to access RabbitMQ server configuration
*/
class Amqp
{
const CONFIG_PATH_HOST = 'queue/amqp/host';
const CONFIG_PATH_USER = 'queue/amqp/user';
const CONFIG_PATH_PASSWORD = 'queue/amqp/password';
const DEFAULT_MANAGEMENT_PROTOCOL = 'http';
const DEFAULT_MANAGEMENT_PORT = '15672';
const DEFAULT_VIRTUALHOST = '/';
public const CONFIG_PATH_HOST = 'queue/amqp/host';
public const CONFIG_PATH_USER = 'queue/amqp/user';
public const CONFIG_PATH_PASSWORD = 'queue/amqp/password';
public const DEFAULT_MANAGEMENT_PROTOCOL = 'http';
public const DEFAULT_MANAGEMENT_PORT = '15672';
public const DEFAULT_VIRTUALHOST = '/';

/**
* @var Curl
*/
private $curl;

/**
* @var \Magento\Framework\App\DeploymentConfig
* @var DeploymentConfig
*/
private $deploymentConfig;

Expand All @@ -42,14 +44,17 @@ class Amqp

/**
* Initialize dependencies.
* @param \Magento\Framework\App\DeploymentConfig $deploymentConfig
* @param DeploymentConfig $deploymentConfig
* @param Curl $curl
*/
public function __construct(
\Magento\Framework\App\DeploymentConfig $deploymentConfig = null
DeploymentConfig $deploymentConfig = null,
Curl $curl = null
) {
$this->deploymentConfig = $deploymentConfig ?? \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
->get(\Magento\Framework\App\DeploymentConfig::class);
$this->curl = new Curl();
->get(DeploymentConfig::class);
$this->curl = $curl ?? \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
->get(Curl::class);
$this->curl->setCredentials(
$this->deploymentConfig->get(self::CONFIG_PATH_USER),
$this->deploymentConfig->get(self::CONFIG_PATH_PASSWORD)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,18 @@
<?php
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not recommended to delete the existing file, as other third-party extensions might use it. Instead, mark it as deprecated.

Thanks

/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
* Copyright 2018 Adobe
* All Rights Reserved.
*/

declare(strict_types=1);

namespace Magento\TestFramework\Helper;

use Magento\Framework\HTTP\Client\Curl as CurlLibrary;

/**
* @deprecated All the curl methods are included in \Magento\Framework\HTTP\Client\Curl class.
* @see \Magento\Framework\HTTP\Client\Curl
*/
class Curl extends CurlLibrary
{
/**
* Make DELETE request
*
* String type was added to parameter $param in order to support sending JSON or XML requests.
* This feature was added base on Community Pull Request https://github.com/magento/magento2/pull/8373
*
* @param string $uri
* @return void
*
* @see \Magento\Framework\HTTP\Client#post($uri, $params)
*/
public function delete($uri)
{
$this->makeRequest("DELETE", $uri);
}
}
106 changes: 101 additions & 5 deletions lib/internal/Magento/Framework/HTTP/Client/Curl.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
* Copyright 2011 Adobe
* All Rights Reserved.
*/

declare(strict_types=1);

namespace Magento\Framework\HTTP\Client;

/**
* Class to work with HTTP protocol using curl library
*
* @author Magento Core Team <core@magentocommerce.com>
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
* @api
*/
Expand Down Expand Up @@ -223,6 +221,8 @@ public function removeCookies()
*
* @param string $uri uri relative to host, ex. "/index.php"
* @return void
*
* @url https://www.rfc-editor.org/rfc/rfc9110.html#section-9.3.1
*/
public function get($uri)
{
Expand All @@ -239,13 +239,109 @@ public function get($uri)
* @param array|string $params
* @return void
*
* @see \Magento\Framework\HTTP\Client#post($uri, $params)
* @see \Magento\Framework\HTTP\Client::post($uri, $params)
* @url https://www.rfc-editor.org/rfc/rfc9110.html#section-9.3.3
*/
public function post($uri, $params)
{
$this->makeRequest("POST", $uri, $params);
}

/**
* Make PUT request
*
* @param string $uri
* @param array|string $params
* @return void
*
* @url https://www.rfc-editor.org/rfc/rfc9110.html#section-9.3.4
*/
public function put(string $uri, string|array $params): void
{
$this->makeRequest("PUT", $uri, $params);
}

/**
* Make DELETE request
*
* @param string $uri
* @param array|string $params
* @return void
*
* @url https://www.rfc-editor.org/rfc/rfc9110.html#section-9.3.5
*/
public function delete(string $uri, array|string $params = []): void
{
$this->makeRequest("DELETE", $uri, $params);
}

/**
* Make PATCH request
*
* @param string $uri
* @param array|string $params
* @return void
*
* @url https://www.rfc-editor.org/info/rfc5789
*/
public function patch(string $uri, array|string $params): void
{
$this->makeRequest("PATCH", $uri, $params);
}

/**
* Make OPTIONS request
*
* @param string $uri
* @param array|string $params
* @return void
*
* @url https://www.rfc-editor.org/rfc/rfc9110.html#section-9.3.7
*/
public function options(string $uri, array|string $params = []): void
{
$this->makeRequest("OPTIONS", $uri, $params);
}

/**
* Make HEAD request
*
* @param string $uri
* @return void
*
* @url https://www.rfc-editor.org/rfc/rfc9110.html#section-9.3.2
*/
public function head(string $uri): void
{
$this->makeRequest("HEAD", $uri);
}

/**
* Make TRACE request
*
* @param string $uri
* @return void
*
* @url https://www.rfc-editor.org/rfc/rfc9110.html#section-9.3.8
*/
public function trace(string $uri): void
{
$this->makeRequest("TRACE", $uri);
}

/**
* Make CONNECT request
*
* @param string $uri
* @return void
*
* @url https://www.rfc-editor.org/rfc/rfc9110.html#section-9.3.6
*/
public function connect(string $uri): void
{
$this->makeRequest("CONNECT", $uri);
}

/**
* Get response headers
*
Expand Down