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

Add missing REST methods to Curl Client (SwiftOtter's SOP-348) #39330

Open
wants to merge 9 commits into
base: 2.4-develop
Choose a base branch
from
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,15 +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::delete() when you want to use delete method
*/
class Curl extends CurlLibrary
{
/**
Expand All @@ -19,12 +22,13 @@ class Curl extends CurlLibrary
* This feature was added base on Community Pull Request https://github.com/magento/magento2/pull/8373
*
* @param string $uri
* @param array|string $params
* @return void
*
* @see \Magento\Framework\HTTP\Client#post($uri, $params)
*/
public function delete($uri)
public function delete(string $uri, array|string $params = [])
{
$this->makeRequest("DELETE", $uri);
$this->makeRequest("DELETE", $uri, $params);
}
}
89 changes: 85 additions & 4 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 <[email protected]>
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
* @api
*/
Expand Down Expand Up @@ -246,6 +244,89 @@ public function post($uri, $params)
$this->makeRequest("POST", $uri, $params);
}

/**
* Make PUT request
*
* @param string $uri
* @param array|string $params
* @return void
*/
public function put($uri, $params)
{
$this->makeRequest("PUT", $uri, $params);
}

/**
* Make DELETE request
*
* @param string $uri
* @param array|string $params
* @return void
*/
public function delete(string $uri, array|string $params = [])
{
$this->makeRequest("DELETE", $uri, $params);
}

/**
* Make PATCH request
*
* @param string $uri
* @param array|string $params
* @return void
*/
public function patch($uri, $params)
{
$this->makeRequest("PATCH", $uri, $params);
}

/**
* Make OPTIONS request
*
* @param string $uri
* @param array|string $params
* @return void
*/
public function options(string $uri, array|string $params = [])
{
$this->makeRequest("OPTIONS", $uri, $params);
}

/**
* Make HEAD request
*
* @param string $uri
* @param array|string $params
* @return void
*/
public function head(string $uri, array|string $params = [])
{
$this->makeRequest("HEAD", $uri, $params);
}

/**
* Make TRACE request
*
* @param string $uri
* @return void
*/
public function trace(string $uri)
{
$this->makeRequest("TRACE", $uri);
}

/**
* Make CONNECT request
*
* @param string $uri
* @param array|string $params
* @return void
*/
public function connect(string $uri, array|string $params = [])
{
$this->makeRequest("CONNECT", $uri, $params);
}

/**
* Get response headers
*
Expand Down