1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2026-02-05 06:24:04 +00:00

Add bootstrapFeatures static property and method

This commit is contained in:
lukinovec 2023-02-20 15:39:23 +01:00
parent 258582112c
commit 654a988af1

View file

@ -17,6 +17,8 @@ use Stancl\Tenancy\Resolvers\DomainTenantResolver;
class TenancyServiceProvider extends ServiceProvider
{
public static $bootstrapFeatures = true;
/* Register services. */
public function register(): void
{
@ -27,18 +29,8 @@ class TenancyServiceProvider extends ServiceProvider
// Make sure Tenancy is stateful.
$this->app->singleton(Tenancy::class);
$this->app->resolving(Tenancy::class, function (Tenancy $tenancy, $app) {
foreach ($this->app['config']['tenancy.features'] ?? [] as $feature) {
if (! $feature::alwaysBootstrap()) { // avoid bootstrapping already bootstrapped features
$this->app[$feature]->bootstrap();
}
}
});
foreach ($this->app['config']['tenancy.features'] ?? [] as $feature) {
if ($feature::alwaysBootstrap()) {
$this->app[$feature]->bootstrap();
}
if (static::bootstrapFeatures()) {
$this->bootstrapFeatures();
}
// Make it possible to inject the current tenant by typehinting the Tenant contract.
@ -149,4 +141,21 @@ class TenancyServiceProvider extends ServiceProvider
return $instance;
});
}
public static function bootstrapFeatures(): void
{
foreach (config('tenancy.features') ?? [] as $feature) {
if ($feature::alwaysBootstrap()) {
app($feature)->bootstrap();
}
}
app()->resolving(Tenancy::class, function (Tenancy $tenancy, $app) {
foreach (config('tenancy.features') ?? [] as $feature) {
if (! $feature::alwaysBootstrap()) { // Avoid bootstrapping already bootstrapped features
$app[$feature]->bootstrap();
}
}
});
}
}