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

Private Tenant constructor

This commit is contained in:
Samuel Štancl 2019-09-15 09:24:38 +02:00
parent fd3cf0a2b3
commit e69a8f597f

View file

@ -5,6 +5,7 @@ declare(strict_types=1);
namespace Stancl\Tenancy;
use ArrayAccess;
use Illuminate\Foundation\Application;
use Stancl\Tenancy\Contracts\StorageDriver;
use Stancl\Tenancy\Contracts\UniqueIdentifierGenerator;
@ -45,21 +46,21 @@ class Tenant implements ArrayAccess
*/
protected $persisted = false;
public function __construct(StorageDriver $storage, TenantManager $tenantManager, UniqueIdentifierGenerator $idGenerator)
protected function __construct(Application $app)
{
$this->storage = $storage;
$this->manager = $tenantManager;
$this->idGenerator = $idGenerator;
$this->storage = $app[StorageDriver::class];
$this->manager = $app[TenantManager::class];
$this->idGenerator = $app[UniqueIdentifierGenerator::class];
}
public static function new(): self
public static function new(Application $app = null): self
{
return app(static::class);
return new static($app ?? app());
}
public static function fromStorage(array $data): self
{
return app(static::class)->withData($data)->persisted();
return static::new()->withData($data)->persisted();
}
protected function persisted()
@ -142,7 +143,7 @@ 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")? or should it be overridable?
// 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 (is_array($key)) {