Skip to content

Commit 1e46eec

Browse files
authored
Merge pull request #7795 from magento-atwix-pyrrans/AC-5889
[Pyrrans] AC-5889 replaced Zend_HTTP with laminas-http
2 parents bddae56 + 50e7536 commit 1e46eec

File tree

55 files changed

+828
-582
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+828
-582
lines changed

app/code/Magento/AdminNotification/Model/Feed.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
namespace Magento\AdminNotification\Model;
77

8+
use Laminas\Http\Request;
89
use Magento\AdminNotification\Model\InboxFactory;
910
use Magento\Backend\App\ConfigInterface;
1011
use Magento\Framework\App\DeploymentConfig;
@@ -227,7 +228,7 @@ public function getFeedData()
227228
{
228229
/** @var Curl $curl */
229230
$curl = $this->curlFactory->create();
230-
$curl->setConfig(
231+
$curl->setOptions(
231232
[
232233
'timeout' => 2,
233234
'useragent' => $this->productMetadata->getName()
@@ -236,7 +237,7 @@ public function getFeedData()
236237
'referer' => $this->urlBuilder->getUrl('*/*/*')
237238
]
238239
);
239-
$curl->write(\Zend_Http_Client::GET, $this->getFeedUrl(), '1.0');
240+
$curl->write(Request::METHOD_GET, $this->getFeedUrl(), '1.0');
240241
$data = $curl->read();
241242
$data = preg_split('/^\r?$/m', $data, 2);
242243
$data = trim($data[1] ?? '');

app/code/Magento/AdminNotification/Model/System/Message/Security.php

Lines changed: 48 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,28 @@
66

77
namespace Magento\AdminNotification\Model\System\Message;
88

9+
use Laminas\Http\Request;
10+
use Laminas\Http\Response;
11+
use Magento\Backend\App\ConfigInterface;
12+
use Magento\Framework\App\CacheInterface;
13+
use Magento\Framework\App\Config\ScopeConfigInterface;
14+
use Magento\Framework\HTTP\Adapter\Curl;
15+
use Magento\Framework\HTTP\Adapter\CurlFactory;
16+
use Magento\Framework\Notification\MessageInterface;
17+
use Magento\Framework\Phrase;
918
use Magento\Store\Model\Store;
19+
use Throwable;
1020

1121
/**
1222
* @api
1323
* @since 100.0.2
1424
*/
15-
class Security implements \Magento\Framework\Notification\MessageInterface
25+
class Security implements MessageInterface
1626
{
1727
/**
1828
* Cache key for saving verification result
1929
*/
20-
const VERIFICATION_RESULT_CACHE_KEY = 'configuration_files_access_level_verification';
30+
public const VERIFICATION_RESULT_CACHE_KEY = 'configuration_files_access_level_verification';
2131

2232
/**
2333
* File path for verification
@@ -34,36 +44,36 @@ class Security implements \Magento\Framework\Notification\MessageInterface
3444
private $_verificationTimeOut = 2;
3545

3646
/**
37-
* @var \Magento\Framework\App\CacheInterface
47+
* @var CacheInterface
3848
*/
3949
protected $_cache;
4050

4151
/**
42-
* @var \Magento\Backend\App\ConfigInterface
52+
* @var ConfigInterface
4353
*/
4454
protected $_backendConfig;
4555

4656
/**
47-
* @var \Magento\Framework\App\Config\ScopeConfigInterface
57+
* @var ScopeConfigInterface
4858
*/
4959
protected $_config;
5060

5161
/**
52-
* @var \Magento\Framework\HTTP\Adapter\CurlFactory
62+
* @var CurlFactory
5363
*/
5464
protected $_curlFactory;
5565

5666
/**
57-
* @param \Magento\Framework\App\CacheInterface $cache
58-
* @param \Magento\Backend\App\ConfigInterface $backendConfig
59-
* @param \Magento\Framework\App\Config\ScopeConfigInterface $config
60-
* @param \Magento\Framework\HTTP\Adapter\CurlFactory $curlFactory
67+
* @param CacheInterface $cache
68+
* @param ConfigInterface $backendConfig
69+
* @param ScopeConfigInterface $config
70+
* @param CurlFactory $curlFactory
6171
*/
6272
public function __construct(
63-
\Magento\Framework\App\CacheInterface $cache,
64-
\Magento\Backend\App\ConfigInterface $backendConfig,
65-
\Magento\Framework\App\Config\ScopeConfigInterface $config,
66-
\Magento\Framework\HTTP\Adapter\CurlFactory $curlFactory
73+
CacheInterface $cache,
74+
ConfigInterface $backendConfig,
75+
ScopeConfigInterface $config,
76+
CurlFactory $curlFactory
6777
) {
6878
$this->_cache = $cache;
6979
$this->_backendConfig = $backendConfig;
@@ -100,12 +110,12 @@ private function _isFileAccessible()
100110
{
101111
$unsecureBaseURL = $this->_config->getValue(Store::XML_PATH_UNSECURE_BASE_URL, 'default');
102112

103-
/** @var $http \Magento\Framework\HTTP\Adapter\Curl */
113+
/** @var $http Curl */
104114
$http = $this->_curlFactory->create();
105-
$http->setConfig(['timeout' => $this->_verificationTimeOut]);
106-
$http->write(\Zend_Http_Client::POST, $unsecureBaseURL . $this->_filePath);
115+
$http->setOptions(['timeout' => $this->_verificationTimeOut]);
116+
$http->write(Request::METHOD_POST, $unsecureBaseURL . $this->_filePath);
107117
$responseBody = $http->read();
108-
$responseCode = \Zend_Http_Response::extractCode($responseBody);
118+
$responseCode = $this->extractCodeFromResponse($responseBody);
109119
$http->close();
110120

111121
return $responseCode == 200;
@@ -134,7 +144,7 @@ public function isDisplayed()
134144
/**
135145
* Retrieve message text
136146
*
137-
* @return \Magento\Framework\Phrase
147+
* @return Phrase
138148
*/
139149
public function getText()
140150
{
@@ -151,6 +161,24 @@ public function getText()
151161
*/
152162
public function getSeverity()
153163
{
154-
return \Magento\Framework\Notification\MessageInterface::SEVERITY_CRITICAL;
164+
return MessageInterface::SEVERITY_CRITICAL;
165+
}
166+
167+
/**
168+
* Extract the response code from a response string
169+
*
170+
* @param string $responseString
171+
*
172+
* @return false|int
173+
*/
174+
private function extractCodeFromResponse(string $responseString)
175+
{
176+
try {
177+
$responseCode = Response::fromString($responseString)->getStatusCode();
178+
} catch (Throwable $e) {
179+
$responseCode = false;
180+
}
181+
182+
return $responseCode;
155183
}
156184
}

app/code/Magento/AdminNotification/Test/Unit/Model/FeedTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ public function testCheckUpdate(bool $callInbox, string $curlRequest): void
173173
$this->curlFactory
174174
->method('create')
175175
->willReturn($this->curl);
176-
$this->curl->expects($this->once())->method('setConfig')->with($configValues)->willReturnSelf();
176+
$this->curl->expects($this->once())->method('setOptions')->with($configValues)->willReturnSelf();
177177
$this->curl->expects($this->once())->method('read')->willReturn($curlRequest);
178178
$this->backendConfig->expects($this->once())->method('isSetFlag')->willReturn(false);
179179
$this->backendConfig

app/code/Magento/Analytics/Model/Connector/Http/Client/Curl.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
namespace Magento\Analytics\Model\Connector\Http\Client;
77

8+
use Laminas\Http\Response;
89
use Magento\Analytics\Model\Connector\Http\ConverterInterface;
910
use Psr\Log\LoggerInterface;
1011
use Magento\Framework\HTTP\Adapter\CurlFactory;
@@ -56,11 +57,12 @@ public function __construct(
5657
}
5758

5859
/**
59-
* {@inheritdoc}
60+
* @inheritdoc
6061
*/
6162
public function request($method, $url, array $body = [], array $headers = [], $version = '1.1')
6263
{
63-
$response = new \Zend_Http_Response(0, []);
64+
$response = new Response();
65+
$response->setCustomStatusCode(Response::STATUS_CODE_CUSTOM);
6466

6567
try {
6668
$curl = $this->curlFactory->create();
@@ -93,6 +95,8 @@ public function request($method, $url, array $body = [], array $headers = [], $v
9395
}
9496

9597
/**
98+
* Apply content type header from converter
99+
*
96100
* @param array $headers
97101
*
98102
* @return array

app/code/Magento/Analytics/Model/Connector/Http/ClientInterface.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55
*/
66
namespace Magento\Analytics\Model\Connector\Http;
77

8+
use Laminas\Http\Response;
9+
810
/**
911
* An interface for an HTTP client.
1012
*
11-
* Sends requests via a proper adapter.
13+
* Send requests via a proper adapter.
1214
*/
1315
interface ClientInterface
1416
{
@@ -23,7 +25,7 @@ interface ClientInterface
2325
* @param array $headers
2426
* @param string $version
2527
*
26-
* @return \Zend_Http_Response
28+
* @return Response
2729
*/
2830
public function request($method, $url, array $body = [], array $headers = [], $version = '1.1');
2931
}

app/code/Magento/Analytics/Model/Connector/Http/ResponseResolver.php

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*/
66
namespace Magento\Analytics\Model\Connector\Http;
77

8+
use Laminas\Http\Response;
9+
810
/**
911
* Extract result from http response. Call response handler by status.
1012
*/
@@ -13,12 +15,12 @@ class ResponseResolver
1315
/**
1416
* @var ConverterInterface
1517
*/
16-
private $converter;
18+
private ConverterInterface $converter;
1719

1820
/**
1921
* @var array
2022
*/
21-
private $responseHandlers;
23+
private array $responseHandlers;
2224

2325
/**
2426
* @param ConverterInterface $converter
@@ -33,24 +35,27 @@ public function __construct(ConverterInterface $converter, array $responseHandle
3335
/**
3436
* Get result from $response.
3537
*
36-
* @param \Zend_Http_Response $response
38+
* @param Response $response
3739
* @return bool|string
3840
*/
39-
public function getResult(\Zend_Http_Response $response)
41+
public function getResult(Response $response)
4042
{
4143
$result = false;
4244
$converterMediaType = $this->converter->getContentMediaType();
4345

4446
/** Content-Type header may not only contain media-type declaration */
45-
if ($response->getBody()
46-
&& is_int(strripos($response->getHeader('Content-Type'), (string) $converterMediaType))) {
47-
$responseBody = $this->converter->fromBody($response->getBody());
47+
$responseBody = $response->getBody();
48+
$contentType = $response->getHeaders()->has('Content-Type') ?
49+
$response->getHeaders()->get('Content-Type')->getFieldValue() :
50+
'';
51+
if ($responseBody && is_int(strripos($contentType, $converterMediaType))) {
52+
$responseBody = $this->converter->fromBody($responseBody);
4853
} else {
4954
$responseBody = [];
5055
}
5156

52-
if (array_key_exists($response->getStatus(), $this->responseHandlers)) {
53-
$result = $this->responseHandlers[$response->getStatus()]->handleResponse($responseBody);
57+
if (array_key_exists($response->getStatusCode(), $this->responseHandlers)) {
58+
$result = $this->responseHandlers[$response->getStatusCode()]->handleResponse($responseBody);
5459
}
5560

5661
return $result;

app/code/Magento/Analytics/Model/Connector/NotifyDataChangedCommand.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
*/
66
namespace Magento\Analytics\Model\Connector;
77

8+
use Laminas\Http\Request;
89
use Magento\Analytics\Model\AnalyticsToken;
10+
use Magento\Analytics\Model\Connector\Http\ResponseResolver;
911
use Magento\Framework\App\Config\ScopeConfigInterface;
10-
use Magento\Framework\HTTP\ZendClient;
11-
use Psr\Log\LoggerInterface;
1212
use Magento\Store\Model\Store;
13-
use Magento\Analytics\Model\Connector\Http\ResponseResolver;
13+
use Psr\Log\LoggerInterface;
1414

1515
/**
1616
* Command notifies MBI about that data collection was finished.
@@ -79,7 +79,7 @@ public function execute()
7979
$result = false;
8080
if ($this->analyticsToken->isTokenExist()) {
8181
$response = $this->httpClient->request(
82-
ZendClient::POST,
82+
Request::METHOD_POST,
8383
$this->config->getValue($this->notifyDataChangedUrlPath),
8484
[
8585
"access-token" => $this->analyticsToken->getToken(),

app/code/Magento/Analytics/Model/Connector/OTPRequest.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
*/
66
namespace Magento\Analytics\Model\Connector;
77

8+
use Laminas\Http\Request;
89
use Magento\Analytics\Model\AnalyticsToken;
910
use Magento\Analytics\Model\Connector\Http\ResponseResolver;
1011
use Magento\Framework\App\Config\ScopeConfigInterface;
11-
use Magento\Framework\HTTP\ZendClient;
1212
use Magento\Store\Model\Store;
1313
use Psr\Log\LoggerInterface;
1414

@@ -91,7 +91,7 @@ public function call()
9191

9292
if ($this->analyticsToken->isTokenExist()) {
9393
$response = $this->httpClient->request(
94-
ZendClient::POST,
94+
Request::METHOD_POST,
9595
$this->config->getValue($this->otpUrlConfigPath),
9696
[
9797
"access-token" => $this->analyticsToken->getToken(),
@@ -105,7 +105,9 @@ public function call()
105105
sprintf(
106106
'Obtaining of an OTP from the MBI service has been failed: %s. Content-Type: %s',
107107
!empty($response->getBody()) ? $response->getBody() : 'Response body is empty',
108-
$response->getHeader('Content-Type')
108+
$response->getHeaders()->has('Content-Type') ?
109+
$response->getHeaders()->get('Content-Type')->getFieldValue() :
110+
''
109111
)
110112
);
111113
}

app/code/Magento/Analytics/Model/Connector/SignUpCommand.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
*/
66
namespace Magento\Analytics\Model\Connector;
77

8+
use Laminas\Http\Request;
89
use Magento\Analytics\Model\AnalyticsToken;
910
use Magento\Analytics\Model\Connector\Http\ResponseResolver;
1011
use Magento\Analytics\Model\IntegrationManager;
1112
use Magento\Framework\App\Config\ScopeConfigInterface;
12-
use Psr\Log\LoggerInterface;
13-
use Magento\Framework\HTTP\ZendClient;
1413
use Magento\Store\Model\Store;
14+
use Psr\Log\LoggerInterface;
1515

1616
/**
1717
* SignUp merchant for Free Tier project
@@ -98,7 +98,7 @@ public function execute()
9898
if ($integrationToken) {
9999
$this->integrationManager->activateIntegration();
100100
$response = $this->httpClient->request(
101-
ZendClient::POST,
101+
Request::METHOD_POST,
102102
$this->config->getValue($this->signUpUrlPath),
103103
[
104104
"token" => $integrationToken->getData('token'),
@@ -113,7 +113,9 @@ public function execute()
113113
'Subscription for MBI service has been failed. An error occurred during token exchange: %s.'
114114
. ' Content-Type: %s',
115115
!empty($response->getBody()) ? $response->getBody() : 'Response body is empty',
116-
$response->getHeader('Content-Type')
116+
$response->getHeaders()->has('Content-Type') ?
117+
$response->getHeaders()->get('Content-Type')->getFieldValue() :
118+
''
117119
)
118120
);
119121
}

0 commit comments

Comments
 (0)