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

Support Guzzle7 #1860

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@
"keywords": ["google"],
"homepage": "http://developers.google.com/api-client-library/php",
"license": "Apache-2.0",
"repositories": [
{ "type": "vcs", "url": "https://github.com/jeromegamez/google-auth-library-php"}
],
"require": {
"php": ">=5.4",
"google/auth": "^1.9",
"google/auth": "dev-guzzle7 as 1.10",
Copy link
Contributor

Choose a reason for hiding this comment

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

need to fix this before merging.

"google/apiclient-services": "~0.13",
"firebase/php-jwt": "~2.0||~3.0||~4.0||~5.0",
"monolog/monolog": "^1.17|^2.0",
"phpseclib/phpseclib": "~0.3.10||~2.0",
"guzzlehttp/guzzle": "~5.3.1||~6.0",
"guzzlehttp/guzzle": "~5.3.1||~6.0||~7.0",
"guzzlehttp/psr7": "^1.2"
},
"require-dev": {
Expand Down
14 changes: 10 additions & 4 deletions src/Google/AuthHandler/AuthHandlerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,18 @@ class Google_AuthHandler_AuthHandlerFactory
*/
public static function build($cache = null, array $cacheConfig = [])
{
$version = ClientInterface::VERSION;
$guzzleVersion = null;
if (defined('\GuzzleHttp\ClientInterface::MAJOR_VERSION')) {
$guzzleVersion = ClientInterface::MAJOR_VERSION;
} elseif (defined('\GuzzleHttp\ClientInterface::VERSION')) {
$guzzleVersion = (int) substr(ClientInterface::VERSION, 0, 1);
}

switch ($version[0]) {
case '5':
switch ($guzzleVersion) {
case 5:
return new Google_AuthHandler_Guzzle5AuthHandler($cache, $cacheConfig);
case '6':
case 6:
case 7:
return new Google_AuthHandler_Guzzle6AuthHandler($cache, $cacheConfig);
default:
throw new Exception('Version not supported');
Expand Down
2 changes: 1 addition & 1 deletion src/Google/AuthHandler/Guzzle6AuthHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use Psr\Cache\CacheItemPoolInterface;

/**
*
* This supports both Guzzle 6 and 7.
*/
class Google_AuthHandler_Guzzle6AuthHandler
{
Expand Down
19 changes: 13 additions & 6 deletions src/Google/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -1124,22 +1124,29 @@ public function setApiFormatV2($value)

protected function createDefaultHttpClient()
{
$options = ['exceptions' => false];
$guzzleVersion = null;
if (defined('\GuzzleHttp\ClientInterface::MAJOR_VERSION')) {
$guzzleVersion = ClientInterface::MAJOR_VERSION;
} elseif (defined('\GuzzleHttp\ClientInterface::VERSION')) {
$guzzleVersion = (int)substr(ClientInterface::VERSION, 0, 1);
}

$version = ClientInterface::VERSION;
if ('5' === $version[0]) {
$options = ['exceptions' => false];
if (5 === $guzzleVersion) {
$options = [
'base_url' => $this->config['base_path'],
'defaults' => $options,
];
if ($this->isAppEngine()) {
// set StreamHandler on AppEngine by default
$options['handler'] = new StreamHandler();
$options['handler'] = new StreamHandler();
$options['defaults']['verify'] = '/etc/ca-certificates.crt';
}
} else {
// guzzle 6
} elseif (6 === $guzzleVersion || 7 === $guzzleVersion) {
// guzzle 6 or 7
$options['base_uri'] = $this->config['base_path'];
} else {
throw new LogicException('Could not find supported version of Guzzle.');
}

return new Client($options);
Expand Down
18 changes: 17 additions & 1 deletion tests/BaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ private function createClient()
}

// adjust constructor depending on guzzle version
if (!$this->isGuzzle6()) {
if ($this->isGuzzle5()) {
$options = ['defaults' => $options];
}

Expand Down Expand Up @@ -208,15 +208,31 @@ protected function loadExample($example)
return false;
}

protected function isGuzzle7()
{
if (!defined('\GuzzleHttp\ClientInterface::MAJOR_VERSION')) {
return false;
}

return (7 === ClientInterface::MAJOR_VERSION);
}

protected function isGuzzle6()
{
if (!defined('\GuzzleHttp\ClientInterface::VERSION')) {
return false;
}
$version = ClientInterface::VERSION;

return ('6' === $version[0]);
}

protected function isGuzzle5()
{
if (!defined('\GuzzleHttp\ClientInterface::VERSION')) {
return false;
}

$version = ClientInterface::VERSION;

return ('5' === $version[0]);
Expand Down
4 changes: 2 additions & 2 deletions tests/Google/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function testSignAppKey()

private function checkAuthHandler($http, $className)
{
if ($this->isGuzzle6()) {
if ($this->isGuzzle6() || $this->isGuzzle7()) {
$stack = $http->getConfig('handler');
$class = new ReflectionClass(get_class($stack));
$property = $class->getProperty('stack');
Expand Down Expand Up @@ -75,7 +75,7 @@ private function checkAuthHandler($http, $className)

private function checkCredentials($http, $fetcherClass, $sub = null)
{
if ($this->isGuzzle6()) {
if ($this->isGuzzle6() || $this->isGuzzle7()) {
$stack = $http->getConfig('handler');
$class = new ReflectionClass(get_class($stack));
$property = $class->getProperty('stack');
Expand Down