1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2026-02-06 01:14: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

@ -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
],

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.

View file

@ -7,9 +7,7 @@ use Stancl\Tenancy\Features\CrossDomainRedirect;
use Stancl\Tenancy\Tests\Etc\Tenant;
test('tenant redirect macro replaces only the hostname', function () {
config([
'tenancy.tenant_unaware_features' => [CrossDomainRedirect::class],
]);
// `CrossDomainRedirect` feature already enabled in config
Route::get('/foobar', function () {
return 'Foo';