1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2025-12-12 19:14:04 +00:00

TenantStorageException

This commit is contained in:
Samuel Štancl 2019-09-15 12:16:45 +02:00
parent 5fb11dfc9f
commit e25a01a997
3 changed files with 10 additions and 5 deletions

View file

@ -6,9 +6,6 @@ namespace Stancl\Tenancy\Contracts;
use Stancl\Tenancy\Tenant;
// todo this class now manages types (json encoding)
// make sure ids are not json encoded
interface StorageDriver
{
public function createTenant(Tenant $tenant): void;

View file

@ -0,0 +1,6 @@
<?php
namespace Stancl\Tenancy\Exceptions;
class TenantStorageException extends \Exception
{}

View file

@ -7,6 +7,7 @@ namespace Stancl\Tenancy;
use ArrayAccess;
use Stancl\Tenancy\Contracts\StorageDriver;
use Stancl\Tenancy\Contracts\UniqueIdentifierGenerator;
use Stancl\Tenancy\Exceptions\TenantStorageException;
/**
* @internal Class is subject to breaking changes in minor and patch versions.
@ -209,8 +210,9 @@ class Tenant implements ArrayAccess
public function put($key, $value = null): self
{
// todo something like if ($this->storage->getIdKey() === $key) throw new Exception("Can't override ID")?
// and the responsibility of not overriding domains is up to the storage driver
if ($this->storage->getIdKey() === $key) {
throw new TenantStorageException("The tenant's id can't be changed.");
}
if (is_array($key)) {
$this->storage->putMany($key);