Skip to content

Commit 9615099

Browse files
committed
Add tenant per document flag
1 parent 06fab72 commit 9615099

File tree

2 files changed

+56
-3
lines changed

2 files changed

+56
-3
lines changed

src/Database/Adapter.php

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ abstract class Adapter
1818

1919
protected ?int $tenant = null;
2020

21+
protected bool $tenantPerDocument = false;
22+
2123
protected int $inTransaction = 0;
2224

2325
/**
@@ -190,6 +192,34 @@ public function getTenant(): ?int
190192
return $this->tenant;
191193
}
192194

195+
/**
196+
* Set Tenant Per Document.
197+
*
198+
* Set whether to use a different tenant for each document
199+
*
200+
* @param bool $tenantPerDocument
201+
*
202+
* @return bool
203+
*/
204+
public function setTenantPerDocument(bool $tenantPerDocument): bool
205+
{
206+
$this->tenantPerDocument = $tenantPerDocument;
207+
208+
return true;
209+
}
210+
211+
/**
212+
* Get Tenant Per Document.
213+
*
214+
* Get whether to use a different tenant for each document
215+
*
216+
* @return bool
217+
*/
218+
public function getTenantPerDocument(): bool
219+
{
220+
return $this->tenantPerDocument;
221+
}
222+
193223
/**
194224
* Set metadata for query comments
195225
*
@@ -261,7 +291,7 @@ abstract public function setTimeout(int $milliseconds, string $event = Database:
261291
public function clearTimeout(string $event): void
262292
{
263293
// Clear existing callback
264-
$this->before($event, 'timeout', null);
294+
$this->before($event, 'timeout');
265295
}
266296

267297
/**
@@ -301,7 +331,6 @@ abstract public function rollbackTransaction(): bool;
301331
* Check if a transaction is active.
302332
*
303333
* @return bool
304-
* @throws DatabaseException
305334
*/
306335
public function inTransaction(): bool
307336
{
@@ -482,7 +511,7 @@ abstract public function createAttribute(string $collection, string $id, string
482511
* @param int $size
483512
* @param bool $signed
484513
* @param bool $array
485-
* @param string $newKey
514+
* @param string|null $newKey
486515
*
487516
* @return bool
488517
*/
@@ -620,6 +649,7 @@ abstract public function createDocuments(string $collection, array $documents):
620649
* Update Document
621650
*
622651
* @param string $collection
652+
* @param string $id
623653
* @param Document $document
624654
*
625655
* @return Document

src/Database/Database.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -941,6 +941,29 @@ public function withTenant(?int $tenant, callable $callback): mixed
941941
}
942942
}
943943

944+
/**
945+
* Set whether to allow creating documents with tenant set per document.
946+
*
947+
* @param bool $enabled
948+
* @return static
949+
*/
950+
public function setTenantPerDocument(bool $enabled): static
951+
{
952+
$this->adapter->setTenantPerDocument($enabled);
953+
954+
return $this;
955+
}
956+
957+
/**
958+
* Get whether to allow creating documents with tenant set per document.
959+
*
960+
* @return bool
961+
*/
962+
public function getTenantPerDocument(): bool
963+
{
964+
return $this->adapter->getTenantPerDocument();
965+
}
966+
944967
public function getPreserveDates(): bool
945968
{
946969
return $this->preserveDates;

0 commit comments

Comments
 (0)