Skip to content

Commit

Permalink
feat: drop support for 7.3 and below (#2431)
Browse files Browse the repository at this point in the history
Release-As: v2.15.0
  • Loading branch information
bshaffer authored May 16, 2023
1 parent 789c8b0 commit c765b37
Show file tree
Hide file tree
Showing 25 changed files with 135 additions and 710 deletions.
11 changes: 4 additions & 7 deletions .github/sync-repo-settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,12 @@ branchProtectionRules:
- pattern: master
isAdminEnforced: true
requiredStatusCheckContexts:
- 'PHP 5.6 Unit Test'
- 'PHP 5.6 --prefer-lowest Unit Test'
- 'PHP 7.0 Unit Test'
- 'PHP 7.1 Unit Test'
- 'PHP 7.2 Unit Test'
- 'PHP 7.3 Unit Test'
- 'PHP 7.4 Unit Test'
- 'PHP 7.4 --prefer-lowest Unit Test'
- 'PHP 8.0 Unit Test'
- 'PHP 8.0 --prefer-lowest Unit Test'
- 'PHP 8.1 Unit Test'
- 'PHP 8.2 Unit Test'
- 'PHP 8.2 --prefer-lowest Unit Test'
- 'PHP Style Check'
- 'cla/google'
requiredApprovingReviewCount: 1
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/asset-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
strategy:
matrix:
operating-system: [ ubuntu-latest ]
php: [ "5.6", "7.0", "7.4", "8.0" ]
php: [ "7.4", "8.0", "8.2" ]

name: Upload Release Assets
steps:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
max_attempts: 3
command: composer install
- name: Generate and Push Documentation
uses: docker://php:7.3-cli
uses: docker://php:7.4-cli
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
with:
Expand Down
15 changes: 6 additions & 9 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ jobs:
strategy:
fail-fast: false
matrix:
php: [ "5.6", "7.0", "7.1", "7.2", "7.3", "7.4", "8.0", "8.1", "8.2" ]
php: [ "7.4", "8.0", "8.1", "8.2" ]
composer-flags: [""]
include:
- php: "5.6"
- php: "7.4"
composer-flags: "--prefer-lowest "
- php: "8.0"
- php: "8.2"
composer-flags: "--prefer-lowest "
name: PHP ${{ matrix.php }} ${{ matrix.composer-flags }}Unit Test
steps:
Expand All @@ -26,14 +26,11 @@ jobs:
with:
php-version: ${{ matrix.php }}
- name: Install Dependencies
uses: nick-invision/retry@v1
uses: nick-invision/retry@v2
with:
timeout_minutes: 10
max_attempts: 3
command: composer update ${{ matrix.composer-flags }}
- if: ${{ matrix.php == '8.0' && matrix.composer-flags == '--prefer-lowest ' }}
name: Update guzzlehttp/ringphp dependency
run: composer update guzzlehttp/ringphp
- name: Run Script
run: vendor/bin/phpunit

Expand All @@ -45,9 +42,9 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: "7.3"
php-version: "7.4"
- name: Install Dependencies
uses: nick-invision/retry@v1
uses: nick-invision/retry@v2
with:
timeout_minutes: 10
max_attempts: 3
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ For Google Cloud Platform APIs such as [Datastore][cloud-datastore], [Cloud Stor
[cloud-compute]: https://github.com/googleapis/google-cloud-php-compute

## Requirements ##
* [PHP 5.6.0 or higher](https://www.php.net/)
* [PHP 7.4 or higher](https://www.php.net/)

## Developer Documentation ##

Expand Down
19 changes: 9 additions & 10 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,24 @@
"homepage": "http://developers.google.com/api-client-library/php",
"license": "Apache-2.0",
"require": {
"php": "^5.6|^7.0|^8.0",
"google/auth": "^1.10",
"php": "^7.4|^8.0",
"google/auth": "^1.26",
"google/apiclient-services": "~0.200",
"firebase/php-jwt": "~2.0||~3.0||~4.0||~5.0||~6.0",
"monolog/monolog": "^1.17||^2.0||^3.0",
"phpseclib/phpseclib": "~2.0||^3.0.2",
"guzzlehttp/guzzle": "~5.3.3||~6.0||~7.0",
"firebase/php-jwt": "~6.0",
"monolog/monolog": "^2.9||^3.0",
"phpseclib/phpseclib": "^3.0.2",
"guzzlehttp/guzzle": "~6.5||~7.0",
"guzzlehttp/psr7": "^1.8.4||^2.2.1"
},
"require-dev": {
"squizlabs/php_codesniffer": "^3.0",
"symfony/dom-crawler": "~2.1",
"symfony/css-selector": "~2.1",
"cache/filesystem-adapter": "^0.3.2|^1.1",
"cache/filesystem-adapter": "^1.1",
"phpcompatibility/php-compatibility": "^9.2",
"composer/composer": "^1.10.22",
"yoast/phpunit-polyfills": "^1.0",
"phpspec/prophecy-phpunit": "^1.1||^2.0",
"phpunit/phpunit": "^5.7.21 || ^6.0 || ^7.0 || ^8.0 || ^9.0"
"phpspec/prophecy-phpunit": "^2.0",
"phpunit/phpunit": "^9.5"
},
"suggest": {
"cache/filesystem-adapter": "For caching certs and tokens (using Google\\Client::setCache)"
Expand Down
3 changes: 0 additions & 3 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,3 @@ parameters:
level: 5
paths:
- src
excludePaths:
- src/AuthHandler/Guzzle5AuthHandler.php

31 changes: 14 additions & 17 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/9.2/phpunit.xsd"
colors="true"
bootstrap="tests/bootstrap.php">
<testsuites>
<testsuite name="Google PHP Client Unit Test Suite">
<directory>tests/Google</directory>
</testsuite>
<testsuite name="Google PHP Client Examples Test Suite">
<directory>tests/examples</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">./src</directory>
</whitelist>
</filter>
<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">
<coverage>
<include>
<directory suffix=".php">./src</directory>
</include>
</coverage>
<testsuites>
<testsuite name="Google PHP Client Unit Test Suite">
<directory>tests/Google</directory>
</testsuite>
<testsuite name="Google PHP Client Examples Test Suite">
<directory>tests/examples</directory>
</testsuite>
</testsuites>
</phpunit>
94 changes: 19 additions & 75 deletions src/AccessToken/Verify.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use Exception;
use ExpiredException;
use Firebase\JWT\ExpiredException as ExpiredExceptionV3;
use Firebase\JWT\JWT;
use Firebase\JWT\Key;
use Firebase\JWT\SignatureInvalidException;
use Google\Auth\Cache\MemoryCacheItemPool;
Expand All @@ -31,8 +32,9 @@
use GuzzleHttp\ClientInterface;
use InvalidArgumentException;
use LogicException;
use phpseclib3\Crypt\AES;
use phpseclib3\Crypt\PublicKeyLoader;
use phpseclib3\Crypt\RSA\PublicKey; // Firebase v2
use phpseclib3\Math\BigInteger;
use Psr\Cache\CacheItemPoolInterface;

/**
Expand Down Expand Up @@ -219,101 +221,43 @@ private function getFederatedSignOnCerts()

private function getJwtService()
{
$jwtClass = 'JWT';
if (class_exists('\Firebase\JWT\JWT')) {
$jwtClass = 'Firebase\JWT\JWT';
}

if (property_exists($jwtClass, 'leeway') && $jwtClass::$leeway < 1) {
$jwt = new JWT();
if ($jwt::$leeway < 1) {
// Ensures JWT leeway is at least 1
// @see https://github.com/google/google-api-php-client/issues/827
$jwtClass::$leeway = 1;
$jwt::$leeway = 1;
}

// @phpstan-ignore-next-line
return new $jwtClass();
return $jwt;
}

private function getPublicKey($cert)
{
$bigIntClass = $this->getBigIntClass();
$modulus = new $bigIntClass($this->jwt->urlsafeB64Decode($cert['n']), 256);
$exponent = new $bigIntClass($this->jwt->urlsafeB64Decode($cert['e']), 256);
$modulus = new BigInteger($this->jwt->urlsafeB64Decode($cert['n']), 256);
$exponent = new BigInteger($this->jwt->urlsafeB64Decode($cert['e']), 256);
$component = ['n' => $modulus, 'e' => $exponent];

if (class_exists('phpseclib3\Crypt\RSA\PublicKey')) {
/** @var PublicKey $loader */
$loader = PublicKeyLoader::load($component);

return $loader->toString('PKCS8');
}

$rsaClass = $this->getRsaClass();
$rsa = new $rsaClass();
$rsa->loadKey($component);

return $rsa->getPublicKey();
}

private function getRsaClass()
{
if (class_exists('phpseclib3\Crypt\RSA')) {
return 'phpseclib3\Crypt\RSA';
}

if (class_exists('phpseclib\Crypt\RSA')) {
return 'phpseclib\Crypt\RSA';
}
$loader = PublicKeyLoader::load($component);

return 'Crypt_RSA';
}

private function getBigIntClass()
{
if (class_exists('phpseclib3\Math\BigInteger')) {
return 'phpseclib3\Math\BigInteger';
}

if (class_exists('phpseclib\Math\BigInteger')) {
return 'phpseclib\Math\BigInteger';
}

return 'Math_BigInteger';
}

private function getOpenSslConstant()
{
if (class_exists('phpseclib3\Crypt\AES')) {
return 'phpseclib3\Crypt\AES::ENGINE_OPENSSL';
}

if (class_exists('phpseclib\Crypt\RSA')) {
return 'phpseclib\Crypt\RSA::MODE_OPENSSL';
}

if (class_exists('Crypt_RSA')) {
return 'CRYPT_RSA_MODE_OPENSSL';
}

throw new Exception('Cannot find RSA class');
return $loader->toString('PKCS8');
}

/**
* phpseclib calls "phpinfo" by default, which requires special
* whitelisting in the AppEngine VM environment. This function
* sets constants to bypass the need for phpseclib to check phpinfo
*
* @see phpseclib/Math/BigInteger
* @see https://github.com/GoogleCloudPlatform/getting-started-php/issues/85
*/
* phpseclib calls "phpinfo" by default, which requires special
* whitelisting in the AppEngine VM environment. This function
* sets constants to bypass the need for phpseclib to check phpinfo
*
* @see phpseclib/Math/BigInteger
* @see https://github.com/GoogleCloudPlatform/getting-started-php/issues/85
*/
private function setPhpsecConstants()
{
if (filter_var(getenv('GAE_VM'), FILTER_VALIDATE_BOOLEAN)) {
if (!defined('MATH_BIGINTEGER_OPENSSL_ENABLED')) {
define('MATH_BIGINTEGER_OPENSSL_ENABLED', true);
}
if (!defined('CRYPT_RSA_MODE')) {
define('CRYPT_RSA_MODE', constant($this->getOpenSslConstant()));
define('CRYPT_RSA_MODE', AES::ENGINE_OPENSSL);
}
}
}
Expand Down
4 changes: 1 addition & 3 deletions src/AuthHandler/AuthHandlerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class AuthHandlerFactory
/**
* Builds out a default http handler for the installed version of guzzle.
*
* @return Guzzle5AuthHandler|Guzzle6AuthHandler|Guzzle7AuthHandler
* @return Guzzle6AuthHandler|Guzzle7AuthHandler
* @throws Exception
*/
public static function build($cache = null, array $cacheConfig = [])
Expand All @@ -38,8 +38,6 @@ public static function build($cache = null, array $cacheConfig = [])
}

switch ($guzzleVersion) {
case 5:
return new Guzzle5AuthHandler($cache, $cacheConfig);
case 6:
return new Guzzle6AuthHandler($cache, $cacheConfig);
case 7:
Expand Down
Loading

0 comments on commit c765b37

Please sign in to comment.