Skip to content

Commit c765b37

Browse files
authored
feat: drop support for 7.3 and below (#2431)
Release-As: v2.15.0
1 parent 789c8b0 commit c765b37

25 files changed

+135
-710
lines changed

.github/sync-repo-settings.yaml

+4-7
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,12 @@ branchProtectionRules:
55
- pattern: master
66
isAdminEnforced: true
77
requiredStatusCheckContexts:
8-
- 'PHP 5.6 Unit Test'
9-
- 'PHP 5.6 --prefer-lowest Unit Test'
10-
- 'PHP 7.0 Unit Test'
11-
- 'PHP 7.1 Unit Test'
12-
- 'PHP 7.2 Unit Test'
13-
- 'PHP 7.3 Unit Test'
148
- 'PHP 7.4 Unit Test'
9+
- 'PHP 7.4 --prefer-lowest Unit Test'
1510
- 'PHP 8.0 Unit Test'
16-
- 'PHP 8.0 --prefer-lowest Unit Test'
11+
- 'PHP 8.1 Unit Test'
12+
- 'PHP 8.2 Unit Test'
13+
- 'PHP 8.2 --prefer-lowest Unit Test'
1714
- 'PHP Style Check'
1815
- 'cla/google'
1916
requiredApprovingReviewCount: 1

.github/workflows/asset-release.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
strategy:
1111
matrix:
1212
operating-system: [ ubuntu-latest ]
13-
php: [ "5.6", "7.0", "7.4", "8.0" ]
13+
php: [ "7.4", "8.0", "8.2" ]
1414

1515
name: Upload Release Assets
1616
steps:

.github/workflows/docs.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
max_attempts: 3
1919
command: composer install
2020
- name: Generate and Push Documentation
21-
uses: docker://php:7.3-cli
21+
uses: docker://php:7.4-cli
2222
env:
2323
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
2424
with:

.github/workflows/tests.yml

+6-9
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ jobs:
1111
strategy:
1212
fail-fast: false
1313
matrix:
14-
php: [ "5.6", "7.0", "7.1", "7.2", "7.3", "7.4", "8.0", "8.1", "8.2" ]
14+
php: [ "7.4", "8.0", "8.1", "8.2" ]
1515
composer-flags: [""]
1616
include:
17-
- php: "5.6"
17+
- php: "7.4"
1818
composer-flags: "--prefer-lowest "
19-
- php: "8.0"
19+
- php: "8.2"
2020
composer-flags: "--prefer-lowest "
2121
name: PHP ${{ matrix.php }} ${{ matrix.composer-flags }}Unit Test
2222
steps:
@@ -26,14 +26,11 @@ jobs:
2626
with:
2727
php-version: ${{ matrix.php }}
2828
- name: Install Dependencies
29-
uses: nick-invision/retry@v1
29+
uses: nick-invision/retry@v2
3030
with:
3131
timeout_minutes: 10
3232
max_attempts: 3
3333
command: composer update ${{ matrix.composer-flags }}
34-
- if: ${{ matrix.php == '8.0' && matrix.composer-flags == '--prefer-lowest ' }}
35-
name: Update guzzlehttp/ringphp dependency
36-
run: composer update guzzlehttp/ringphp
3734
- name: Run Script
3835
run: vendor/bin/phpunit
3936

@@ -45,9 +42,9 @@ jobs:
4542
- name: Setup PHP
4643
uses: shivammathur/setup-php@v2
4744
with:
48-
php-version: "7.3"
45+
php-version: "7.4"
4946
- name: Install Dependencies
50-
uses: nick-invision/retry@v1
47+
uses: nick-invision/retry@v2
5148
with:
5249
timeout_minutes: 10
5350
max_attempts: 3

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ For Google Cloud Platform APIs such as [Datastore][cloud-datastore], [Cloud Stor
2525
[cloud-compute]: https://github.com/googleapis/google-cloud-php-compute
2626

2727
## Requirements ##
28-
* [PHP 5.6.0 or higher](https://www.php.net/)
28+
* [PHP 7.4 or higher](https://www.php.net/)
2929

3030
## Developer Documentation ##
3131

composer.json

+9-10
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,24 @@
66
"homepage": "http://developers.google.com/api-client-library/php",
77
"license": "Apache-2.0",
88
"require": {
9-
"php": "^5.6|^7.0|^8.0",
10-
"google/auth": "^1.10",
9+
"php": "^7.4|^8.0",
10+
"google/auth": "^1.26",
1111
"google/apiclient-services": "~0.200",
12-
"firebase/php-jwt": "~2.0||~3.0||~4.0||~5.0||~6.0",
13-
"monolog/monolog": "^1.17||^2.0||^3.0",
14-
"phpseclib/phpseclib": "~2.0||^3.0.2",
15-
"guzzlehttp/guzzle": "~5.3.3||~6.0||~7.0",
12+
"firebase/php-jwt": "~6.0",
13+
"monolog/monolog": "^2.9||^3.0",
14+
"phpseclib/phpseclib": "^3.0.2",
15+
"guzzlehttp/guzzle": "~6.5||~7.0",
1616
"guzzlehttp/psr7": "^1.8.4||^2.2.1"
1717
},
1818
"require-dev": {
1919
"squizlabs/php_codesniffer": "^3.0",
2020
"symfony/dom-crawler": "~2.1",
2121
"symfony/css-selector": "~2.1",
22-
"cache/filesystem-adapter": "^0.3.2|^1.1",
22+
"cache/filesystem-adapter": "^1.1",
2323
"phpcompatibility/php-compatibility": "^9.2",
2424
"composer/composer": "^1.10.22",
25-
"yoast/phpunit-polyfills": "^1.0",
26-
"phpspec/prophecy-phpunit": "^1.1||^2.0",
27-
"phpunit/phpunit": "^5.7.21 || ^6.0 || ^7.0 || ^8.0 || ^9.0"
25+
"phpspec/prophecy-phpunit": "^2.0",
26+
"phpunit/phpunit": "^9.5"
2827
},
2928
"suggest": {
3029
"cache/filesystem-adapter": "For caching certs and tokens (using Google\\Client::setCache)"

phpstan.neon.dist

-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,3 @@ parameters:
33
level: 5
44
paths:
55
- src
6-
excludePaths:
7-
- src/AuthHandler/Guzzle5AuthHandler.php
8-

phpunit.xml.dist

+14-17
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3-
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/9.2/phpunit.xsd"
4-
colors="true"
5-
bootstrap="tests/bootstrap.php">
6-
<testsuites>
7-
<testsuite name="Google PHP Client Unit Test Suite">
8-
<directory>tests/Google</directory>
9-
</testsuite>
10-
<testsuite name="Google PHP Client Examples Test Suite">
11-
<directory>tests/examples</directory>
12-
</testsuite>
13-
</testsuites>
14-
<filter>
15-
<whitelist>
16-
<directory suffix=".php">./src</directory>
17-
</whitelist>
18-
</filter>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" colors="true" bootstrap="tests/bootstrap.php">
3+
<coverage>
4+
<include>
5+
<directory suffix=".php">./src</directory>
6+
</include>
7+
</coverage>
8+
<testsuites>
9+
<testsuite name="Google PHP Client Unit Test Suite">
10+
<directory>tests/Google</directory>
11+
</testsuite>
12+
<testsuite name="Google PHP Client Examples Test Suite">
13+
<directory>tests/examples</directory>
14+
</testsuite>
15+
</testsuites>
1916
</phpunit>

src/AccessToken/Verify.php

+19-75
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
use Exception;
2424
use ExpiredException;
2525
use Firebase\JWT\ExpiredException as ExpiredExceptionV3;
26+
use Firebase\JWT\JWT;
2627
use Firebase\JWT\Key;
2728
use Firebase\JWT\SignatureInvalidException;
2829
use Google\Auth\Cache\MemoryCacheItemPool;
@@ -31,8 +32,9 @@
3132
use GuzzleHttp\ClientInterface;
3233
use InvalidArgumentException;
3334
use LogicException;
35+
use phpseclib3\Crypt\AES;
3436
use phpseclib3\Crypt\PublicKeyLoader;
35-
use phpseclib3\Crypt\RSA\PublicKey; // Firebase v2
37+
use phpseclib3\Math\BigInteger;
3638
use Psr\Cache\CacheItemPoolInterface;
3739

3840
/**
@@ -219,101 +221,43 @@ private function getFederatedSignOnCerts()
219221

220222
private function getJwtService()
221223
{
222-
$jwtClass = 'JWT';
223-
if (class_exists('\Firebase\JWT\JWT')) {
224-
$jwtClass = 'Firebase\JWT\JWT';
225-
}
226-
227-
if (property_exists($jwtClass, 'leeway') && $jwtClass::$leeway < 1) {
224+
$jwt = new JWT();
225+
if ($jwt::$leeway < 1) {
228226
// Ensures JWT leeway is at least 1
229227
// @see https://github.com/google/google-api-php-client/issues/827
230-
$jwtClass::$leeway = 1;
228+
$jwt::$leeway = 1;
231229
}
232230

233-
// @phpstan-ignore-next-line
234-
return new $jwtClass();
231+
return $jwt;
235232
}
236233

237234
private function getPublicKey($cert)
238235
{
239-
$bigIntClass = $this->getBigIntClass();
240-
$modulus = new $bigIntClass($this->jwt->urlsafeB64Decode($cert['n']), 256);
241-
$exponent = new $bigIntClass($this->jwt->urlsafeB64Decode($cert['e']), 256);
236+
$modulus = new BigInteger($this->jwt->urlsafeB64Decode($cert['n']), 256);
237+
$exponent = new BigInteger($this->jwt->urlsafeB64Decode($cert['e']), 256);
242238
$component = ['n' => $modulus, 'e' => $exponent];
243239

244-
if (class_exists('phpseclib3\Crypt\RSA\PublicKey')) {
245-
/** @var PublicKey $loader */
246-
$loader = PublicKeyLoader::load($component);
247-
248-
return $loader->toString('PKCS8');
249-
}
250-
251-
$rsaClass = $this->getRsaClass();
252-
$rsa = new $rsaClass();
253-
$rsa->loadKey($component);
254-
255-
return $rsa->getPublicKey();
256-
}
257-
258-
private function getRsaClass()
259-
{
260-
if (class_exists('phpseclib3\Crypt\RSA')) {
261-
return 'phpseclib3\Crypt\RSA';
262-
}
263-
264-
if (class_exists('phpseclib\Crypt\RSA')) {
265-
return 'phpseclib\Crypt\RSA';
266-
}
240+
$loader = PublicKeyLoader::load($component);
267241

268-
return 'Crypt_RSA';
269-
}
270-
271-
private function getBigIntClass()
272-
{
273-
if (class_exists('phpseclib3\Math\BigInteger')) {
274-
return 'phpseclib3\Math\BigInteger';
275-
}
276-
277-
if (class_exists('phpseclib\Math\BigInteger')) {
278-
return 'phpseclib\Math\BigInteger';
279-
}
280-
281-
return 'Math_BigInteger';
282-
}
283-
284-
private function getOpenSslConstant()
285-
{
286-
if (class_exists('phpseclib3\Crypt\AES')) {
287-
return 'phpseclib3\Crypt\AES::ENGINE_OPENSSL';
288-
}
289-
290-
if (class_exists('phpseclib\Crypt\RSA')) {
291-
return 'phpseclib\Crypt\RSA::MODE_OPENSSL';
292-
}
293-
294-
if (class_exists('Crypt_RSA')) {
295-
return 'CRYPT_RSA_MODE_OPENSSL';
296-
}
297-
298-
throw new Exception('Cannot find RSA class');
242+
return $loader->toString('PKCS8');
299243
}
300244

301245
/**
302-
* phpseclib calls "phpinfo" by default, which requires special
303-
* whitelisting in the AppEngine VM environment. This function
304-
* sets constants to bypass the need for phpseclib to check phpinfo
305-
*
306-
* @see phpseclib/Math/BigInteger
307-
* @see https://github.com/GoogleCloudPlatform/getting-started-php/issues/85
308-
*/
246+
* phpseclib calls "phpinfo" by default, which requires special
247+
* whitelisting in the AppEngine VM environment. This function
248+
* sets constants to bypass the need for phpseclib to check phpinfo
249+
*
250+
* @see phpseclib/Math/BigInteger
251+
* @see https://github.com/GoogleCloudPlatform/getting-started-php/issues/85
252+
*/
309253
private function setPhpsecConstants()
310254
{
311255
if (filter_var(getenv('GAE_VM'), FILTER_VALIDATE_BOOLEAN)) {
312256
if (!defined('MATH_BIGINTEGER_OPENSSL_ENABLED')) {
313257
define('MATH_BIGINTEGER_OPENSSL_ENABLED', true);
314258
}
315259
if (!defined('CRYPT_RSA_MODE')) {
316-
define('CRYPT_RSA_MODE', constant($this->getOpenSslConstant()));
260+
define('CRYPT_RSA_MODE', AES::ENGINE_OPENSSL);
317261
}
318262
}
319263
}

src/AuthHandler/AuthHandlerFactory.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class AuthHandlerFactory
2525
/**
2626
* Builds out a default http handler for the installed version of guzzle.
2727
*
28-
* @return Guzzle5AuthHandler|Guzzle6AuthHandler|Guzzle7AuthHandler
28+
* @return Guzzle6AuthHandler|Guzzle7AuthHandler
2929
* @throws Exception
3030
*/
3131
public static function build($cache = null, array $cacheConfig = [])
@@ -38,8 +38,6 @@ public static function build($cache = null, array $cacheConfig = [])
3838
}
3939

4040
switch ($guzzleVersion) {
41-
case 5:
42-
return new Guzzle5AuthHandler($cache, $cacheConfig);
4341
case 6:
4442
return new Guzzle6AuthHandler($cache, $cacheConfig);
4543
case 7:

0 commit comments

Comments
 (0)