diff --git a/assets/config.php b/assets/config.php index 3bd68b97..3778e107 100644 --- a/assets/config.php +++ b/assets/config.php @@ -283,9 +283,6 @@ return [ // Stancl\Tenancy\Features\TelescopeTags::class, // Stancl\Tenancy\Features\UniversalRoutes::class, // Stancl\Tenancy\Features\TenantConfig::class, // https://tenancyforlaravel.com/docs/v3/features/tenant-config - ], - - 'tenant_unaware_features' => [ // Stancl\Tenancy\Features\CrossDomainRedirect::class, // https://tenancyforlaravel.com/docs/v3/features/cross-domain-redirect ], diff --git a/src/Contracts/Feature.php b/src/Contracts/Feature.php index 74289981..25363cf5 100644 --- a/src/Contracts/Feature.php +++ b/src/Contracts/Feature.php @@ -4,10 +4,8 @@ declare(strict_types=1); namespace Stancl\Tenancy\Contracts; -use Stancl\Tenancy\Tenancy; - /** Additional features, like Telescope tags and tenant redirects. */ interface Feature { - public function bootstrap(Tenancy $tenancy): void; + public function bootstrap(): void; } diff --git a/src/Contracts/TenantUnwareFeature.php b/src/Contracts/TenantUnwareFeature.php deleted file mode 100644 index 498774c9..00000000 --- a/src/Contracts/TenantUnwareFeature.php +++ /dev/null @@ -1,10 +0,0 @@ -macro('impersonate', function (Tenant $tenant, string $userId, string $redirectUrl, string $authGuard = null): ImpersonationToken { + Tenancy::macro('impersonate', function (Tenant $tenant, string $userId, string $redirectUrl, string $authGuard = null): ImpersonationToken { return ImpersonationToken::create([ Tenancy::tenantKeyColumn() => $tenant->getTenantKey(), 'user_id' => $userId, diff --git a/src/Listeners/BootstrapFeatures.php b/src/Listeners/BootstrapFeatures.php new file mode 100644 index 00000000..8ebbd6ec --- /dev/null +++ b/src/Listeners/BootstrapFeatures.php @@ -0,0 +1,23 @@ +app['config']['tenancy.features'] ?? [] as $feature) { + $this->app[$feature]->bootstrap($event->tenancy); + } + } +} diff --git a/src/TenancyServiceProvider.php b/src/TenancyServiceProvider.php index f4e18dba..3a27c5da 100644 --- a/src/TenancyServiceProvider.php +++ b/src/TenancyServiceProvider.php @@ -27,16 +27,7 @@ class TenancyServiceProvider extends ServiceProvider // Make sure Tenancy is stateful. $this->app->singleton(Tenancy::class); - // Make sure features are bootstrapped as soon as Tenancy is instantiated. - $this->app->extend(Tenancy::class, function (Tenancy $tenancy) { - foreach ($this->app['config']['tenancy.features'] ?? [] as $feature) { - $this->app[$feature]->bootstrap($tenancy); - } - - return $tenancy; - }); - - foreach ($this->app['config']['tenancy.tenant_unaware_features'] ?? [] as $feature) { + foreach ($this->app['config']['tenancy.features'] ?? [] as $feature) { $this->app[$feature]->bootstrap(); }