From aa6276942b2cb30b19af2c0b9bf22ca847a7cb52 Mon Sep 17 00:00:00 2001 From: Tom Janssen Date: Thu, 28 Nov 2024 11:42:03 +0100 Subject: [PATCH 1/7] add option to hide button --- resources/views/components/buttons.blade.php | 6 +-- src/Provider.php | 2 + src/Traits/CanBeHidden.php | 40 ++++++++++++++++++++ src/View/Components/Buttons.php | 4 +- 4 files changed, 48 insertions(+), 4 deletions(-) create mode 100644 src/Traits/CanBeHidden.php diff --git a/resources/views/components/buttons.blade.php b/resources/views/components/buttons.blade.php index 50aef85..de84c73 100644 --- a/resources/views/components/buttons.blade.php +++ b/resources/views/components/buttons.blade.php @@ -5,7 +5,7 @@ @endforeach @endif - @if (count($providers)) + @if (count($visibleProviders)) @if($showDivider)
@@ -15,8 +15,8 @@
@endif -
- @foreach($providers as $key => $provider) +
+ @foreach($visibleProviders as $key => $provider) isHidden = $condition; + + return $this; + } + + public function visible(bool | Closure $condition = true): static + { + $this->isVisible = $condition; + + return $this; + } + + public function isHidden(): bool + { + if ($this->evaluate($this->isHidden)) { + return true; + } + + return ! $this->evaluate($this->isVisible); + } + + public function isVisible(): bool + { + return ! $this->isHidden(); + } +} diff --git a/src/View/Components/Buttons.php b/src/View/Components/Buttons.php index 1c61df2..0ef81e7 100644 --- a/src/View/Components/Buttons.php +++ b/src/View/Components/Buttons.php @@ -3,6 +3,7 @@ namespace DutchCodingCompany\FilamentSocialite\View\Components; use DutchCodingCompany\FilamentSocialite\FilamentSocialitePlugin; +use DutchCodingCompany\FilamentSocialite\Provider; use Illuminate\Support\MessageBag; use Illuminate\View\Component; @@ -28,7 +29,8 @@ public function render() } return view('filament-socialite::components.buttons', [ - 'providers' => $this->plugin->getProviders(), + 'providers' => $providers = $this->plugin->getProviders(), + 'visibleProviders' => array_filter($providers, fn (Provider $provider) => $provider->isVisible()), 'socialiteRoute' => $this->plugin->getRoute(), 'messageBag' => $messageBag, ]); From 7b927a5587b680e7828f5bfb82c01d2ca0ca2190 Mon Sep 17 00:00:00 2001 From: Tom Janssen Date: Thu, 28 Nov 2024 11:45:04 +0100 Subject: [PATCH 2/7] add docs --- README.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/README.md b/README.md index 673fb76..9322f99 100644 --- a/README.md +++ b/README.md @@ -332,6 +332,20 @@ FilamentSocialitePlugin::make() ]), ]), ``` +## Visibility + +You can set the visibility of a provider, if it is not visible, buttons will not be rendered. All functionality will still be enabled. + +```php +use DutchCodingCompany\FilamentSocialite\FilamentSocialitePlugin; +use DutchCodingCompany\FilamentSocialite\Provider; + +FilamentSocialitePlugin::make() + ->providers([ + Provider::make('github') + ->visible(fn () => true), + ]), +``` ## Stateless Authentication You can add `stateless` parameters to the provider configuration in the config/services.php config file, for example: From 9eff6823b17b0ef021bef1e59b1809a0214cc708 Mon Sep 17 00:00:00 2001 From: Tom Janssen Date: Thu, 28 Nov 2024 11:47:43 +0100 Subject: [PATCH 3/7] update baseline --- phpstan-baseline.neon | 5 +++++ tests/Fixtures/TestTenantUser.php | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index b905152..3c28ca7 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -15,6 +15,11 @@ parameters: count: 1 path: src/Http/Controllers/SocialiteLoginController.php + - + message: "#^Method DutchCodingCompany\\\\FilamentSocialite\\\\Tests\\\\Fixtures\\\\TestTenantUser\\:\\:teams\\(\\) should return Illuminate\\\\Database\\\\Eloquent\\\\Relations\\\\BelongsToMany\\ but returns Illuminate\\\\Database\\\\Eloquent\\\\Relations\\\\BelongsToMany\\\\.$#" + count: 1 + path: tests/Fixtures/TestTenantUser.php + - message: "#^Call to an undefined method Mockery\\\\ExpectationInterface\\|Mockery\\\\HigherOrderMessage\\:\\:andReturn\\(\\)\\.$#" count: 3 diff --git a/tests/Fixtures/TestTenantUser.php b/tests/Fixtures/TestTenantUser.php index f3e95ac..3d6d80d 100644 --- a/tests/Fixtures/TestTenantUser.php +++ b/tests/Fixtures/TestTenantUser.php @@ -27,7 +27,7 @@ public function getTenants(Panel $panel): Collection } /** - * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany<\DutchCodingCompany\FilamentSocialite\Tests\Fixtures\TestTeam> + * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany<\DutchCodingCompany\FilamentSocialite\Tests\Fixtures\TestTeam, static> */ public function teams(): BelongsToMany { From 9ef65a16e4a5f1587fd5d15f790169a86182671e Mon Sep 17 00:00:00 2001 From: Tom Janssen Date: Thu, 28 Nov 2024 12:18:06 +0100 Subject: [PATCH 4/7] change workflow --- .github/workflows/phpstan.yml | 10 +++++++--- phpstan-baseline.laravel-10.neon | 31 +++++++++++++++++++++++++++++++ phpstan.laravel-10.neon.dist | 12 ++++++++++++ 3 files changed, 50 insertions(+), 3 deletions(-) create mode 100644 phpstan-baseline.laravel-10.neon create mode 100644 phpstan.laravel-10.neon.dist diff --git a/.github/workflows/phpstan.yml b/.github/workflows/phpstan.yml index 70dfe55..d300787 100644 --- a/.github/workflows/phpstan.yml +++ b/.github/workflows/phpstan.yml @@ -6,7 +6,10 @@ on: - '**.php' - '.github/workflows/phpstan.yml' - 'phpstan.neon.dist' + - 'phpstan.laravel-10.neon.dist' pull_request: + branches: + - '**' jobs: phpstan: @@ -15,14 +18,16 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest] - php: [8.3, 8.2, 8.1] + php: [8.4, 8.3, 8.2, 8.1] laravel: [10.*, 11.*] stability: [prefer-stable] include: - laravel: 10.* testbench: 8.* + phpstan_neon: phpstan.laravel-10.neon.dist - laravel: 11.* testbench: 9.* + phpstan_neon: phpstan.neon.dist exclude: - laravel: 11.* php: 8.1 @@ -44,9 +49,8 @@ jobs: run: | composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update composer update --${{ matrix.stability }} --prefer-dist --no-interaction - - name: List Installed Dependencies run: composer show -D - name: Run PHPStan - run: vendor/bin/phpstan --error-format=github + run: vendor/bin/phpstan --error-format=github --configuration=${{ matrix.phpstan_neon }} diff --git a/phpstan-baseline.laravel-10.neon b/phpstan-baseline.laravel-10.neon new file mode 100644 index 0000000..4d514a6 --- /dev/null +++ b/phpstan-baseline.laravel-10.neon @@ -0,0 +1,31 @@ +parameters: + ignoreErrors: + - + message: "#^Class App\\\\Models\\\\User not found\\.$#" + count: 1 + path: src/FilamentSocialitePlugin.php + + - + message: "#^Property DutchCodingCompany\\\\FilamentSocialite\\\\FilamentSocialitePlugin\\:\\:\\$userModelClass \\(class\\-string\\\\) does not accept default value of type string\\.$#" + count: 1 + path: src/FilamentSocialitePlugin.php + + - + message: "#^Parameter \\#1 \\$value of method DutchCodingCompany\\\\FilamentSocialite\\\\Http\\\\Controllers\\\\SocialiteLoginController\\:\\:evaluate\\(\\) expects bool\\|\\(callable\\(\\)\\: bool\\), bool\\|\\(Closure\\(string, Laravel\\\\Socialite\\\\Contracts\\\\User, Illuminate\\\\Contracts\\\\Auth\\\\Authenticatable\\|null\\)\\: bool\\) given\\.$#" + count: 1 + path: src/Http/Controllers/SocialiteLoginController.php + + - + message: "#^Method DutchCodingCompany\\\\FilamentSocialite\\\\Tests\\\\Fixtures\\\\TestTenantUser\\:\\:teams\\(\\) should return Illuminate\\\\Database\\\\Eloquent\\\\Relations\\\\BelongsToMany\\ but returns Illuminate\\\\Database\\\\Eloquent\\\\Relations\\\\BelongsToMany\\\\.$#" + count: 1 + path: tests/Fixtures/TestTenantUser.php + + - + message: "#^Call to an undefined method Mockery\\\\ExpectationInterface\\|Mockery\\\\HigherOrderMessage\\:\\:andReturn\\(\\)\\.$#" + count: 3 + path: tests/TestCase.php + + - + message: "#^Parameter \\#1 \\$callback of static method Illuminate\\\\Database\\\\Eloquent\\\\Factories\\\\Factory\\\\:\\:guessFactoryNamesUsing\\(\\) expects callable\\(class\\-string\\\\)\\: class\\-string\\, Closure\\(string\\)\\: non\\-falsy\\-string given\\.$#" + count: 1 + path: tests/TestCase.php diff --git a/phpstan.laravel-10.neon.dist b/phpstan.laravel-10.neon.dist new file mode 100644 index 0000000..9ef2981 --- /dev/null +++ b/phpstan.laravel-10.neon.dist @@ -0,0 +1,12 @@ +includes: + - ./vendor/larastan/larastan/extension.neon + - ./phpstan-baseline.laravel-10.neon + +parameters: + level: 8 + + paths: + - config + - database + - src + - tests From c813d881234a25094014eb36b577222222c0404f Mon Sep 17 00:00:00 2001 From: Tom Janssen Date: Thu, 28 Nov 2024 12:22:44 +0100 Subject: [PATCH 5/7] change baseline --- phpstan-baseline.laravel-10.neon | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/phpstan-baseline.laravel-10.neon b/phpstan-baseline.laravel-10.neon index 4d514a6..3ff713f 100644 --- a/phpstan-baseline.laravel-10.neon +++ b/phpstan-baseline.laravel-10.neon @@ -15,6 +15,11 @@ parameters: count: 1 path: src/Http/Controllers/SocialiteLoginController.php + - + message: "#^Generic type Illuminate\\\\Database\\\\Eloquent\\\\Relations\\\\BelongsToMany\\ in PHPDoc tag @return specifies 2 template types, but class Illuminate\\\\Database\\\\Eloquent\\\\Relations\\\\BelongsToMany supports only 1\\: TRelatedModel$#" + count: 1 + path: tests/Fixtures/TestTenantUser.php + - message: "#^Method DutchCodingCompany\\\\FilamentSocialite\\\\Tests\\\\Fixtures\\\\TestTenantUser\\:\\:teams\\(\\) should return Illuminate\\\\Database\\\\Eloquent\\\\Relations\\\\BelongsToMany\\ but returns Illuminate\\\\Database\\\\Eloquent\\\\Relations\\\\BelongsToMany\\\\.$#" count: 1 From 1d3b73d54185424c4ff7171ad432fab87133042c Mon Sep 17 00:00:00 2001 From: Tom Janssen Date: Thu, 28 Nov 2024 12:24:27 +0100 Subject: [PATCH 6/7] add null to type --- src/Traits/Callbacks.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Traits/Callbacks.php b/src/Traits/Callbacks.php index e6fe2ce..79a0e35 100644 --- a/src/Traits/Callbacks.php +++ b/src/Traits/Callbacks.php @@ -35,7 +35,7 @@ trait Callbacks /** * @param ?\Closure(string $provider, \Laravel\Socialite\Contracts\User $oauthUser, \DutchCodingCompany\FilamentSocialite\FilamentSocialitePlugin $plugin): \Illuminate\Contracts\Auth\Authenticatable $callback */ - public function createUserUsing(Closure $callback = null): static + public function createUserUsing(?Closure $callback = null): static { $this->createUserUsing = $callback; @@ -99,9 +99,9 @@ public function getRedirectAfterLoginUsing(): Closure } /** - * @param \Closure(string $provider, \Laravel\Socialite\Contracts\User $oauthUser, \DutchCodingCompany\FilamentSocialite\FilamentSocialitePlugin $plugin): ?(\Illuminate\Contracts\Auth\Authenticatable) $callback + * @param ?\Closure(string $provider, \Laravel\Socialite\Contracts\User $oauthUser, \DutchCodingCompany\FilamentSocialite\FilamentSocialitePlugin $plugin): ?(\Illuminate\Contracts\Auth\Authenticatable) $callback */ - public function resolveUserUsing(Closure $callback = null): static + public function resolveUserUsing(?Closure $callback = null): static { $this->resolveUserUsing = $callback; @@ -125,9 +125,9 @@ public function getResolveUserUsing(): Closure } /** - * @param \Closure(\DutchCodingCompany\FilamentSocialite\FilamentSocialitePlugin $plugin, \Laravel\Socialite\Contracts\User $oauthUser): bool $callback + * @param ?\Closure(\DutchCodingCompany\FilamentSocialite\FilamentSocialitePlugin $plugin, \Laravel\Socialite\Contracts\User $oauthUser): bool $callback */ - public function authorizeUserUsing(Closure $callback = null): static + public function authorizeUserUsing(?Closure $callback = null): static { $this->authorizeUserUsing = $callback; From 99d4c84a260e35a83cbe47ca3961f1f1109af9c3 Mon Sep 17 00:00:00 2001 From: Tom Janssen Date: Thu, 28 Nov 2024 12:25:31 +0100 Subject: [PATCH 7/7] change workflow --- .github/workflows/phpstan.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/phpstan.yml b/.github/workflows/phpstan.yml index d300787..49ed3fa 100644 --- a/.github/workflows/phpstan.yml +++ b/.github/workflows/phpstan.yml @@ -8,8 +8,6 @@ on: - 'phpstan.neon.dist' - 'phpstan.laravel-10.neon.dist' pull_request: - branches: - - '**' jobs: phpstan: