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

Remove Zend for Magento 2.4.6 #362

Merged
merged 1 commit into from
Jul 12, 2023
Merged

Conversation

rangerz
Copy link
Contributor

@rangerz rangerz commented Jun 2, 2023

Context

Because #358 and #360 still not update.

Description

  • Use Magento\Framework\HTTP\LaminasClient (Magento 2.4.6 and above) to replace Zend_Http_Client
  • In my dev env, set the adapter to Laminas\Http\Client\Adapter\Socket is necessary, and the default adapter is Magento\Framework\HTTP\Adapter\Curl that is missing pass some header (include Authorization). So I got the 401 for Unauthorized
# My test code for debug
$om = \Magento\Framework\App\ObjectManager::getInstance();
$clientFactory = $om->get(\Magento\Framework\HTTP\LaminasClientFactory::class);
$client = $clientFactory->create();

$method = 'POST';
$apiKey = 'fake_key';
$url = 'https://httpbin.org/post';
$data = [
  'city' => 'Irving',
  'country' => 'US',
  'state' => 'TX',
  'street' => '101 No Steet',
  'zip' => '77777',
];

$client->setUri($url);
$client->setMethod($method);
$client->setHeaders([
    'Authorization' => 'Bearer ' . $apiKey,
    'x-api-version' => 'FAKE_VERSION',
    'Referer' => 'https://www.taxjar.com/'
]);
$client->setOptions([
  'timeout' => 30,
  'useragent' => 'my UA'
]);
$client->setRawBody(json_encode($data));
$client->setEncType('application/json');

echo $client->send();

$output = <<<OUTPUT
{
  "args": {},
  "data": "",
  "files": {},
  "form": {
    "{\"city\":\"Irving\",\"country\":\"US\",\"state\":\"TX\",\"street\":\"101 No Steet\",\"zip\":\"77777\"}": ""
  },
  "headers": {
    "Accept": "*/*",
    "Content-Length": "83",
    "Content-Type": "application/x-www-form-urlencoded",
    "Host": "httpbin.org",
    "Https": "//www.taxjar.com/",
    "User-Agent": "my UA",
    "X-Amzn-Trace-Id": "Root=1-647a40aa-44948c4f575e30814c965143"
  },
  "json": null,
  "origin": "MY_IP_ADDRESS",
  "url": "https://httpbin.org/post"
}
OUTPUT;

# Set Adapter for Authorization header
$client->setAdapter(\Laminas\Http\Client\Adapter\Socket::class);
echo $client->send();

$output = <<<OUTPUT
{
  "args": {},
  "data": "{\"city\":\"Irving\",\"country\":\"US\",\"state\":\"TX\",\"street\":\"101 No Steet\",\"zip\":\"77777\"}",
  "files": {},
  "form": {},
  "headers": {
    "Accept-Encoding": "gzip, deflate",
    "Authorization": "Bearer fake_key",
    "Content-Length": "83",
    "Content-Type": "application/json",
    "Host": "httpbin.org",
    "Referer": "https://www.taxjar.com/",
    "User-Agent": "my UA",
    "X-Amzn-Trace-Id": "Root=1-647a40c7-346b48df0919db53041d4158",
    "X-Api-Version": "FAKE_VERSION"
  },
  "json": {
    "city": "Irving",
    "country": "US",
    "state": "TX",
    "street": "101 No Steet",
    "zip": "77777"
  },
  "origin": "MY_IP_ADDRESS",
  "url": "https://httpbin.org/post"
}
OUTPUT;
  • BTW, the best practice is using Magento\Framework\HTTP\ClientInterface, but it does not provide PUT and DELETE method interfaces. 🙁

Performance

N/A

Testing

N/A

Versions

  • Magento 2.4.6
  • Magento 2.3
  • Magento Open Source (formerly Magento 2 Community Edition)
  • Adobe Commerce (formerly Magento 2 Enterprise Edition)
  • PHP 8.2
  • PHP 8.1
  • PHP 7.4
  • PHP 7.3

@CLAassistant
Copy link

CLAassistant commented Jun 2, 2023

CLA assistant check
All committers have signed the CLA.

@rangerz rangerz mentioned this pull request Jun 2, 2023
Copy link
Contributor

@smolentzov-stripe smolentzov-stripe left a comment

Choose a reason for hiding this comment

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

@rangerz thank you so much for submitting this!
Click-tested locally with 2.4.6 and it looks good. Moving ahead with submitting this.

@rangerz
Copy link
Contributor Author

rangerz commented Jul 17, 2023

@smolentzov-stripe
This pull request only works for Magento 2.4.6 and above.

You should not directly use it and update the module version to release.

ex: Use Magento 2.4.4 to install taxjar/module-taxjar:2.2.0 will fail to get the error message by bin/magento setup:di:compile

Area configuration aggregation... 5/9 [===============>------------]  55% 1 min 466.0 MiB
In ClassReader.php line 57:

  Impossible to process constructor argument Parameter #5 [ <required> Magento\Framework\HTTP\LaminasClientFactory $clien
  tFactory ] of Taxjar\SalesTax\Model\Smartcalcs class


In GetParameterClassTrait.php line 34:

  Class "Magento\Framework\HTTP\LaminasClientFactory" does not exist

@damienwebdev
Copy link

This PR should have caused a major version bump to v3 as well as a modification to the composer.json. The breaks older installs of v2.4.4.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants