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

Add methods to Tenant contract

This commit is contained in:
Samuel Štancl 2020-05-10 20:20:44 +02:00
parent 494d274798
commit 2492345280
3 changed files with 18 additions and 7 deletions

View file

@ -3,4 +3,7 @@
namespace Stancl\Tenancy\Contracts;
interface Tenant
{}
{
public function getTenantKeyName(): string;
public function getTenantKey(): string;
}

View file

@ -7,7 +7,6 @@ use Stancl\Tenancy\DatabaseConfig;
use Stancl\Tenancy\Events;
use Stancl\Tenancy\Contracts;
// todo use a contract
// todo @property
class Tenant extends Model implements Contracts\Tenant
{
@ -16,6 +15,17 @@ class Tenant extends Model implements Contracts\Tenant
}
public $primaryKey = 'id';
public $guarded = [];
public function getTenantKeyName(): string
{
return 'id';
}
public function getTenantKey(): string
{
return $this->getAttribute($this->getTenantKeyName());
}
public function getCasts()
{
@ -29,8 +39,6 @@ class Tenant extends Model implements Contracts\Tenant
return config('tenancy.id_generator') === null;
}
public $guarded = [];
public static function internalPrefix(): string
{
return config('tenancy.database_prefix');

View file

@ -3,7 +3,7 @@
namespace Stancl\Tenancy;
use Stancl\Tenancy\Contracts\TenancyBootstrapper;
use Stancl\Tenancy\Database\Models\Tenant; // todo contract
use Stancl\Tenancy\Contracts\Tenant;
class Tenancy
{
@ -18,8 +18,7 @@ class Tenancy
public function initialize(Tenant $tenant): void
{
// todo the id is something that should be on the contract, with a method
if ($this->initialized && $this->tenant->id === $tenant->id) {
if ($this->initialized && $this->tenant->getTenantKey() === $tenant->getTenantKey()) {
return;
}
@ -42,6 +41,7 @@ class Tenancy
/** @return TenancyBootstrapper[] */
public function getBootstrappers(): array
{
// If no callback for getting bootstrappers is set, we just return all of them.
$resolve = static::$getBootstrappers ?? function (Tenant $tenant) {
return config('tenancy.bootstrappers');
};