From 7e79f3d7be4811f760e19cc4a2c558e04196ec1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Mendoza?= Date: Thu, 2 May 2024 12:34:51 -0400 Subject: [PATCH 1/5] feat: add the protected apiVersion property (#2588) --- src/Service/Resource.php | 10 +++++++++ tests/Google/Service/ResourceTest.php | 29 +++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/src/Service/Resource.php b/src/Service/Resource.php index edc3a36ee..693aaa781 100644 --- a/src/Service/Resource.php +++ b/src/Service/Resource.php @@ -48,6 +48,9 @@ class Resource /** @var string $rootUrlTemplate */ private $rootUrlTemplate; + /** @var string $apiVersion */ + protected $apiVersion; + /** @var \Google\Client $client */ private $client; @@ -225,6 +228,13 @@ public function call($name, $arguments, $expectedClass = null) $expectedClass = null; } + // If the class which is extending from this one contains + // an Api Version, add it to the header + if ($this->apiVersion) { + $request = $request + ->withHeader('X-Goog-Api-Version', $this->apiVersion); + } + // if the client is marked for deferring, rather than // execute the request, return the response if ($this->client->shouldDefer()) { diff --git a/tests/Google/Service/ResourceTest.php b/tests/Google/Service/ResourceTest.php index 86e0bef24..ccf29a7f7 100644 --- a/tests/Google/Service/ResourceTest.php +++ b/tests/Google/Service/ResourceTest.php @@ -106,6 +106,7 @@ public function testCall() $this->assertEquals("https://test.example.com/method/path", (string) $request->getUri()); $this->assertEquals("POST", $request->getMethod()); $this->assertFalse($request->hasHeader('Content-Type')); + $this->assertFalse($request->hasHeader('X-Goog-Api-Version')); } public function testCallWithUniverseDomainTemplate() @@ -474,4 +475,32 @@ public function testExceptionMessage() $this->assertEquals($errors, $e->getErrors()); } } + + public function testVersionedResource() + { + $resource = new VersionedResource( + $this->service, + "test", + "testResource", + [ + "methods" => [ + "testMethod" => [ + "parameters" => [], + "path" => "method/path", + "httpMethod" => "POST", + ] + ] + ] + ); + $request = $resource->call("testMethod", [['postBody' => ['foo' => 'bar']]]); + $this->assertEquals("https://test.example.com/method/path", (string) $request->getUri()); + $this->assertEquals("POST", $request->getMethod()); + $this->assertTrue($request->hasHeader('X-Goog-Api-Version')); + $this->assertEquals('v1_20240101', $request->getHeaderLine('X-Goog-Api-Version')); + } +} + +class VersionedResource extends GoogleResource +{ + protected $apiVersion = 'v1_20240101'; } From dae35dfc3118d3a752c9ef08635fd0fefe84417d Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Fri, 17 May 2024 11:31:11 -0600 Subject: [PATCH 2/5] chore: drop support for PHP 7.4 (#2562) --- .github/sync-repo-settings.yaml | 3 +-- .github/workflows/asset-release.yml | 2 +- .github/workflows/docs.yml | 2 +- .github/workflows/tests.yml | 4 ++-- README.md | 4 ++-- composer.json | 12 ++++++------ 6 files changed, 13 insertions(+), 14 deletions(-) diff --git a/.github/sync-repo-settings.yaml b/.github/sync-repo-settings.yaml index 7a538ecaf..c4543198e 100644 --- a/.github/sync-repo-settings.yaml +++ b/.github/sync-repo-settings.yaml @@ -5,9 +5,8 @@ branchProtectionRules: - pattern: master isAdminEnforced: true requiredStatusCheckContexts: - - '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.3 Unit Test' diff --git a/.github/workflows/asset-release.yml b/.github/workflows/asset-release.yml index 59d5cdd56..bc4b2bf8d 100644 --- a/.github/workflows/asset-release.yml +++ b/.github/workflows/asset-release.yml @@ -10,7 +10,7 @@ jobs: strategy: matrix: operating-system: [ ubuntu-latest ] - php: [ "7.4", "8.0", "8.2" ] + php: [ "8.0", "8.3" ] name: Upload Release Assets steps: diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 02d757bc1..ae9bf2ed0 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -18,7 +18,7 @@ jobs: max_attempts: 3 command: composer install - name: Generate and Push Documentation - uses: docker://php:7.4-cli + uses: docker://php:8.1-cli env: GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} with: diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 614045f13..8f833c134 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -11,10 +11,10 @@ jobs: strategy: fail-fast: false matrix: - php: [ "7.4", "8.0", "8.1", "8.2", "8.3" ] + php: [ "8.0", "8.1", "8.2", "8.3" ] composer-flags: [""] include: - - php: "7.4" + - php: "8.0" composer-flags: "--prefer-lowest " - php: "8.3" composer-flags: "--prefer-lowest " diff --git a/README.md b/README.md index 34960da0d..abd64f123 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ list of [Google cloud packages](https://cloud.google.com/php/docs/reference) fir these are the recommended libraries.
-
Reference Docs
https://googleapis.github.io/google-api-php-client/main/
+
Reference Docs
https://googleapis.github.io/google-api-php-client/main/
License
Apache 2.0
@@ -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 7.4 or higher](https://www.php.net/) +* [PHP 8.0 or higher](https://www.php.net/) ## Developer Documentation ## diff --git a/composer.json b/composer.json index 14c5d4207..abacbe84b 100644 --- a/composer.json +++ b/composer.json @@ -6,14 +6,14 @@ "homepage": "http://developers.google.com/api-client-library/php", "license": "Apache-2.0", "require": { - "php": "^7.4|^8.0", + "php": "^8.0", "google/auth": "^1.37", "google/apiclient-services": "~0.350", - "firebase/php-jwt": "~6.0", + "firebase/php-jwt": "^6.0", "monolog/monolog": "^2.9||^3.0", "phpseclib/phpseclib": "^3.0.36", - "guzzlehttp/guzzle": "^6.5.8||^7.4.5", - "guzzlehttp/psr7": "^1.9.1||^2.2.1" + "guzzlehttp/guzzle": "^7.4.5", + "guzzlehttp/psr7": "^2.6" }, "require-dev": { "squizlabs/php_codesniffer": "^3.8", @@ -22,8 +22,8 @@ "cache/filesystem-adapter": "^1.1", "phpcompatibility/php-compatibility": "^9.2", "composer/composer": "^1.10.23", - "phpspec/prophecy-phpunit": "^2.0", - "phpunit/phpunit": "^9.5" + "phpspec/prophecy-phpunit": "^2.1", + "phpunit/phpunit": "^9.6" }, "suggest": { "cache/filesystem-adapter": "For caching certs and tokens (using Google\\Client::setCache)" From 71579b70a11f1d57ee85b89ac8c9c1d27a6aec27 Mon Sep 17 00:00:00 2001 From: Adrian Kirchner <149483+adriankirchner@users.noreply.github.com> Date: Wed, 22 May 2024 17:07:21 +0200 Subject: [PATCH 3/5] docs: fix link to github hosted reference docs (#2598) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index abd64f123..95150d9f1 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ list of [Google cloud packages](https://cloud.google.com/php/docs/reference) fir these are the recommended libraries.
-
Reference Docs
https://googleapis.github.io/google-api-php-client/main/
+
Reference Docs
https://googleapis.github.io/google-api-php-client/main/
License
Apache 2.0
From 1f4713329d71111a317cda8ef8603fa1bdc88858 Mon Sep 17 00:00:00 2001 From: Razvan Grigore Date: Wed, 10 Jul 2024 17:56:12 +0300 Subject: [PATCH 4/5] feat: add logger to client constructor config (#2606) --- src/Client.php | 6 ++++++ tests/Google/ClientTest.php | 11 +++++++++++ 2 files changed, 17 insertions(+) diff --git a/src/Client.php b/src/Client.php index c7724bd08..330e8ac6b 100644 --- a/src/Client.php +++ b/src/Client.php @@ -196,6 +196,7 @@ public function __construct(array $config = []) 'prompt' => '', 'openid.realm' => '', 'include_granted_scopes' => null, + 'logger' => null, 'login_hint' => '', 'request_visible_actions' => '', 'access_type' => 'online', @@ -242,6 +243,11 @@ public function __construct(array $config = []) $this->setCache($this->config['cache']); unset($this->config['cache']); } + + if (!is_null($this->config['logger'])) { + $this->setLogger($this->config['logger']); + unset($this->config['logger']); + } } /** diff --git a/tests/Google/ClientTest.php b/tests/Google/ClientTest.php index 81ea7525e..7aea7e9ef 100644 --- a/tests/Google/ClientTest.php +++ b/tests/Google/ClientTest.php @@ -268,6 +268,16 @@ public function testDefaultLoggerAppEngine() $this->assertInstanceOf('Monolog\Handler\SyslogHandler', $handler); } + public function testLoggerFromConstructor() + { + $logger1 = new \Monolog\Logger('unit-test'); + $client = new Client(['logger' => $logger1]); + $logger2 = $client->getLogger(); + $this->assertInstanceOf('Monolog\Logger', $logger2); + $this->assertEquals('unit-test', $logger2->getName()); + $this->assertSame($logger1, $logger2); + } + public function testSettersGetters() { $client = new Client(); @@ -279,6 +289,7 @@ public function testSettersGetters() $client->setRedirectUri('localhost'); $client->setConfig('application_name', 'me'); + $client->setLogger(new \Monolog\Logger('test')); $cache = $this->prophesize(CacheItemPoolInterface::class); $client->setCache($cache->reveal()); From b1f63d72c44307ec8ef7bf18f1012de35d8944ed Mon Sep 17 00:00:00 2001 From: "release-please[bot]" <55107282+release-please[bot]@users.noreply.github.com> Date: Wed, 10 Jul 2024 14:57:54 +0000 Subject: [PATCH 5/5] chore(main): release 2.17.0 (#2590) --- CHANGELOG.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 800b01c16..a43c59d90 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Changelog +## [2.17.0](https://github.com/googleapis/google-api-php-client/compare/v2.16.0...v2.17.0) (2024-07-10) + + +### Features + +* Add logger to client constructor config ([#2606](https://github.com/googleapis/google-api-php-client/issues/2606)) ([1f47133](https://github.com/googleapis/google-api-php-client/commit/1f4713329d71111a317cda8ef8603fa1bdc88858)) +* Add the protected apiVersion property ([#2588](https://github.com/googleapis/google-api-php-client/issues/2588)) ([7e79f3d](https://github.com/googleapis/google-api-php-client/commit/7e79f3d7be4811f760e19cc4a2c558e04196ec1d)) + ## [2.16.0](https://github.com/googleapis/google-api-php-client/compare/v2.15.4...v2.16.0) (2024-04-24)