From 633a2ee9e64fcd5fa9847b33d50324934150205a Mon Sep 17 00:00:00 2001 From: Chris Brown Date: Sun, 24 Dec 2023 01:53:21 -0500 Subject: [PATCH] Register package information in About command output --- src/PermissionServiceProvider.php | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/PermissionServiceProvider.php b/src/PermissionServiceProvider.php index a9011cd2..e3290baf 100644 --- a/src/PermissionServiceProvider.php +++ b/src/PermissionServiceProvider.php @@ -2,10 +2,12 @@ namespace Spatie\Permission; +use Composer\InstalledVersions; use Illuminate\Contracts\Auth\Access\Gate; use Illuminate\Contracts\Events\Dispatcher; use Illuminate\Contracts\Foundation\Application; use Illuminate\Filesystem\Filesystem; +use Illuminate\Foundation\Console\AboutCommand; use Illuminate\Routing\Route; use Illuminate\Support\Arr; use Illuminate\Support\Collection; @@ -38,6 +40,8 @@ public function boot() }); $this->app->singleton(PermissionRegistrar::class); + + $this->registerAbout(); } public function register() @@ -181,4 +185,27 @@ protected function getMigrationFileName(string $migrationFileName): string ->push($this->app->databasePath()."/migrations/{$timestamp}_{$migrationFileName}") ->first(); } + + protected function registerAbout(): void + { + if (!class_exists(InstalledVersions::class)) { + return; + } + + $features = [ + 'Teams' => 'teams', + 'Wildcard-Permissions' => 'enable_wildcard_permission', + 'Octane-Listener' => 'register_octane_reset_listener', + 'Passport' => 'use_passport_client_credentials', + ]; + + AboutCommand::add('Spatie Permissions', fn () => [ + 'Features Enabled' => collect($features) + ->filter(fn (string $feature, string $name): bool => $this->app['config']->get("permission.{$feature}")) + ->keys() + ->whenEmpty(fn (Collection $collection) => $collection->push('Default')) + ->join(', '), + 'Version' => InstalledVersions::getPrettyVersion('spatie/laravel-permission'), + ]); + } }