mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-15 23:44:02 +00:00
Private Tenant constructor
This commit is contained in:
parent
fd3cf0a2b3
commit
e69a8f597f
1 changed files with 9 additions and 8 deletions
|
|
@ -5,6 +5,7 @@ declare(strict_types=1);
|
||||||
namespace Stancl\Tenancy;
|
namespace Stancl\Tenancy;
|
||||||
|
|
||||||
use ArrayAccess;
|
use ArrayAccess;
|
||||||
|
use Illuminate\Foundation\Application;
|
||||||
use Stancl\Tenancy\Contracts\StorageDriver;
|
use Stancl\Tenancy\Contracts\StorageDriver;
|
||||||
use Stancl\Tenancy\Contracts\UniqueIdentifierGenerator;
|
use Stancl\Tenancy\Contracts\UniqueIdentifierGenerator;
|
||||||
|
|
||||||
|
|
@ -45,21 +46,21 @@ class Tenant implements ArrayAccess
|
||||||
*/
|
*/
|
||||||
protected $persisted = false;
|
protected $persisted = false;
|
||||||
|
|
||||||
public function __construct(StorageDriver $storage, TenantManager $tenantManager, UniqueIdentifierGenerator $idGenerator)
|
protected function __construct(Application $app)
|
||||||
{
|
{
|
||||||
$this->storage = $storage;
|
$this->storage = $app[StorageDriver::class];
|
||||||
$this->manager = $tenantManager;
|
$this->manager = $app[TenantManager::class];
|
||||||
$this->idGenerator = $idGenerator;
|
$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
|
public static function fromStorage(array $data): self
|
||||||
{
|
{
|
||||||
return app(static::class)->withData($data)->persisted();
|
return static::new()->withData($data)->persisted();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function persisted()
|
protected function persisted()
|
||||||
|
|
@ -142,7 +143,7 @@ class Tenant implements ArrayAccess
|
||||||
|
|
||||||
public function put($key, $value = null): self
|
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
|
// and the responsibility of not overriding domains is up to the storage driver
|
||||||
|
|
||||||
if (is_array($key)) {
|
if (is_array($key)) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue