Skip to content

Commit e88fae5

Browse files
committed
Upgrade kreait/firebase-php to ^6.0
1 parent d173518 commit e88fae5

File tree

9 files changed

+102
-129
lines changed

9 files changed

+102
-129
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ This is a release with breaking changes. Please review the following changes and
66

77
### Changes
88

9+
* Added support for `kreait/firebase-php` ^6.0
10+
* Dropped support for `kreait/firebase-php` <6.0
911
* Dropped support for Laravel/Lumen <8.0
1012
* Removed deprecated Facades - use the `Kreait\Laravel\Firebase\Facades\Firebase` facade instead
1113
* `Kreait\Laravel\Firebase\Facades\FirebaseAuth`

README.md

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ A Laravel package for the [Firebase PHP Admin SDK](https://github.com/kreait/fir
2121

2222
## Installation
2323

24-
This package requires Laravel 6.x and higher or Lumen 6.x and higher.
24+
This package requires Laravel 8.x and higher or Lumen 8.x and higher.
2525

2626
```bash
2727
composer require kreait/laravel-firebase
@@ -94,15 +94,15 @@ cp vendor/kreait/laravel-firebase/config/firebase.php config/firebase.php
9494

9595
## Usage
9696

97-
| 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) |
98-
| --- | --- | --- | --- |
99-
| [Authentication](https://firebase-php.readthedocs.io/en/stable/authentication.html) | `\Kreait\Firebase\Auth` | `Firebase::auth()` | `app('firebase.auth')` |
100-
| [Cloud Firestore](https://firebase-php.readthedocs.io/en/stable/cloud-firestore.html) | `\Kreait\Firebase\Firestore` | `Firebase::firestore()` | `app('firebase.firestore')` |
101-
| [Cloud&nbsp;Messaging&nbsp;(FCM)](https://firebase-php.readthedocs.io/en/stable/cloud-messaging.html) | `\Kreait\Firebase\Messaging` | `Firebase::messaging()` | `app('firebase.messaging')` |
102-
| [Dynamic&nbsp;Links](https://firebase-php.readthedocs.io/en/stable/dynamic-links.html) | `\Kreait\Firebase\DynamicLinks` | `Firebase::dynamicLinks()` | `app('firebase.dynamic_links')` |
103-
| [Realtime Database](https://firebase-php.readthedocs.io/en/stable/realtime-database.html) | `\Kreait\Firebase\Database` | `Firebase::database()` | `app('firebase.database')` |
104-
| [Remote Config](https://firebase-php.readthedocs.io/en/stable/remote-config.html) | `\Kreait\Firebase\RemoteConfig` | `Firebase::remoteConfig()` | `app('firebase.remote_config')` |
105-
| [Cloud Storage](https://firebase-php.readthedocs.io/en/stable/cloud-storage.html) | `\Kreait\Firebase\Storage` | `Firebase::storage()` | `app('firebase.storage')` |
97+
| Component | [Automatic Injection](https://laravel.com/docs/container#automatic-injection) | [Facades](https://laravel.com/docs/facades) | [`app()`](https://laravel.com/docs/helpers#method-app) |
98+
|-------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------|---------------------------------------------|--------------------------------------------------------|
99+
| [Authentication](https://firebase-php.readthedocs.io/en/stable/authentication.html) | `\Kreait\Firebase\Contract\Auth` | `Firebase::auth()` | `app('firebase.auth')` |
100+
| [Cloud Firestore](https://firebase-php.readthedocs.io/en/stable/cloud-firestore.html) | `\Kreait\Firebase\Contract\Firestore` | `Firebase::firestore()` | `app('firebase.firestore')` |
101+
| [Cloud&nbsp;Messaging&nbsp;(FCM)](https://firebase-php.readthedocs.io/en/stable/cloud-messaging.html) | `\Kreait\Firebase\Contract\Messaging` | `Firebase::messaging()` | `app('firebase.messaging')` |
102+
| [Dynamic&nbsp;Links](https://firebase-php.readthedocs.io/en/stable/dynamic-links.html) | `\Kreait\Firebase\Contract\DynamicLinks` | `Firebase::dynamicLinks()` | `app('firebase.dynamic_links')` |
103+
| [Realtime Database](https://firebase-php.readthedocs.io/en/stable/realtime-database.html) | `\Kreait\Firebase\Contract\Database` | `Firebase::database()` | `app('firebase.database')` |
104+
| [Remote Config](https://firebase-php.readthedocs.io/en/stable/remote-config.html) | `\Kreait\Firebase\Contract\RemoteConfig` | `Firebase::remoteConfig()` | `app('firebase.remote_config')` |
105+
| [Cloud Storage](https://firebase-php.readthedocs.io/en/stable/cloud-storage.html) | `\Kreait\Firebase\Contract\Storage` | `Firebase::storage()` | `app('firebase.storage')` |
106106

107107
Once you have retrieved a component, please refer to the [documentation of the Firebase PHP Admin SDK](https://firebase-php.readthedocs.io)
108108
for further information on how to use it.
@@ -133,6 +133,10 @@ $anotherAppAuth = Firebase::project('another-app')->auth();
133133
- [Feature Requests and Discussions (Admin SDK)](https://github.com/kreait/firebase-php/discussions)
134134
- [Stack Overflow](https://stackoverflow.com/questions/tagged/firebase+php)
135135

136+
_If you or your team rely on this project and me maintaining it, please consider becoming a
137+
[Sponsor](https://github.com/sponsors/jeromegamez/) 🙏. Higher tiers enable access to extended
138+
support._
139+
136140
## License
137141

138142
Firebase Admin PHP SDK is licensed under the [MIT License](LICENSE).

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "kreait/laravel-firebase",
33
"description": "A Laravel package for the Firebase PHP Admin SDK",
4-
"keywords": ["laravel", "firebase", "fcm", "gcm"],
4+
"keywords": ["laravel", "firebase", "firebase", "sdk", "api", "database", "fcm", "gcm"],
55
"type": "library",
66
"license": "MIT",
77
"authors": [
@@ -11,8 +11,8 @@
1111
}
1212
],
1313
"require": {
14-
"kreait/firebase-php": "^5.24",
1514
"php": "^7.4|^8.0",
15+
"kreait/firebase-php": "^6.0",
1616
"illuminate/contracts": "^8.0",
1717
"illuminate/support": "^8.0",
1818
"symfony/cache": "^5.4|^6.0"

src/Facades/Firebase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
*/
2424
final class Firebase extends Facade
2525
{
26-
protected static function getFacadeAccessor()
26+
protected static function getFacadeAccessor(): string
2727
{
2828
return 'firebase.manager';
2929
}

src/FirebaseProject.php

Lines changed: 25 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,44 +4,36 @@
44

55
namespace Kreait\Laravel\Firebase;
66

7-
use Kreait\Firebase;
7+
use Kreait\Firebase\Contract\Auth;
8+
use Kreait\Firebase\Contract\Database;
9+
use Kreait\Firebase\Contract\DynamicLinks;
10+
use Kreait\Firebase\Contract\Firestore;
11+
use Kreait\Firebase\Contract\Messaging;
12+
use Kreait\Firebase\Contract\RemoteConfig;
13+
use Kreait\Firebase\Contract\Storage;
14+
use Kreait\Firebase\Factory;
815

916
class FirebaseProject
1017
{
11-
/** @var \Kreait\Firebase\Factory */
12-
protected $factory;
18+
protected Factory $factory;
1319

14-
/** @var array */
15-
protected $config;
20+
protected array $config;
1621

17-
/** @var \Kreait\Firebase\Contract\Auth|null */
18-
protected $auth;
22+
protected ?Auth $auth = null;
23+
protected ?Database $database = null;
24+
protected ?DynamicLinks $dynamicLinks = null;
25+
protected ?Firestore $firestore = null;
26+
protected ?Messaging $messaging = null;
27+
protected ?RemoteConfig $remoteConfig = null;
28+
protected ?Storage $storage = null;
1929

20-
/** @var \Kreait\Firebase\Contract\Database|null */
21-
protected $database;
22-
23-
/** @var \Kreait\Firebase\Contract\DynamicLinks|null */
24-
protected $dynamicLinks;
25-
26-
/** @var \Kreait\Firebase\Contract\Firestore|null */
27-
protected $firestore;
28-
29-
/** @var \Kreait\Firebase\Contract\Messaging|null */
30-
protected $messaging;
31-
32-
/** @var \Kreait\Firebase\Contract\RemoteConfig|null */
33-
protected $remoteConfig;
34-
35-
/** @var \Kreait\Firebase\Contract\Storage|null */
36-
protected $storage;
37-
38-
public function __construct(Firebase\Factory $factory, array $config)
30+
public function __construct(Factory $factory, array $config)
3931
{
4032
$this->factory = $factory;
4133
$this->config = $config;
4234
}
4335

44-
public function auth(): Firebase\Contract\Auth
36+
public function auth(): Auth
4537
{
4638
if (!$this->auth) {
4739
$this->auth = $this->factory->createAuth();
@@ -50,7 +42,7 @@ public function auth(): Firebase\Contract\Auth
5042
return $this->auth;
5143
}
5244

53-
public function database(): Firebase\Contract\Database
45+
public function database(): Database
5446
{
5547
if (!$this->database) {
5648
$this->database = $this->factory->createDatabase();
@@ -59,7 +51,7 @@ public function database(): Firebase\Contract\Database
5951
return $this->database;
6052
}
6153

62-
public function dynamicLinks(): Firebase\Contract\DynamicLinks
54+
public function dynamicLinks(): DynamicLinks
6355
{
6456
if (!$this->dynamicLinks) {
6557
$this->dynamicLinks = $this->factory->createDynamicLinksService($this->config['dynamic_links']['default_domain'] ?? null);
@@ -68,7 +60,7 @@ public function dynamicLinks(): Firebase\Contract\DynamicLinks
6860
return $this->dynamicLinks;
6961
}
7062

71-
public function firestore(): Firebase\Contract\Firestore
63+
public function firestore(): Firestore
7264
{
7365
if (!$this->firestore) {
7466
$this->firestore = $this->factory->createFirestore();
@@ -77,7 +69,7 @@ public function firestore(): Firebase\Contract\Firestore
7769
return $this->firestore; // @codeCoverageIgnore
7870
}
7971

80-
public function messaging(): Firebase\Contract\Messaging
72+
public function messaging(): Messaging
8173
{
8274
if (!$this->messaging) {
8375
$this->messaging = $this->factory->createMessaging();
@@ -86,7 +78,7 @@ public function messaging(): Firebase\Contract\Messaging
8678
return $this->messaging;
8779
}
8880

89-
public function remoteConfig(): Firebase\Contract\RemoteConfig
81+
public function remoteConfig(): RemoteConfig
9082
{
9183
if (!$this->remoteConfig) {
9284
$this->remoteConfig = $this->factory->createRemoteConfig();
@@ -95,7 +87,7 @@ public function remoteConfig(): Firebase\Contract\RemoteConfig
9587
return $this->remoteConfig;
9688
}
9789

98-
public function storage(): Firebase\Contract\Storage
90+
public function storage(): Storage
9991
{
10092
if (!$this->storage) {
10193
$this->storage = $this->factory->createStorage();

src/FirebaseProjectManager.php

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,20 @@
55
namespace Kreait\Laravel\Firebase;
66

77
use Illuminate\Contracts\Container\Container;
8+
use Illuminate\Contracts\Foundation\Application;
89
use Kreait\Firebase\Exception\InvalidArgumentException;
910
use Kreait\Firebase\Factory;
1011
use Kreait\Firebase\Http\HttpClientOptions;
11-
use Psr\Cache\CacheItemPoolInterface;
1212
use Psr\SimpleCache\CacheInterface;
1313
use Symfony\Component\Cache\Adapter\Psr16Adapter;
14-
use Symfony\Component\Cache\Psr16Cache;
1514

1615
class FirebaseProjectManager
1716
{
18-
/** @var \Illuminate\Contracts\Foundation\Application */
17+
/** @var Application */
1918
protected $app;
2019

2120
/** @var FirebaseProject[] */
22-
protected $projects = [];
21+
protected array $projects = [];
2322

2423
public function __construct(Container $app)
2524
{
@@ -39,7 +38,7 @@ public function project(?string $name = null): FirebaseProject
3938

4039
protected function configuration(string $name): array
4140
{
42-
$config = $this->app->config->get('firebase.projects.'.$name) ?? null;
41+
$config = $this->app->config->get('firebase.projects.'.$name);
4342

4443
if (!$config) {
4544
throw new InvalidArgumentException("Firebase project [{$name}] not configured.");
@@ -50,9 +49,9 @@ protected function configuration(string $name): array
5049

5150
protected function resolveCredentials(string $credentials): string
5251
{
53-
$isJsonString = \strpos($credentials, '{') === 0;
54-
$isAbsoluteLinuxPath = \strpos($credentials, '/') === 0;
55-
$isAbsoluteWindowsPath = \strpos($credentials, ':\\') !== false;
52+
$isJsonString = \str_starts_with($credentials, '{');
53+
$isAbsoluteLinuxPath = \str_starts_with($credentials, '/');
54+
$isAbsoluteWindowsPath = \str_contains($credentials, ':\\');
5655

5756
$isRelativePath = !$isJsonString && !$isAbsoluteLinuxPath && !$isAbsoluteWindowsPath;
5857

@@ -75,7 +74,7 @@ protected function configure(string $name): FirebaseProject
7574
$factory = $factory->withServiceAccount($resolvedCredentials);
7675
}
7776

78-
$enableAutoDiscovery = $config['credentials']['auto_discovery'] ?? ($this->getDefaultProject() == $name ? true : false);
77+
$enableAutoDiscovery = $config['credentials']['auto_discovery'] ?? ($this->getDefaultProject() === $name);
7978
if (!$enableAutoDiscovery) {
8079
$factory = $factory->withDisabledAutoDiscovery();
8180
}
@@ -92,26 +91,19 @@ protected function configure(string $name): FirebaseProject
9291
$factory = $factory->withDefaultStorageBucket($defaultStorageBucket);
9392
}
9493

95-
if ($config['debug'] ?? false) {
96-
$factory = $factory->withEnabledDebug();
97-
}
98-
9994
if ($cacheStore = $config['cache_store'] ?? null) {
10095
$cache = $this->app->make('cache')->store($cacheStore);
10196

102-
if ($cache instanceof CacheItemPoolInterface) {
103-
$psr6Cache = $cache;
104-
$psr16Cache = new Psr16Cache($cache);
105-
} elseif ($cache instanceof CacheInterface) {
106-
$psr6Cache = new Psr16Adapter($cache);
107-
$psr16Cache = $cache;
97+
if ($cache instanceof CacheInterface) {
98+
$cache = new Psr16Adapter($cache);
10899
} else {
109-
throw new InvalidArgumentException("The cache store must be an instance of a PSR-6 or PSR-16 cache");
100+
throw new InvalidArgumentException('The cache store must be an instance of a PSR-6 or PSR-16 cache');
110101
}
111102

112103
$factory = $factory
113-
->withVerifierCache($psr16Cache)
114-
->withAuthTokenCache($psr6Cache);
104+
->withVerifierCache($cache)
105+
->withAuthTokenCache($cache)
106+
;
115107
}
116108

117109
if ($logChannel = $config['logging']['http_log_channel'] ?? null) {

src/ServiceProvider.php

Lines changed: 21 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
final class ServiceProvider extends \Illuminate\Support\ServiceProvider
1212
{
13-
public function boot()
13+
public function boot(): void
1414
{
1515
// @codeCoverageIgnoreStart
1616
if (!$this->app->runningInConsole()) {
@@ -27,7 +27,7 @@ public function boot()
2727
], 'config');
2828
}
2929

30-
public function register()
30+
public function register(): void
3131
{
3232
// @codeCoverageIgnoreStart
3333
if ($this->app instanceof Lumen) {
@@ -43,48 +43,31 @@ public function register()
4343

4444
private function registerComponents(): void
4545
{
46-
$this->app->singleton(Firebase\Contract\Auth::class, static function (Container $app) {
47-
return $app->make(FirebaseProjectManager::class)->project()->auth();
48-
});
49-
$this->app->alias(Firebase\Contract\Auth::class, Firebase\Auth::class);
46+
$this->app->singleton(Firebase\Contract\Auth::class, static fn (Container $app) => $app->make(FirebaseProjectManager::class)->project()->auth());
5047
$this->app->alias(Firebase\Contract\Auth::class, 'firebase.auth');
5148

52-
$this->app->singleton(Firebase\Database::class, static function (Container $app) {
53-
return $app->make(FirebaseProjectManager::class)->project()->database();
54-
});
55-
$this->app->alias(Firebase\Database::class, 'firebase.database');
56-
57-
$this->app->singleton(Firebase\DynamicLinks::class, static function (Container $app) {
58-
return $app->make(FirebaseProjectManager::class)->project()->dynamicLinks();
59-
});
60-
$this->app->alias(Firebase\DynamicLinks::class, 'firebase.dynamic_links');
61-
62-
$this->app->singleton(Firebase\Firestore::class, static function (Container $app) {
63-
return $app->make(FirebaseProjectManager::class)->project()->firestore();
64-
});
65-
$this->app->alias(Firebase\Firestore::class, 'firebase.firestore');
66-
67-
$this->app->singleton(Firebase\Messaging::class, static function (Container $app) {
68-
return $app->make(FirebaseProjectManager::class)->project()->messaging();
69-
});
70-
$this->app->alias(Firebase\Messaging::class, 'firebase.messaging');
71-
72-
$this->app->singleton(Firebase\RemoteConfig::class, static function (Container $app) {
73-
return $app->make(FirebaseProjectManager::class)->project()->remoteConfig();
74-
});
75-
$this->app->alias(Firebase\RemoteConfig::class, 'firebase.remote_config');
76-
77-
$this->app->singleton(Firebase\Storage::class, static function (Container $app) {
78-
return $app->make(FirebaseProjectManager::class)->project()->storage();
79-
});
80-
$this->app->alias(Firebase\Storage::class, 'firebase.storage');
49+
$this->app->singleton(Firebase\Contract\Database::class, static fn (Container $app) => $app->make(FirebaseProjectManager::class)->project()->database());
50+
$this->app->alias(Firebase\Contract\Database::class, 'firebase.database');
51+
52+
$this->app->singleton(Firebase\Contract\DynamicLinks::class, static fn (Container $app) => $app->make(FirebaseProjectManager::class)->project()->dynamicLinks());
53+
$this->app->alias(Firebase\Contract\DynamicLinks::class, 'firebase.dynamic_links');
54+
55+
$this->app->singleton(Firebase\Contract\Firestore::class, static fn (Container $app) => $app->make(FirebaseProjectManager::class)->project()->firestore());
56+
$this->app->alias(Firebase\Contract\Firestore::class, 'firebase.firestore');
57+
58+
$this->app->singleton(Firebase\Contract\Messaging::class, static fn (Container $app) => $app->make(FirebaseProjectManager::class)->project()->messaging());
59+
$this->app->alias(Firebase\Contract\Messaging::class, 'firebase.messaging');
60+
61+
$this->app->singleton(Firebase\Contract\RemoteConfig::class, static fn (Container $app) => $app->make(FirebaseProjectManager::class)->project()->remoteConfig());
62+
$this->app->alias(Firebase\Contract\RemoteConfig::class, 'firebase.remote_config');
63+
64+
$this->app->singleton(Firebase\Contract\Storage::class, static fn (Container $app) => $app->make(FirebaseProjectManager::class)->project()->storage());
65+
$this->app->alias(Firebase\Contract\Storage::class, 'firebase.storage');
8166
}
8267

8368
private function registerManager(): void
8469
{
85-
$this->app->singleton(FirebaseProjectManager::class, static function (Container $app) {
86-
return new FirebaseProjectManager($app);
87-
});
70+
$this->app->singleton(FirebaseProjectManager::class, static fn (Container $app) => new FirebaseProjectManager($app));
8871
$this->app->alias(FirebaseProjectManager::class, 'firebase.manager');
8972
}
9073
}

0 commit comments

Comments
 (0)