Skip to content

Commit 292d5c8

Browse files
authored
Add support for multiple Firebase projects (#67)
1 parent 87b5c23 commit 292d5c8

22 files changed

+920
-360
lines changed

.github/workflows/tests.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,14 @@ jobs:
1111
fail-fast: false
1212
matrix:
1313
php: ['7.4']
14-
laravel: ['5.8', '6.0', '7.0', '8.0']
14+
laravel: ['6.0', '7.0', '8.0']
1515
include:
1616
- laravel: '8.0'
1717
testbench: '6.0'
1818
- laravel: '7.0'
1919
testbench: '5.2'
2020
- laravel: '6.0'
2121
testbench: '4.8'
22-
- laravel: '5.8'
23-
testbench: '3.8.6'
2422

2523
name: Laravel ${{ matrix.laravel }}
2624

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
/build
22
/vendor
33

4+
/.php_cs
5+
/.php_cs.cache
46
/.phpunit.result.cache
57
/composer.lock
68
/google-service-account.json

.php_cs.dist

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
$finder = PhpCsFixer\Finder::create()
6+
->in(['src', 'tests']);
7+
8+
return PhpCsFixer\Config::create()
9+
->setUsingCache(true)
10+
->setRiskyAllowed(true)
11+
->setRules([
12+
'@Symfony' => true,
13+
'align_multiline_comment' => true,
14+
'array_indentation' => true,
15+
'array_syntax' => ['syntax' => 'short'],
16+
'combine_consecutive_issets' => true,
17+
'date_time_immutable' => true,
18+
'declare_strict_types' => true,
19+
'function_to_constant' => true,
20+
'header_comment' => ['header' => ''],
21+
// 'mb_str_functions' => true,
22+
'method_chaining_indentation' => true,
23+
'multiline_whitespace_before_semicolons' => true,
24+
'native_constant_invocation' => true,
25+
'native_function_invocation' => true,
26+
'no_alternative_syntax' => true,
27+
'no_homoglyph_names' => true,
28+
'no_null_property_initialization' => true,
29+
'no_superfluous_elseif' => true,
30+
'no_superfluous_phpdoc_tags' => [
31+
'allow_mixed' => true,
32+
],
33+
'no_useless_else' => true,
34+
'nullable_type_declaration_for_default_null_value' => [
35+
'use_nullable_type_declaration' => true,
36+
],
37+
'ordered_imports' => true,
38+
'ordered_interfaces' => true,
39+
'phpdoc_line_span' => [
40+
'const' => 'single',
41+
'property' => 'single',
42+
],
43+
'phpdoc_no_empty_return' => true,
44+
'php_unit_expectation' => true,
45+
'php_unit_internal_class' => true,
46+
'php_unit_mock' => true,
47+
'php_unit_mock_short_will_return' => true,
48+
'php_unit_namespaced' => true,
49+
'php_unit_no_expectation_annotation' => true,
50+
'php_unit_set_up_tear_down_visibility' => true,
51+
'php_unit_test_case_static_method_calls' => [
52+
'call_type' => 'this',
53+
],
54+
'phpdoc_align' => false,
55+
'phpdoc_order' => true,
56+
'phpdoc_trim_consecutive_blank_line_separation' => true,
57+
'simple_to_complex_string_variable' => true,
58+
'single_line_throw' => false,
59+
'static_lambda' => true,
60+
// 'void_return' => true,
61+
'yoda_style' => false,
62+
])
63+
->setFinder($finder);

CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
11
# CHANGELOG
22

3+
## Unreleased
4+
5+
### Added
6+
* Support for multiple firebase projects.
7+
See "upgrading to version 3" section in [UPGRADE.md](UPGRADE.md)
8+
* `\Kreait\Laravel\Firebase\Facades\Firebase` facade
9+
10+
### Changed
11+
* [config/firebase.php](config/firebase.php) has a new format to support multiple projects
12+
13+
### Deprecated
14+
* Use of `FirebaseAuth`, `FirebaseDatabase`, `FirebaseDynamicLinks`, `FirebaseFirestore`, `FirebaseMessaging`, `FirebaseRemoteConfig` and `FirebaseStorage` facades
15+
16+
### Removed
17+
* Laravel and Lumen 5.8 support
18+
319
## 2.4.0 - 2020-10-04
420

521
### Added

README.md

Lines changed: 41 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,26 @@ A Laravel package for the [Firebase PHP Admin SDK](https://github.com/kreait/fir
1010
[![Discord](https://img.shields.io/discord/523866370778333184.svg?color=7289da&logo=discord)](https://discord.gg/nbgVfty)
1111
[![Sponsor](https://img.shields.io/static/v1?logo=GitHub&label=Sponsor&message=%E2%9D%A4&color=ff69b4)](https://github.com/sponsors/jeromegamez)
1212

13-
* [Installation](#installation)
14-
* [Configuration](#configuration)
15-
* [Usage](#usage)
16-
* [Documentation](https://firebase-php.readthedocs.io/)
13+
- [Installation](#installation)
14+
- [Laravel](#laravel)
15+
- [Lumen](#lumen)
16+
- [Configuration](#configuration)
17+
- [Upgrading to version 3](#upgrading-to-version-3)
18+
- [Facades](#facades)
19+
- [Usage](#usage)
20+
- [Multiple projects](#multiple-projects)
1721
- [Support](#support)
1822
- [License](#license)
1923

2024
## Installation
2125

22-
This package requires Laravel 5.8 and higher or Lumen 5.8 and higher.
26+
This package requires Laravel 6.x and higher or Lumen 6.x and higher.
2327

2428
```bash
2529
composer require kreait/laravel-firebase
2630
```
2731

28-
If you use Lumen or don't use Laravel's package auto-discovery, add the following service provider in
32+
If you use Lumen or don't use Laravel's package auto-discovery, add the following service provider in
2933
`config/app.php` (Laravel) or `bootstrap/app.php` (Lumen):
3034

3135
### Laravel
@@ -39,7 +43,7 @@ return [
3943
// ...
4044
Kreait\Laravel\Firebase\ServiceProvider::class
4145
]
42-
// ...
46+
// ...
4347
];
4448
```
4549

@@ -52,15 +56,18 @@ return [
5256
$app->register(Kreait\Laravel\Firebase\ServiceProvider::class);
5357
```
5458

59+
## Upgrade
60+
See [UPGRADE.md](upgrade.md) for upgrade instructions.
61+
5562
## Configuration
5663

5764
In order to access a Firebase project and its related services using a server SDK, requests must be authenticated.
5865
For server-to-server communication this is done with a Service Account.
5966

60-
The package uses auto discovery to find the credentials needed for authenticating requests to the Firebase APIs
61-
by inspecting certain environment variables and looking into Google's well known path(s).
67+
The package uses auto discovery for the default project to find the credentials needed for authenticating requests to
68+
the Firebase APIs by inspecting certain environment variables and looking into Google's well known path(s).
6269

63-
If you don't already have generated a Service Account, you can do so by following the instructions from the
70+
If you don't already have generated a Service Account, you can do so by following the instructions from the
6471
official documentation pages at https://firebase.google.com/docs/admin/setup#initialize_the_sdk.
6572

6673
Once you have downloaded the Service Account JSON file, you can use it to configure the package by specifying
@@ -88,20 +95,35 @@ cp vendor/kreait/laravel-firebase/config/firebase.php config/firebase.php
8895

8996
| Component | [Automatic Injection](https://laravel.com/docs/5.8/container#automatic-injection) | [Facades](https://laravel.com/docs/facades) | [`app()`](https://laravel.com/docs/helpers#method-app) |
9097
| --- | --- | --- | --- |
91-
| [Authentication](https://firebase-php.readthedocs.io/en/stable/authentication.html) | `\Kreait\Firebase\Auth` | `FirebaseAuth` | `app('firebase.auth')` |
92-
| [Cloud Firestore](https://firebase-php.readthedocs.io/en/stable/cloud-firestore.html) | `\Kreait\Firebase\Firestore` | `FirebaseFirestore` | `app('firebase.firestore')` |
93-
| [Cloud&nbsp;Messaging&nbsp;(FCM)](https://firebase-php.readthedocs.io/en/stable/cloud-messaging.html) | `\Kreait\Firebase\Messaging` | `FirebaseMessaging` | `app('firebase.messaging')` |
94-
| [Dynamic&nbsp;Links](https://firebase-php.readthedocs.io/en/stable/dynamic-links.html) | `\Kreait\Firebase\DynamicLinks` | `FirebaseDynamicLinks` | `app('firebase.dynamic_links')` |
95-
| [Realtime Database](https://firebase-php.readthedocs.io/en/stable/realtime-database.html) | `\Kreait\Firebase\Database` | `FirebaseDatabase` | `app('firebase.database')` |
96-
| [Remote Config](https://firebase-php.readthedocs.io/en/stable/remote-config.html) | `\Kreait\Firebase\RemoteConfig` | `FirebaseRemoteConfig` | `app('firebase.remote_config')` |
97-
| [Cloud Storage](https://firebase-php.readthedocs.io/en/stable/cloud-storage.html) | `\Kreait\Firebase\Storage` | `FirebaseStorage` | `app('firebase.storage')` |
98-
99-
Once you have retrieved a component, please refer to the [documentation of the Firebase PHP Admin SDK](https://firebase-php.readthedocs.io)
98+
| [Authentication](https://firebase-php.readthedocs.io/en/stable/authentication.html) | `\Kreait\Firebase\Auth` | `Firebase::auth()` | `app('firebase.auth')` |
99+
| [Cloud Firestore](https://firebase-php.readthedocs.io/en/stable/cloud-firestore.html) | `\Kreait\Firebase\Firestore` | `Firebase::firestore()` | `app('firebase.firestore')` |
100+
| [Cloud&nbsp;Messaging&nbsp;(FCM)](https://firebase-php.readthedocs.io/en/stable/cloud-messaging.html) | `\Kreait\Firebase\Messaging` | `Firebase::messaging()` | `app('firebase.messaging')` |
101+
| [Dynamic&nbsp;Links](https://firebase-php.readthedocs.io/en/stable/dynamic-links.html) | `\Kreait\Firebase\DynamicLinks` | `Firebase::dynamicLinks()` | `app('firebase.dynamic_links')` |
102+
| [Realtime Database](https://firebase-php.readthedocs.io/en/stable/realtime-database.html) | `\Kreait\Firebase\Database` | `Firebase::database()` | `app('firebase.database')` |
103+
| [Remote Config](https://firebase-php.readthedocs.io/en/stable/remote-config.html) | `\Kreait\Firebase\RemoteConfig` | `Firebase::remoteConfig()` | `app('firebase.remote_config')` |
104+
| [Cloud Storage](https://firebase-php.readthedocs.io/en/stable/cloud-storage.html) | `\Kreait\Firebase\Storage` | `Firebase::storage()` | `app('firebase.storage')` |
105+
106+
Once you have retrieved a component, please refer to the [documentation of the Firebase PHP Admin SDK](https://firebase-php.readthedocs.io)
100107
for further information on how to use it.
101108

102109
**You don't need and should not use the `new Factory()` pattern described in the SDK documentation, this is already
103110
done for you with the Laravel Service Provider. Use Dependency Injection, the Facades or the `app()` helper instead**
104111

112+
### Multiple projects
113+
114+
Multiple projects can be configured in [config/firebase.php](config/firebase.php) by adding another section to the projects array.
115+
116+
When accessing components, the facade uses the default project. One can also explicitly use a project:
117+
118+
```php
119+
Firebase::auth() // returns an intance of \Kreait\Firebase\Auth with the configuration found for the default project
120+
// or
121+
// 'app' is configured as the default project by default, this would be equivalent to Firebase::firestore() when that is the case
122+
Firebase::project('app')->firestore() // returns an intance of \Kreait\Firebase\Firestore with the configuration found for the 'app' project
123+
// or
124+
Firebase::project('secondary-app')->database() // returns an instance of \Kreait\Firebase\Database with the configuration found for the 'secondary-app' project
125+
```
126+
105127
## Support
106128

107129
- [Issue Tracker (Laravel Package)](https://github.com/kreait/laravel-firebase/issues/)

UPGRADE.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
## Upgrading to version 3
2+
3+
When upgrading to `laravel-firebase:^3.0` from an earlier version, you have to update your config file.
4+
5+
All existing keys need to be wrapped in the projects array and a default project needs to be configured:
6+
7+
```php
8+
[
9+
'credentials' => [
10+
'file' => env('FIREBASE_CREDENTIALS'),
11+
'auto_discovery' => true,
12+
],
13+
// ... other keys
14+
]
15+
```
16+
17+
becomes
18+
19+
```php
20+
[
21+
'default' => env('FIREBASE_PROJECT', 'app'),
22+
23+
'projects' => [
24+
'app' => [
25+
'credentials' => [
26+
'file' => env('FIREBASE_CREDENTIALS'),
27+
'auto_discovery' => true,
28+
],
29+
// ... other keys
30+
],
31+
],
32+
]
33+
```
34+
35+
### Facades
36+
Existing facades (eg. `Kreait\Firebase\Facades\FirebaseAuth`) are deprecated in favor of the new `Kreait\Firebase\Facades\Firebase` facade in order to support multiple projects. For now, the old facades are included and resolve to the default project for better backward compatibility, but upgrading is advised as they will be removed in the future.

composer.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@
1313
"require": {
1414
"php": "^7.2|^8.0",
1515
"kreait/firebase-php": "^5.8.1",
16-
"illuminate/contracts": "^5.8|^6.0|^7.0|^8.0",
17-
"illuminate/support": "^5.8|^6.0|^7.0|^8.0"
16+
"illuminate/contracts": "^6.0|^7.0|^8.0",
17+
"illuminate/support": "^6.0|^7.0|^8.0"
1818
},
1919
"require-dev": {
20-
"orchestra/testbench": "^3.8.6|^4.8|^5.2|^6.0",
21-
"roave/better-reflection": "^3.6|^4.6"
20+
"orchestra/testbench": "^4.0|^5.0|^6.0",
21+
"roave/better-reflection": "^3.6|^4.6",
22+
"friendsofphp/php-cs-fixer": "^2.16"
2223
},
2324
"autoload": {
2425
"psr-4": {
@@ -39,6 +40,7 @@
3940
"Kreait\\Laravel\\Firebase\\ServiceProvider"
4041
],
4142
"aliases": {
43+
"Firebase": "Kreait\\Laravel\\Firebase\\Facades\\Firebase",
4244
"FirebaseAuth": "Kreait\\Laravel\\Firebase\\Facades\\FirebaseAuth",
4345
"FirebaseDatabase": "Kreait\\Laravel\\Firebase\\Facades\\FirebaseDatabase",
4446
"FirebaseDynamicLinks": "Kreait\\Laravel\\Firebase\\Facades\\FirebaseDynamicLinks",

0 commit comments

Comments
 (0)