diff --git a/src/Storage/Connection/Rest.php b/src/Storage/Connection/Rest.php index 697103fe8c49..da98048e6c7f 100644 --- a/src/Storage/Connection/Rest.php +++ b/src/Storage/Connection/Rest.php @@ -43,6 +43,11 @@ class Rest implements ConnectionInterface const UPLOAD_URI = 'https://www.googleapis.com/upload/storage/v1/b/{bucket}/o{?query*}'; const DOWNLOAD_URI = 'https://www.googleapis.com/storage/v1/b/{bucket}/o/{object}{?query*}'; + /** + * @var string + */ + private $projectId; + /** * @param array $config */ @@ -58,6 +63,16 @@ public function __construct(array $config = []) $config['serviceDefinitionPath'], self::BASE_URI )); + + $this->projectId = $this->pluck('projectId', $config, false); + } + + /** + * @return string + */ + public function projectId() + { + return $this->projectId; } /** diff --git a/src/Storage/StorageClient.php b/src/Storage/StorageClient.php index 764741981377..3ff11624b373 100644 --- a/src/Storage/StorageClient.php +++ b/src/Storage/StorageClient.php @@ -92,7 +92,9 @@ public function __construct(array $config = []) $config['scopes'] = [self::FULL_CONTROL_SCOPE]; } - $this->connection = new Rest($this->configureAuthentication($config)); + $this->connection = new Rest($this->configureAuthentication($config) + [ + 'projectId' => $this->projectId + ]); } /** diff --git a/tests/unit/Storage/Connection/RestTest.php b/tests/unit/Storage/Connection/RestTest.php index 16022ad07107..9541e1a69a7b 100644 --- a/tests/unit/Storage/Connection/RestTest.php +++ b/tests/unit/Storage/Connection/RestTest.php @@ -104,6 +104,18 @@ public function methodProvider() ]; } + public function testProjectId() + { + $rest = new Rest(['projectId' => 'foo']); + $this->assertEquals('foo', $rest->projectId()); + } + + public function testProjectIdNull() + { + $rest = new Rest(); + $this->assertNull($rest->projectId()); + } + public function testDownloadObject() { $actualRequest = null;