mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-05 09:04:03 +00:00
Add bootstrapFeatures static property and method
This commit is contained in:
parent
258582112c
commit
654a988af1
1 changed files with 21 additions and 12 deletions
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue