Skip to content

Commit 18d7ccc

Browse files
authored
Add AppCheck support (#174)
1 parent 48b788c commit 18d7ccc

File tree

5 files changed

+17
-0
lines changed

5 files changed

+17
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ php artisan vendor:publish --provider="Kreait\Laravel\Firebase\ServiceProvider"
5959

6060
| Component | [Container Injection](https://laravel.com/docs/container#automatic-injection) | [Facades](https://laravel.com/docs/facades) | [`app()`](https://laravel.com/docs/helpers#method-app) |
6161
|-------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------|---------------------------------------------|--------------------------------------------------------|
62+
| [AppCheck](https://firebase-php.readthedocs.io/en/stable/app-check.html) | `\Kreait\Firebase\Contract\AppCheck` | `Firebase::appCheck()` | `app('firebase.app_check')` |
6263
| [Authentication](https://firebase-php.readthedocs.io/en/stable/authentication.html) | `\Kreait\Firebase\Contract\Auth` | `Firebase::auth()` | `app('firebase.auth')` |
6364
| [Cloud Firestore](https://firebase-php.readthedocs.io/en/stable/cloud-firestore.html) | `\Kreait\Firebase\Contract\Firestore` | `Firebase::firestore()` | `app('firebase.firestore')` |
6465
| [Cloud Messaging (FCM)](https://firebase-php.readthedocs.io/en/stable/cloud-messaging.html) | `\Kreait\Firebase\Contract\Messaging` | `Firebase::messaging()` | `app('firebase.messaging')` |

src/Facades/Firebase.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
* @method static \Kreait\Laravel\Firebase\FirebaseProject project(string $name = null)
1111
* @method static string getDefaultProject()
1212
* @method static void setDefaultProject(string $name)
13+
* @method static \Kreait\Firebase\Contract\AppCheck appCheck()
1314
* @method static \Kreait\Firebase\Contract\Auth auth()
1415
* @method static \Kreait\Firebase\Contract\Database database()
1516
* @method static \Kreait\Firebase\Contract\DynamicLinks dynamicLinks()

src/FirebaseProject.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Kreait\Laravel\Firebase;
66

7+
use Kreait\Firebase\Contract\AppCheck;
78
use Kreait\Firebase\Contract\Auth;
89
use Kreait\Firebase\Contract\Database;
910
use Kreait\Firebase\Contract\DynamicLinks;
@@ -19,6 +20,7 @@ class FirebaseProject
1920

2021
protected array $config;
2122

23+
protected ?AppCheck $appCheck = null;
2224
protected ?Auth $auth = null;
2325
protected ?Database $database = null;
2426
protected ?DynamicLinks $dynamicLinks = null;
@@ -33,6 +35,15 @@ public function __construct(Factory $factory, array $config)
3335
$this->config = $config;
3436
}
3537

38+
public function appCheck(): AppCheck
39+
{
40+
if (!$this->appCheck) {
41+
$this->appCheck = $this->factory->createAppCheck();
42+
}
43+
44+
return $this->appCheck;
45+
}
46+
3647
public function auth(): Auth
3748
{
3849
if (!$this->auth) {

src/ServiceProvider.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ public function register(): void
3232

3333
private function registerComponents(): void
3434
{
35+
$this->app->singleton(Firebase\Contract\AppCheck::class, static fn (Container $app) => $app->make(FirebaseProjectManager::class)->project()->appCheck());
36+
$this->app->alias(Firebase\Contract\AppCheck::class, 'firebase.app_check');
37+
3538
$this->app->singleton(Firebase\Contract\Auth::class, static fn (Container $app) => $app->make(FirebaseProjectManager::class)->project()->auth());
3639
$this->app->alias(Firebase\Contract\Auth::class, 'firebase.auth');
3740

tests/ServiceProviderTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public function it_provides_components(): void
1818
{
1919
$this->app->config->set('firebase.projects.app.credentials.file', \realpath(__DIR__ . '/_fixtures/service_account.json'));
2020

21+
$this->assertInstanceOf(Firebase\Contract\AppCheck::class, $this->app->make(Firebase\Contract\AppCheck::class));
2122
$this->assertInstanceOf(Firebase\Contract\Auth::class, $this->app->make(Firebase\Contract\Auth::class));
2223
$this->assertInstanceOf(Firebase\Contract\Database::class, $this->app->make(Firebase\Contract\Database::class));
2324
$this->assertInstanceOf(Firebase\Contract\DynamicLinks::class, $this->app->make(Firebase\Contract\DynamicLinks::class));

0 commit comments

Comments
 (0)