Skip to content

Commit

Permalink
Allow overriding the Firestore default database
Browse files Browse the repository at this point in the history
Co-authored-by: Saiht <[email protected]>
  • Loading branch information
jeromegamez and saiht committed Jan 12, 2024
1 parent f632f07 commit 4831cd1
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## Unreleased

* Added support for overriding the name of the Firestore Default Database
([#209](https://github.com/kreait/laravel-firebase/pull/209))

## 5.5.0 - 2023-11-30

* Added support for PHP 8.3
Expand Down
20 changes: 20 additions & 0 deletions config/firebase.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,26 @@
'tenant_id' => env('FIREBASE_AUTH_TENANT_ID'),
],

/*
* ------------------------------------------------------------------------
* Firestore Component
* ------------------------------------------------------------------------
*/

'firestore' => [

/*
* If you want to access a Firestore database other than the default database,
* enter its name here.
*
* By default, the Firestore client will connect to the `(default)` database.
*
* https://firebase.google.com/docs/firestore/manage-databases
*/

// 'database' => env('FIREBASE_FIRESTORE_DATABASE'),
],

/*
* ------------------------------------------------------------------------
* Firebase Realtime Database
Expand Down
4 changes: 4 additions & 0 deletions src/FirebaseProjectManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ protected function configure(string $name): FirebaseProject
$factory = $factory->withDatabaseAuthVariableOverride($authVariableOverride);
}

if ($firestoreDatabase = $config['firestore']['database'] ?? null) {
$factory = $factory->withFirestoreDatabase($firestoreDatabase);
}

if ($defaultStorageBucket = $config['storage']['default_bucket'] ?? null) {
$factory = $factory->withDefaultStorageBucket($defaultStorageBucket);
}
Expand Down
14 changes: 14 additions & 0 deletions tests/FirebaseProjectManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,20 @@ public function it_uses_the_laravel_cache_as_verifier_cache(): void
$this->assertInstanceOf(CacheItemPoolInterface::class, $property->getValue($factory));
}

/**
* @test
*/
public function it_overrides_the_default_firestore_database(): void
{
config(['firebase.projects.app.firestore.database' => 'override-database']);
$projectName = $this->app->config->get('firebase.default');
$factory = $this->factoryForProject($projectName);

$property = $this->getAccessibleProperty($factory, 'firestoreClientConfig');

$this->assertEquals('override-database', $property->getValue($factory)['database']);
}

/**
* @test
*/
Expand Down

0 comments on commit 4831cd1

Please sign in to comment.