Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add AppCheck support #174

Merged
merged 3 commits into from
Mar 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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