mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-05 07:54:03 +00:00
Add AuthTenancyBootstrapper.
It'll remove the 'auth.password' singleton from the container. This will ensure a new instance is created when another tenant needs it in the same app lifecycle. Fixes #1052
This commit is contained in:
parent
7d59ff180f
commit
8bc37a3f4e
3 changed files with 48 additions and 5 deletions
|
|
@ -32,6 +32,7 @@ return [
|
||||||
Stancl\Tenancy\Bootstrappers\CacheTenancyBootstrapper::class,
|
Stancl\Tenancy\Bootstrappers\CacheTenancyBootstrapper::class,
|
||||||
Stancl\Tenancy\Bootstrappers\FilesystemTenancyBootstrapper::class,
|
Stancl\Tenancy\Bootstrappers\FilesystemTenancyBootstrapper::class,
|
||||||
Stancl\Tenancy\Bootstrappers\QueueTenancyBootstrapper::class,
|
Stancl\Tenancy\Bootstrappers\QueueTenancyBootstrapper::class,
|
||||||
|
Stancl\Tenancy\Bootstrappers\AuthTenancyBootstrapper::class,
|
||||||
// Stancl\Tenancy\Bootstrappers\RedisTenancyBootstrapper::class, // Note: phpredis is needed
|
// Stancl\Tenancy\Bootstrappers\RedisTenancyBootstrapper::class, // Note: phpredis is needed
|
||||||
],
|
],
|
||||||
|
|
||||||
|
|
|
||||||
21
src/Bootstrappers/AuthTenancyBootstrapper.php
Normal file
21
src/Bootstrappers/AuthTenancyBootstrapper.php
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Stancl\Tenancy\Bootstrappers;
|
||||||
|
|
||||||
|
use Illuminate\Support\Facades\App;
|
||||||
|
use Stancl\Tenancy\Contracts\TenancyBootstrapper;
|
||||||
|
use Stancl\Tenancy\Contracts\Tenant;
|
||||||
|
|
||||||
|
class AuthTenancyBootstrapper implements TenancyBootstrapper
|
||||||
|
{
|
||||||
|
|
||||||
|
public function bootstrap(Tenant $tenant)
|
||||||
|
{
|
||||||
|
// empty
|
||||||
|
}
|
||||||
|
|
||||||
|
public function revert()
|
||||||
|
{
|
||||||
|
App::forgetInstance('auth.password');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -10,6 +10,7 @@ use ReflectionProperty;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
use Stancl\JobPipeline\JobPipeline;
|
use Stancl\JobPipeline\JobPipeline;
|
||||||
|
use Stancl\Tenancy\Bootstrappers\AuthTenancyBootstrapper;
|
||||||
use Stancl\Tenancy\Tests\Etc\Tenant;
|
use Stancl\Tenancy\Tests\Etc\Tenant;
|
||||||
use Illuminate\Support\Facades\Cache;
|
use Illuminate\Support\Facades\Cache;
|
||||||
use Illuminate\Support\Facades\Event;
|
use Illuminate\Support\Facades\Event;
|
||||||
|
|
@ -201,11 +202,31 @@ class BootstrapperTest extends TestCase
|
||||||
$this->assertEquals($expected_storage_path, $new_storage_path);
|
$this->assertEquals($expected_storage_path, $new_storage_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getDiskPrefix(string $disk): string
|
/**
|
||||||
{
|
* @test
|
||||||
/** @var FilesystemAdapter $disk */
|
*/
|
||||||
$disk = Storage::disk($disk);
|
public function it_resets_the_auth_password_singleton_after_tenant_switch(): void {
|
||||||
$adapter = $disk->getAdapter();
|
config(['tenancy.bootstrappers' => [
|
||||||
|
AuthTenancyBootstrapper::class,
|
||||||
|
]]);
|
||||||
|
|
||||||
|
$tenant1 = Tenant::create();
|
||||||
|
$tenant2 = Tenant::create();
|
||||||
|
|
||||||
|
tenancy()->initialize($tenant1);
|
||||||
|
$manager = app('auth.password');
|
||||||
|
tenancy()->end();
|
||||||
|
tenancy()->initialize($tenant2);
|
||||||
|
$manager2 = app('auth.password');
|
||||||
|
|
||||||
|
$this->assertFalse($manager === $manager2);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getDiskPrefix(string $disk): string
|
||||||
|
{
|
||||||
|
/** @var FilesystemAdapter $disk */
|
||||||
|
$disk = Storage::disk($disk);
|
||||||
|
$adapter = $disk->getAdapter();
|
||||||
|
|
||||||
if (! Str::startsWith(app()->version(), '9.')) {
|
if (! Str::startsWith(app()->version(), '9.')) {
|
||||||
return $adapter->getPathPrefix();
|
return $adapter->getPathPrefix();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue