From e69a8f597fec96c67378d678f03ffb962a6e2d16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20=C5=A0tancl?= Date: Sun, 15 Sep 2019 09:24:38 +0200 Subject: [PATCH] Private Tenant constructor --- src/Tenant.php | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/Tenant.php b/src/Tenant.php index df2e750b..a760dc1b 100644 --- a/src/Tenant.php +++ b/src/Tenant.php @@ -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)) {