mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-05 23:24:03 +00:00
add TenantModel interface, fix issues pointed out by @carlos-mora
This commit is contained in:
parent
de025a6a4d
commit
4d7c6b6683
5 changed files with 59 additions and 37 deletions
|
|
@ -2,11 +2,16 @@
|
|||
|
||||
namespace Stancl\Tenancy\StorageDrivers;
|
||||
|
||||
use Stancl\Tenancy\Tenant;
|
||||
use Stancl\Tenancy\Interfaces\StorageDriver;
|
||||
use Stancl\Tenancy\Interfaces\TenantModel;
|
||||
|
||||
class DatabaseStorageDriver implements StorageDriver
|
||||
{
|
||||
public function __construct(TenantModel $tenant)
|
||||
{
|
||||
$this->tenant = $tenant;
|
||||
}
|
||||
|
||||
public function identifyTenant(string $domain): array
|
||||
{
|
||||
$id = $this->getTenantIdByDomain($domain);
|
||||
|
|
@ -26,50 +31,50 @@ class DatabaseStorageDriver implements StorageDriver
|
|||
*/
|
||||
public function getTenantById(string $uuid, array $fields = []): array
|
||||
{
|
||||
return Tenant::find($uuid)->only($fields)->toArray();
|
||||
return $this->tenant->find($uuid)->only($fields);
|
||||
}
|
||||
|
||||
public function getTenantIdByDomain(string $domain): ?string
|
||||
{
|
||||
return Tenant::where('domain', $domain)->first()->uuid ?? null;
|
||||
return $this->tenant->where('domain', $domain)->first()->uuid ?? null;
|
||||
}
|
||||
|
||||
public function createTenant(string $domain, string $uuid): array
|
||||
{
|
||||
return Tenant::create(['uuid' => $uuid, 'domain' => $domain])->toArray();
|
||||
return $this->tenant->create(['uuid' => $uuid, 'domain' => $domain])->toArray();
|
||||
}
|
||||
|
||||
public function deleteTenant(string $id): bool
|
||||
{
|
||||
return Tenant::find($id)->delete();
|
||||
return $this->tenant->find($id)->delete();
|
||||
}
|
||||
|
||||
public function getAllTenants(array $uuids = []): array
|
||||
{
|
||||
return Tenant::all()->map(function ($model) {
|
||||
return $this->tenant->all()->map(function ($model) {
|
||||
return $model->toArray();
|
||||
})->toArray();
|
||||
}
|
||||
|
||||
public function get(string $uuid, string $key)
|
||||
{
|
||||
return Tenant::find($uuid)->get($key);
|
||||
return $this->tenant->find($uuid)->get($key);
|
||||
}
|
||||
|
||||
public function getMany(string $uuid, array $keys): array
|
||||
{
|
||||
return Tenant::getMany($keys);
|
||||
return $this->tenant->getMany($keys);
|
||||
}
|
||||
|
||||
public function put(string $uuid, string $key, $value)
|
||||
{
|
||||
return Tenant::find($uuid)->put($key, $value);
|
||||
return $this->tenant->find($uuid)->put($key, $value);
|
||||
}
|
||||
|
||||
public function putMany(string $uuid, array $values): array
|
||||
{
|
||||
foreach ($values as $key => $value) {
|
||||
Tenant::find($uuid)->put($key, $value);
|
||||
$this->tenant->find($uuid)->put($key, $value);
|
||||
}
|
||||
|
||||
return $values;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue