mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-06 05:04:03 +00:00
remove tenant_unaware_features key and use static function
This commit is contained in:
parent
250f927d33
commit
be6b2f8248
9 changed files with 35 additions and 9 deletions
|
|
@ -283,9 +283,6 @@ return [
|
||||||
// Stancl\Tenancy\Features\TelescopeTags::class,
|
// Stancl\Tenancy\Features\TelescopeTags::class,
|
||||||
// Stancl\Tenancy\Features\UniversalRoutes::class,
|
// Stancl\Tenancy\Features\UniversalRoutes::class,
|
||||||
// Stancl\Tenancy\Features\TenantConfig::class, // https://tenancyforlaravel.com/docs/v3/features/tenant-config
|
// 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
|
Stancl\Tenancy\Features\CrossDomainRedirect::class, // https://tenancyforlaravel.com/docs/v3/features/cross-domain-redirect
|
||||||
],
|
],
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,4 +8,6 @@ namespace Stancl\Tenancy\Contracts;
|
||||||
interface Feature
|
interface Feature
|
||||||
{
|
{
|
||||||
public function bootstrap(): void;
|
public function bootstrap(): void;
|
||||||
|
|
||||||
|
public static function alwaysBootstrap(): bool;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,4 +27,9 @@ class CrossDomainRedirect implements Feature
|
||||||
return $this;
|
return $this;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function alwaysBootstrap(): bool
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -32,4 +32,9 @@ class TelescopeTags implements Feature
|
||||||
return $tags;
|
return $tags;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function alwaysBootstrap(): bool
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -69,4 +69,9 @@ class TenantConfig implements Feature
|
||||||
$this->config->set($key, $value);
|
$this->config->set($key, $value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function alwaysBootstrap(): bool
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -60,4 +60,9 @@ class UniversalRoutes implements Feature
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function alwaysBootstrap(): bool
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -50,4 +50,9 @@ class UserImpersonation implements Feature
|
||||||
|
|
||||||
return redirect($token->redirect_url);
|
return redirect($token->redirect_url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function alwaysBootstrap(): bool
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -29,13 +29,17 @@ class TenancyServiceProvider extends ServiceProvider
|
||||||
|
|
||||||
$this->app->resolving(Tenancy::class, function (Tenancy $tenancy, $app) {
|
$this->app->resolving(Tenancy::class, function (Tenancy $tenancy, $app) {
|
||||||
foreach ($this->app['config']['tenancy.features'] ?? [] as $feature) {
|
foreach ($this->app['config']['tenancy.features'] ?? [] as $feature) {
|
||||||
|
if (! $feature::alwaysBootstrap()) { // avoid bootstrapping already bootstrapped features
|
||||||
$this->app[$feature]->bootstrap();
|
$this->app[$feature]->bootstrap();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
foreach ($this->app['config']['tenancy.tenant_unaware_features'] ?? [] as $feature) {
|
foreach ($this->app['config']['tenancy.features'] ?? [] as $feature) {
|
||||||
|
if ($feature::alwaysBootstrap()) {
|
||||||
$this->app[$feature]->bootstrap();
|
$this->app[$feature]->bootstrap();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Make it possible to inject the current tenant by typehinting the Tenant contract.
|
// Make it possible to inject the current tenant by typehinting the Tenant contract.
|
||||||
$this->app->bind(Tenant::class, function ($app) {
|
$this->app->bind(Tenant::class, function ($app) {
|
||||||
|
|
|
||||||
|
|
@ -7,9 +7,7 @@ use Stancl\Tenancy\Features\CrossDomainRedirect;
|
||||||
use Stancl\Tenancy\Tests\Etc\Tenant;
|
use Stancl\Tenancy\Tests\Etc\Tenant;
|
||||||
|
|
||||||
test('tenant redirect macro replaces only the hostname', function () {
|
test('tenant redirect macro replaces only the hostname', function () {
|
||||||
config([
|
// `CrossDomainRedirect` feature already enabled in config
|
||||||
'tenancy.tenant_unaware_features' => [CrossDomainRedirect::class],
|
|
||||||
]);
|
|
||||||
|
|
||||||
Route::get('/foobar', function () {
|
Route::get('/foobar', function () {
|
||||||
return 'Foo';
|
return 'Foo';
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue