Working with different guzzlehttp in OpenCart 3.0.3.6 and Journal 3.1.4
I would like to share with you my workaround of getting different version of guzzlehttp/guzzle working in OpenCart 3.0.3.6 and Journal 3.1.4 .
After installed OpenCart 3.0.3.6 and Journal 3.1.4, I just realized that default OpenCart guzzlehttp/guzzle version 5.3.4 was superseded by Journal 3 guzzlehttp/guzzle version 6.5.4.
This can be checked by following command:
grep -A 2 -i 'guzzlehttp/guzzle' /var/www/html/opencart/system/library/journal3/vendor-composer/composer/installed.json
"name": "guzzlehttp/guzzle",
"version": "6.5.4",
"version_normalized": "6.5.4.0",
grep -A 2 -i 'guzzlehttp/guzzle' /var/www/html/opencart_storage/vendor/composer/installed.json
"name": "guzzlehttp/guzzle",
"version": "5.3.4",
"version_normalized": "5.3.4.0",
Unfortunately, I'd a private extension which required guzzlehttp/guzzle version 5.x, following PHP error occurs after runs this extension:
sudo tail -f /var/log/php-fpm/www-error.log
PHP Fatal error: Uncaught TypeError: Argument 1 passed to GuzzleHttp\Client::send() must be an instance of Psr\Http\Message\RequestInterface, instance of GuzzleHttp\Message\Request given, called in /var/www/html/opencart/system/library/privateextension/api.php on line 413 and defined in /var/www/html/opencart/system/library/journal3/vendor-composer/guzzlehttp/guzzle/src/Client.php:126
According to https://github.com/guzzle/guzzle/blob/m ... GRADING.md
5.0 to 6.0
Guzzle now uses PSR-7 for HTTP messages. Due to the fact that these messages are immutable, this prompted a refactoring of Guzzle to use a
middleware based system rather than an event system. Any HTTP message interaction (e.g., GuzzleHttp\Message\Request) need to be updated to
work with the new immutable PSR-7 request and response objects.
To get this private extension works with guzzlehttp/guzzle version 6.x, this will need major coding modification, and the bad news is 3rd party developer no longer support this . So, this rack my brain to think off how to get both guzzlehttp/guzzle version 5.x and 6.x co-exist.
After some research, the nearest solution I found was this article https://stackoverflow.com/questions/271 ... e/27153452
However, this solution was complicated for me, and I'm afraid other unforeseen problem may arise.
After some study, I realized that the most straight forward method to distinguish guzzlehttp/guzzle version 5.x from 6.x is changing the namespace.
So, I came out the idea of manually update OpenCart 3.0.3.6 Guzzle namespace from "GuzzleHttp\Guzzle" to "GuzzleHttp5\Guzzle". At this point, I am sure that only this private extension will use it but no other.
Following the steps I'd taken for this modification.
# Step1: Replace string "GuzzleHttp" to "GuzzleHttp5" for all files under folder opencart_storage/vendor/*
# Go to the opencart storage/vendor directory. e.g.
cd /var/www/html/opencart_storage/vendor
# Make a backup of directory vendor
sudo cp -pr vendor vendor_backup
# Check number of string cotains "GuzzleHttp".
grep -r GuzzleHttp . | wc -l
824
# Check number of file contains string "GuzzleHttp".
grep -rl GuzzleHttp . | wc -l
198
# Replace string "GuzzleHttp" to "GuzzleHttp5" for all files.
sudo grep -rl GuzzleHttp . | sudo xargs sed -i 's/GuzzleHttp/GuzzleHttp5/g'
# Check number of string cotains "GuzzleHttp5".
grep -r GuzzleHttp5 . | wc -l
824
# Check number of file contains string "GuzzleHttp5".
grep -rl GuzzleHttp5 . | wc -l
198
# Step2: Replace string "GuzzleHttp" to "GuzzleHttp5" in system/library/privateextension/api.php
sudo vi /var/www/html/opencart/system/library/privateextension/api.php
use GuzzleHttp\Client; -> use GuzzleHttp5\Client;
use GuzzleHttp\Exception\BadResponseException; -> use GuzzleHttp5\Exception\BadResponseException;
use GuzzleHttp\Exception\ClientException; -> use GuzzleHttp5\Exception\ClientException;
use GuzzleHttp\Message\Request; -> use GuzzleHttp5\Message\Request;
use GuzzleHttp\Message\Response; -> use GuzzleHttp5\Message\Response;
use GuzzleHttp\Message\ResponseInterface; -> use GuzzleHttp5\Message\ResponseInterface;
use GuzzleHttp\Stream\Stream; -> use GuzzleHttp5\Stream\Stream;
use GuzzleHttp\Subscriber\HttpError; -> use GuzzleHttp5\Subscriber\HttpError;
Surprisingly, this private extension is working well after above workaround applied. I understood that this violate the structure of the underlying system library. Anyhow, just share with you my thought that proved working on my opencart/journal system.
Unsupported.
Dedication and passion goes to those who are able to push and merge a project.
Regards,
Straightlight
Programmer / Opencart Tester
He didn't ask for any help but he shared what could be a workaround when there are different versions being called!
when their is this issue major error could appear as
when their is this issue major error could appear as
Code: Select all
PHP Fatal error: Uncaught Error: Call to undefined function GuzzleHttp\_idn_uri_convert() in /home/public_html/system/library/myextension/vendor/guzzlehttp/guzzle/src/Client.php:220
Urgent Questions shoot here: khnaz35@gmail.com
Enjoy nature
Who is online
Users browsing this forum: No registered users and 69 guests