Skip to content

Commit

Permalink
Add AppCheck support (#174)
Browse files Browse the repository at this point in the history
  • Loading branch information
nhaynes authored Mar 30, 2023
1 parent 48b788c commit 18d7ccc
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ php artisan vendor:publish --provider="Kreait\Laravel\Firebase\ServiceProvider"

| Component | [Container Injection](https://laravel.com/docs/container#automatic-injection) | [Facades](https://laravel.com/docs/facades) | [`app()`](https://laravel.com/docs/helpers#method-app) |
|-------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------|---------------------------------------------|--------------------------------------------------------|
| [AppCheck](https://firebase-php.readthedocs.io/en/stable/app-check.html) | `\Kreait\Firebase\Contract\AppCheck` | `Firebase::appCheck()` | `app('firebase.app_check')` |
| [Authentication](https://firebase-php.readthedocs.io/en/stable/authentication.html) | `\Kreait\Firebase\Contract\Auth` | `Firebase::auth()` | `app('firebase.auth')` |
| [Cloud Firestore](https://firebase-php.readthedocs.io/en/stable/cloud-firestore.html) | `\Kreait\Firebase\Contract\Firestore` | `Firebase::firestore()` | `app('firebase.firestore')` |
| [Cloud Messaging (FCM)](https://firebase-php.readthedocs.io/en/stable/cloud-messaging.html) | `\Kreait\Firebase\Contract\Messaging` | `Firebase::messaging()` | `app('firebase.messaging')` |
Expand Down
1 change: 1 addition & 0 deletions src/Facades/Firebase.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* @method static \Kreait\Laravel\Firebase\FirebaseProject project(string $name = null)
* @method static string getDefaultProject()
* @method static void setDefaultProject(string $name)
* @method static \Kreait\Firebase\Contract\AppCheck appCheck()
* @method static \Kreait\Firebase\Contract\Auth auth()
* @method static \Kreait\Firebase\Contract\Database database()
* @method static \Kreait\Firebase\Contract\DynamicLinks dynamicLinks()
Expand Down
11 changes: 11 additions & 0 deletions src/FirebaseProject.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Kreait\Laravel\Firebase;

use Kreait\Firebase\Contract\AppCheck;
use Kreait\Firebase\Contract\Auth;
use Kreait\Firebase\Contract\Database;
use Kreait\Firebase\Contract\DynamicLinks;
Expand All @@ -19,6 +20,7 @@ class FirebaseProject

protected array $config;

protected ?AppCheck $appCheck = null;
protected ?Auth $auth = null;
protected ?Database $database = null;
protected ?DynamicLinks $dynamicLinks = null;
Expand All @@ -33,6 +35,15 @@ public function __construct(Factory $factory, array $config)
$this->config = $config;
}

public function appCheck(): AppCheck
{
if (!$this->appCheck) {
$this->appCheck = $this->factory->createAppCheck();
}

return $this->appCheck;
}

public function auth(): Auth
{
if (!$this->auth) {
Expand Down
3 changes: 3 additions & 0 deletions src/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ public function register(): void

private function registerComponents(): void
{
$this->app->singleton(Firebase\Contract\AppCheck::class, static fn (Container $app) => $app->make(FirebaseProjectManager::class)->project()->appCheck());
$this->app->alias(Firebase\Contract\AppCheck::class, 'firebase.app_check');

$this->app->singleton(Firebase\Contract\Auth::class, static fn (Container $app) => $app->make(FirebaseProjectManager::class)->project()->auth());
$this->app->alias(Firebase\Contract\Auth::class, 'firebase.auth');

Expand Down
1 change: 1 addition & 0 deletions tests/ServiceProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public function it_provides_components(): void
{
$this->app->config->set('firebase.projects.app.credentials.file', \realpath(__DIR__ . '/_fixtures/service_account.json'));

$this->assertInstanceOf(Firebase\Contract\AppCheck::class, $this->app->make(Firebase\Contract\AppCheck::class));
$this->assertInstanceOf(Firebase\Contract\Auth::class, $this->app->make(Firebase\Contract\Auth::class));
$this->assertInstanceOf(Firebase\Contract\Database::class, $this->app->make(Firebase\Contract\Database::class));
$this->assertInstanceOf(Firebase\Contract\DynamicLinks::class, $this->app->make(Firebase\Contract\DynamicLinks::class));
Expand Down

0 comments on commit 18d7ccc

Please sign in to comment.