1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2026-02-05 20:54:03 +00:00

remove tenant_unaware_features key and use static function

This commit is contained in:
Abrar Ahmad 2022-11-28 11:23:30 +05:00
parent 250f927d33
commit be6b2f8248
9 changed files with 35 additions and 9 deletions

View file

@ -8,4 +8,6 @@ namespace Stancl\Tenancy\Contracts;
interface Feature
{
public function bootstrap(): void;
public static function alwaysBootstrap(): bool;
}

View file

@ -27,4 +27,9 @@ class CrossDomainRedirect implements Feature
return $this;
});
}
public static function alwaysBootstrap(): bool
{
return true;
}
}

View file

@ -32,4 +32,9 @@ class TelescopeTags implements Feature
return $tags;
});
}
public static function alwaysBootstrap(): bool
{
return false;
}
}

View file

@ -69,4 +69,9 @@ class TenantConfig implements Feature
$this->config->set($key, $value);
}
}
public static function alwaysBootstrap(): bool
{
return false;
}
}

View file

@ -60,4 +60,9 @@ class UniversalRoutes implements Feature
return false;
}
public static function alwaysBootstrap(): bool
{
return false;
}
}

View file

@ -50,4 +50,9 @@ class UserImpersonation implements Feature
return redirect($token->redirect_url);
}
public static function alwaysBootstrap(): bool
{
return false;
}
}

View file

@ -29,12 +29,16 @@ class TenancyServiceProvider extends ServiceProvider
$this->app->resolving(Tenancy::class, function (Tenancy $tenancy, $app) {
foreach ($this->app['config']['tenancy.features'] ?? [] as $feature) {
$this->app[$feature]->bootstrap();
if (! $feature::alwaysBootstrap()) { // avoid bootstrapping already bootstrapped features
$this->app[$feature]->bootstrap();
}
}
});
foreach ($this->app['config']['tenancy.tenant_unaware_features'] ?? [] as $feature) {
$this->app[$feature]->bootstrap();
foreach ($this->app['config']['tenancy.features'] ?? [] as $feature) {
if ($feature::alwaysBootstrap()) {
$this->app[$feature]->bootstrap();
}
}
// Make it possible to inject the current tenant by typehinting the Tenant contract.