mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-05 14:14:03 +00:00
Merge branch 'master' into broadcasting-tenancy
This commit is contained in:
commit
4ac0bb2252
3 changed files with 14 additions and 1 deletions
|
|
@ -5,6 +5,7 @@ declare(strict_types=1);
|
||||||
namespace Stancl\Tenancy\Bootstrappers;
|
namespace Stancl\Tenancy\Bootstrappers;
|
||||||
|
|
||||||
use Closure;
|
use Closure;
|
||||||
|
use Illuminate\Config\Repository;
|
||||||
use Illuminate\Contracts\Routing\UrlGenerator;
|
use Illuminate\Contracts\Routing\UrlGenerator;
|
||||||
use Stancl\Tenancy\Contracts\TenancyBootstrapper;
|
use Stancl\Tenancy\Contracts\TenancyBootstrapper;
|
||||||
use Stancl\Tenancy\Contracts\Tenant;
|
use Stancl\Tenancy\Contracts\Tenant;
|
||||||
|
|
@ -16,6 +17,7 @@ class UrlTenancyBootstrapper implements TenancyBootstrapper
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
protected UrlGenerator $urlGenerator,
|
protected UrlGenerator $urlGenerator,
|
||||||
|
protected Repository $config,
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -24,12 +26,16 @@ class UrlTenancyBootstrapper implements TenancyBootstrapper
|
||||||
$this->originalRootUrl = $this->urlGenerator->to('/');
|
$this->originalRootUrl = $this->urlGenerator->to('/');
|
||||||
|
|
||||||
if (static::$rootUrlOverride) {
|
if (static::$rootUrlOverride) {
|
||||||
$this->urlGenerator->forceRootUrl((static::$rootUrlOverride)($tenant));
|
$newRootUrl = (static::$rootUrlOverride)($tenant);
|
||||||
|
|
||||||
|
$this->urlGenerator->forceRootUrl($newRootUrl);
|
||||||
|
$this->config->set('app.url', $newRootUrl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function revert(): void
|
public function revert(): void
|
||||||
{
|
{
|
||||||
$this->urlGenerator->forceRootUrl($this->originalRootUrl);
|
$this->urlGenerator->forceRootUrl($this->originalRootUrl);
|
||||||
|
$this->config->set('app.url', $this->originalRootUrl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -476,6 +476,7 @@ test('url bootstrapper overrides the root url when tenancy gets initialized and
|
||||||
});
|
});
|
||||||
|
|
||||||
$baseUrl = url(route('home'));
|
$baseUrl = url(route('home'));
|
||||||
|
config(['app.url' => $baseUrl]);
|
||||||
|
|
||||||
$rootUrlOverride = function (Tenant $tenant) use ($baseUrl) {
|
$rootUrlOverride = function (Tenant $tenant) use ($baseUrl) {
|
||||||
$scheme = str($baseUrl)->before('://');
|
$scheme = str($baseUrl)->before('://');
|
||||||
|
|
@ -493,14 +494,17 @@ test('url bootstrapper overrides the root url when tenancy gets initialized and
|
||||||
|
|
||||||
expect(url(route('home')))->toBe($baseUrl);
|
expect(url(route('home')))->toBe($baseUrl);
|
||||||
expect(URL::to('/'))->toBe($baseUrl);
|
expect(URL::to('/'))->toBe($baseUrl);
|
||||||
|
expect(config('app.url'))->toBe($baseUrl);
|
||||||
|
|
||||||
tenancy()->initialize($tenant);
|
tenancy()->initialize($tenant);
|
||||||
|
|
||||||
expect(url(route('home')))->toBe($tenantUrl);
|
expect(url(route('home')))->toBe($tenantUrl);
|
||||||
expect(URL::to('/'))->toBe($tenantUrl);
|
expect(URL::to('/'))->toBe($tenantUrl);
|
||||||
|
expect(config('app.url'))->toBe($tenantUrl);
|
||||||
|
|
||||||
tenancy()->end();
|
tenancy()->end();
|
||||||
|
|
||||||
expect(url(route('home')))->toBe($baseUrl);
|
expect(url(route('home')))->toBe($baseUrl);
|
||||||
expect(URL::to('/'))->toBe($baseUrl);
|
expect(URL::to('/'))->toBe($baseUrl);
|
||||||
|
expect(config('app.url'))->toBe($baseUrl);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ use Stancl\Tenancy\Facades\GlobalCache;
|
||||||
use Stancl\Tenancy\TenancyServiceProvider;
|
use Stancl\Tenancy\TenancyServiceProvider;
|
||||||
use Stancl\Tenancy\Bootstrappers\RedisTenancyBootstrapper;
|
use Stancl\Tenancy\Bootstrappers\RedisTenancyBootstrapper;
|
||||||
use Stancl\Tenancy\Bootstrappers\BroadcastTenancyBootstrapper;
|
use Stancl\Tenancy\Bootstrappers\BroadcastTenancyBootstrapper;
|
||||||
|
use Stancl\Tenancy\Bootstrappers\UrlTenancyBootstrapper;
|
||||||
use Stancl\Tenancy\Bootstrappers\MailTenancyBootstrapper;
|
use Stancl\Tenancy\Bootstrappers\MailTenancyBootstrapper;
|
||||||
|
|
||||||
abstract class TestCase extends \Orchestra\Testbench\TestCase
|
abstract class TestCase extends \Orchestra\Testbench\TestCase
|
||||||
|
|
@ -107,6 +108,7 @@ abstract class TestCase extends \Orchestra\Testbench\TestCase
|
||||||
'tenancy.bootstrappers.redis' => RedisTenancyBootstrapper::class, // todo1 change this to []? two tests in TenantDatabaseManagerTest are failing with that
|
'tenancy.bootstrappers.redis' => RedisTenancyBootstrapper::class, // todo1 change this to []? two tests in TenantDatabaseManagerTest are failing with that
|
||||||
'tenancy.bootstrappers.broadcast' => BroadcastTenancyBootstrapper::class, // todo1 change this to []? two tests in TenantDatabaseManagerTest are failing with that
|
'tenancy.bootstrappers.broadcast' => BroadcastTenancyBootstrapper::class, // todo1 change this to []? two tests in TenantDatabaseManagerTest are failing with that
|
||||||
'tenancy.bootstrappers.mail' => MailTenancyBootstrapper::class,
|
'tenancy.bootstrappers.mail' => MailTenancyBootstrapper::class,
|
||||||
|
'tenancy.bootstrappers.url' => UrlTenancyBootstrapper::class,
|
||||||
'queue.connections.central' => [
|
'queue.connections.central' => [
|
||||||
'driver' => 'sync',
|
'driver' => 'sync',
|
||||||
'central' => true,
|
'central' => true,
|
||||||
|
|
@ -118,6 +120,7 @@ abstract class TestCase extends \Orchestra\Testbench\TestCase
|
||||||
$app->singleton(RedisTenancyBootstrapper::class); // todo (Samuel) use proper approach eg config for singleton registration
|
$app->singleton(RedisTenancyBootstrapper::class); // todo (Samuel) use proper approach eg config for singleton registration
|
||||||
$app->singleton(BroadcastTenancyBootstrapper::class);
|
$app->singleton(BroadcastTenancyBootstrapper::class);
|
||||||
$app->singleton(MailTenancyBootstrapper::class);
|
$app->singleton(MailTenancyBootstrapper::class);
|
||||||
|
$app->singleton(UrlTenancyBootstrapper::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getPackageProviders($app)
|
protected function getPackageProviders($app)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue