diff --git a/config/permission.php b/config/permission.php index 9c0532d89..2a520f351 100644 --- a/config/permission.php +++ b/config/permission.php @@ -104,9 +104,8 @@ 'register_permission_check_method' => true, /* - * When set to true, the Spatie\Permission\Listeners\OctaneReloadPermissions listener will be registered - * on the Laravel\Octane\Events\OperationTerminated event, this will refresh permissions on every - * TickTerminated, TaskTerminated and RequestTerminated + * When set to true, Laravel\Octane\Events\OperationTerminated event listener will be registered + * this will refresh permissions on every TickTerminated, TaskTerminated and RequestTerminated * NOTE: This should not be needed in most cases, but an Octane/Vapor combination benefited from it. */ 'register_octane_reset_listener' => false, diff --git a/src/Listeners/OctaneReloadPermissions.php b/src/Listeners/OctaneReloadPermissions.php deleted file mode 100644 index 6f4544e5e..000000000 --- a/src/Listeners/OctaneReloadPermissions.php +++ /dev/null @@ -1,13 +0,0 @@ -sandbox->make(PermissionRegistrar::class)->clearPermissionsCollection(); - } -} diff --git a/src/PermissionRegistrar.php b/src/PermissionRegistrar.php index 0443eb026..051e48b0f 100644 --- a/src/PermissionRegistrar.php +++ b/src/PermissionRegistrar.php @@ -98,7 +98,7 @@ protected function getCacheStoreFromConfig(): Repository /** * Set the team id for teams/groups support, this id is used when querying permissions/roles * - * @param int|string|\Illuminate\Database\Eloquent\Model $id + * @param int|string|\Illuminate\Database\Eloquent\Model|null $id */ public function setPermissionsTeamId($id): void { diff --git a/src/PermissionServiceProvider.php b/src/PermissionServiceProvider.php index b68f31984..a9011cd2b 100644 --- a/src/PermissionServiceProvider.php +++ b/src/PermissionServiceProvider.php @@ -13,7 +13,6 @@ use Illuminate\View\Compilers\BladeCompiler; use Spatie\Permission\Contracts\Permission as PermissionContract; use Spatie\Permission\Contracts\Role as RoleContract; -use Spatie\Permission\Listeners\OctaneReloadPermissions; class PermissionServiceProvider extends ServiceProvider { @@ -91,17 +90,25 @@ protected function registerCommands(): void protected function registerOctaneListener(): void { - if ($this->app->runningInConsole() || ! $this->app['config']->get('permission.register_octane_reset_listener')) { + if ($this->app->runningInConsole() || ! $this->app['config']->get('octane.listeners')) { return; } - if (! $this->app['config']->get('octane.listeners')) { + $dispatcher = $this->app[Dispatcher::class]; + // @phpstan-ignore-next-line + $dispatcher->listen(function (\Laravel\Octane\Events\OperationTerminated $event) { + // @phpstan-ignore-next-line + $event->sandbox->make(PermissionRegistrar::class)->setPermissionsTeamId(null); + }); + + if (! $this->app['config']->get('permission.register_octane_reset_listener')) { return; } - - $dispatcher = $this->app[Dispatcher::class]; // @phpstan-ignore-next-line - $dispatcher->listen(\Laravel\Octane\Events\OperationTerminated::class, OctaneReloadPermissions::class); + $dispatcher->listen(function (\Laravel\Octane\Events\OperationTerminated $event) { + // @phpstan-ignore-next-line + $event->sandbox->make(PermissionRegistrar::class)->clearPermissionsCollection(); + }); } protected function registerModelBindings(): void