php-geckoboard-api
php-geckoboard-api copied to clipboard
Plans to upgrade Guzzle from 3 to 6?
Hi,
Is there any plans on upgrading this library from Guzzle 3 to Guzzle 6?
Guzzle 3 is very very old and will from my experience not work (at all) with PHP versions newer than 7.0. And the lifetime of PHP 7.0 is coming to it's end quite soon: http://php.net/supported-versions.php
This lib is also the most downloaded geckoboard library on packagist, so it's probably worth upgrading it to work with supported versions of PHP (as of december): https://packagist.org/?query=geckoboard
Unless the project is abandoned, but I don't see any mentions of that (as in huge titles on top of the readme or so).
Confirmed it can not be used in Magento 2.3.1 as this version requires symfony/event-dispatcher 4.1.* whereas guzzle/guzzle requires ~2.1.
I think it's necessary to upgrade to guzzlehttp/guzzle.
Hey @kozie,
To get around this issue I'm running this lib on a private fork for our internal projects at work.
But this is the only patch that is needed:
diff --git a/src/CarlosIO/Geckoboard/Client.php b/src/CarlosIO/Geckoboard/Client.php
index 378cd4a..120e27a 100644
--- a/src/CarlosIO/Geckoboard/Client.php
+++ b/src/CarlosIO/Geckoboard/Client.php
@@ -2,7 +2,8 @@
namespace CarlosIO\Geckoboard;
-use Guzzle\Http\Client as Guzzle;
+use GuzzleHttp\Client as HttpClient;
+use GuzzleHttp\RequestOptions;
use CarlosIO\Geckoboard\Widgets\Widget;
/**
@@ -13,9 +14,9 @@ class Client
const URI = 'https://push.geckoboard.com';
/**
- * @var \Guzzle\Http\Client
+ * @var HttpClient
*/
- protected $client;
+ protected $httpClient;
/**
* @var string
@@ -28,17 +29,19 @@ class Client
public function __construct()
{
$this->api = '';
- $this->client = new Guzzle(self::URI);
+ $this->httpClient = new HttpClient([
+ 'base_uri' => self::URI,
+ ]);
}
/**
- * @param array|\Guzzle\Common\Collection $config
+ * @param array $config
*
* @return Client $this
*/
- public function setGuzzleConfig($config)
+ public function setGuzzleConfig(array $config)
{
- $this->client->setConfig($config);
+ $this->httpClient = new HttpClient($config);
return $this;
}
@@ -46,11 +49,11 @@ public function setGuzzleConfig($config)
/**
* @param string|bool $key
*
- * @return \Guzzle\Common\Collection|mixed
+ * @return mixed
*/
public function getGuzzleConfig($key = false)
{
- return $this->client->getConfig($key);
+ return $this->httpClient->getConfig($key);
}
/**
@@ -123,14 +126,14 @@ private function pushWidgets($widgets)
*/
private function pushWidget(Widget $widget)
{
- $this->client->post(
+ $this->httpClient->post(
'/v1/send/'.$widget->getId(),
- null,
- json_encode(
- array(
+ [
+ RequestOptions::JSON => [
'api_key' => $this->getApiKey(),
'data' => $widget->getData(),
- )
- ))->send();
+ ]
+ ]
+ );
}
}
Plus obviously changing the composer.json to depend on a newer guzzle (I'm running it on guzzle 6.3.3).
This change also broke a test but yeah, for a monkeypatch I didn't care to much about that.
Awesome, @etu !
Thanks for sorting out and sharing the patch! :)