1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2025-12-12 20:34:03 +00:00

[1.8.0] Custom id scheme (#108)

* Add UniqueIdentifierGenerators

* Apply fixes from StyleCI
This commit is contained in:
Samuel Štancl 2019-08-21 20:29:53 +02:00 committed by GitHub
parent 787063ed73
commit f590e2ce2a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 48 additions and 3 deletions

View file

@ -5,6 +5,7 @@ namespace Stancl\Tenancy;
use Stancl\Tenancy\Interfaces\StorageDriver;
use Stancl\Tenancy\Traits\BootstrapsTenancy;
use Illuminate\Contracts\Foundation\Application;
use Stancl\Tenancy\Interfaces\UniqueIdentifierGenerator;
use Stancl\Tenancy\Exceptions\CannotChangeUuidOrDomainException;
use Stancl\Tenancy\Exceptions\TenantCouldNotBeIdentifiedException;
@ -33,6 +34,13 @@ final class TenantManager
*/
public $database;
/**
* Unique identifier generator.
*
* @var UniqueIdentifierGenerator
*/
protected $generator;
/**
* Current tenant.
*
@ -40,11 +48,12 @@ final class TenantManager
*/
public $tenant = [];
public function __construct(Application $app, StorageDriver $storage, DatabaseManager $database)
public function __construct(Application $app, StorageDriver $storage, DatabaseManager $database, UniqueIdentifierGenerator $generator)
{
$this->app = $app;
$this->storage = $storage;
$this->database = $database;
$this->generator = $generator;
}
public function init(string $domain = null): array
@ -87,7 +96,7 @@ final class TenantManager
throw new \Exception("Domain $domain is already occupied by tenant $id.");
}
$tenant = $this->storage->createTenant($domain, (string) \Webpatser\Uuid\Uuid::generate(1, $domain));
$tenant = $this->storage->createTenant($domain, $this->generateUniqueIdentifier($domain, $data));
if ($this->useJson()) {
$tenant = $this->jsonDecodeArrayValues($tenant);
}
@ -103,6 +112,11 @@ final class TenantManager
return $tenant;
}
public function generateUniqueIdentifier(string $domain, array $data)
{
return $this->generator->handle($domain, $data);
}
public function delete(string $uuid): bool
{
return $this->storage->deleteTenant($uuid);