Skip to content

Commit

Permalink
Register package information in About command output
Browse files Browse the repository at this point in the history
  • Loading branch information
drbyte committed Dec 24, 2023
1 parent f518fd5 commit 10045a2
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/PermissionServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -38,6 +40,8 @@ public function boot()
});

$this->app->singleton(PermissionRegistrar::class);

$this->registerAbout();
}

public function register()
Expand Down Expand Up @@ -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) || ! class_exists('AboutCommand::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'),
]);
}
}

0 comments on commit 10045a2

Please sign in to comment.