Skip to content

Commit

Permalink
Merge pull request #3 from anju-fingent/master
Browse files Browse the repository at this point in the history
Zend dependency for magento till 2.4.3
  • Loading branch information
SreedarshA authored Jun 22, 2023
2 parents 08bea5e + 4fd6603 commit 1c18ab1
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 41 deletions.
12 changes: 6 additions & 6 deletions Gateway/Http/Client/Adapter/Rest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
namespace Mastercard\Mastercard\Gateway\Http\Client\Adapter;

use Magento\Framework\HTTP\Adapter\Curl;
use Laminas\Http\Client;
use Zend_Http_Client;
use Zend_Uri_Exception;
use Laminas\Uri\Http;
use Zend_Uri_Http;

class Rest extends Curl
{
Expand All @@ -47,15 +47,15 @@ public function write($method, $url, $httpVer = '1.1', $headers = [], $body = ''
curl_setopt($this->_getResource(), CURLOPT_URL, $url);
curl_setopt($this->_getResource(), CURLOPT_RETURNTRANSFER, true);

if ($method == \Laminas\Http\Request::METHOD_POST) {
if ($method == Zend_Http_Client::POST) {
curl_setopt($this->_getResource(), CURLOPT_POST, true);
curl_setopt($this->_getResource(), CURLOPT_POSTFIELDS, $body);
$headers[] = 'Content-Length: ' . strlen($body);
} elseif ($method == \Laminas\Http\Request::METHOD_PUT) {
curl_setopt($this->_getResource(), CURLOPT_CUSTOMREQUEST, \Laminas\Http\Request::METHOD_PUT);
} elseif ($method == Zend_Http_Client::PUT) {
curl_setopt($this->_getResource(), CURLOPT_CUSTOMREQUEST, Zend_Http_Client::PUT);
curl_setopt($this->_getResource(), CURLOPT_POSTFIELDS, $body);
$headers[] = 'Content-Length: ' . strlen($body);
} elseif ($method == \Laminas\Http\Request::METHOD_GET) {
} elseif ($method == Zend_Http_Client::GET) {
curl_setopt($this->_getResource(), CURLOPT_HTTPGET, true);
}

Expand Down
4 changes: 2 additions & 2 deletions Gateway/Http/Client/ResponseFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

namespace Mastercard\Mastercard\Gateway\Http\Client;

use Laminas\Http\Response;
use Zend_Http_Response;

class ResponseFactory
{
Expand All @@ -29,6 +29,6 @@ class ResponseFactory
*/
public function create($response)
{
return Response::fromString($response);
return Zend_Http_Response::fromString($response);
}
}
41 changes: 10 additions & 31 deletions Gateway/Http/Client/Rest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
use Magento\Payment\Gateway\Http\ConverterInterface;
use Magento\Payment\Gateway\Http\TransferInterface;
use Magento\Payment\Model\Method\Logger;
use Laminas\Http\Client;
use Laminas\Uri\Http;
use Zend_Http_Client_Adapter_Interface;

class Rest implements ClientInterface
{
Expand Down Expand Up @@ -69,7 +68,7 @@ class Rest implements ClientInterface
private $responseFactory;

/**
* @var AdapterInterface
* @var Zend_Http_Client_Adapter_Interface
*/
private $adapter;

Expand All @@ -78,33 +77,25 @@ class Rest implements ClientInterface
*/
private $json;

/**
* @var Http
*/
private $http;

/**
* @param Logger $logger
* @param ConverterInterface $converter
* @param ResponseFactory $responseFactory
* @param AdapterInterface $adapter
* @param Zend_Http_Client_Adapter_Interface $adapter
* @param Json $json
* @param Http $http
*/
public function __construct(
Logger $logger,
ConverterInterface $converter,
ResponseFactory $responseFactory,
Client $adapters,
Json $json,
Http $http
Zend_Http_Client_Adapter_Interface $adapter,
Json $json
) {
$this->logger = $logger;
$this->converter = $converter;
$this->responseFactory = $responseFactory;
$this->adapters = $adapters;
$this->adapter = $adapter;
$this->json = $json;
$this->http = $http;
}

/**
Expand All @@ -114,14 +105,8 @@ public function placeRequest(TransferInterface $transferObject)
{
$response = [];

$client = new Client();

// $adapter = new \Laminas\Http\Client\Adapter\Socket();
//$client = new \Laminas\Http\Client();
//$client->setAdapter($adapter);

try {
$client->setOptions(
$this->adapter->setOptions(
[CURLOPT_TIMEOUT => self::REQUEST_TIMEOUT] + $transferObject->getClientConfig()
);
$headers = [];
Expand All @@ -135,9 +120,9 @@ public function placeRequest(TransferInterface $transferObject)
'request_uri' => $transferObject->getUri(),
];

$client->write(
$this->adapter->write(
$transferObject->getMethod(),
$this->http->parse($transferObject->getUri()),
\Zend_Uri_Http::fromString($transferObject->getUri()),
self::HTTP_1,
$headers,
$this->json->serialize($transferObject->getBody())
Expand All @@ -159,12 +144,6 @@ public function placeRequest(TransferInterface $transferObject)
*/
public function read()
{

$client = new Client();

//$adapter = new \Laminas\Http\Client\Adapter\Socket();
//$client = new \Laminas\Http\Client();
//$client->setAdapter($adapter);
return $this->responseFactory->create($client->read())->getBody();
return $this->responseFactory->create($this->adapter->read())->getBody();
}
}
4 changes: 2 additions & 2 deletions Model/Feed.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
use Magento\Framework\App\CacheInterface;
use Psr\Log\LoggerInterface;
use SimpleXMLElement;
use Laminas\Http\Request;
use Zend_Http_Client;
use Exception;

class Feed
Expand Down Expand Up @@ -164,7 +164,7 @@ public function getFeedData()
]
);
$feedUrl = $this->backendConfig->getValue(self::XML_FEED_URL_PATH);
$curl->write(Request::METHOD_GET, $feedUrl, '1.0');
$curl->write(Zend_Http_Client::GET, $feedUrl, '1.0');
$data = $curl->read();
$data = preg_split('/^\r?$/m', $data, 2);
$data = trim($data[1]);
Expand Down

0 comments on commit 1c18ab1

Please sign in to comment.