Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/Database/Adapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ abstract class Adapter

protected bool $sharedTables = false;

protected ?int $tenant = null;
protected int|string|null $tenant = null;

protected bool $tenantPerDocument = false;

Expand Down Expand Up @@ -219,11 +219,11 @@ public function getSharedTables(): bool
*
* Set tenant to use if tables are shared
*
* @param ?int $tenant
* @param int|string|null $tenant
*
* @return bool
*/
public function setTenant(?int $tenant): bool
public function setTenant(int|string|null $tenant): bool
{
$this->tenant = $tenant;

Expand All @@ -235,9 +235,9 @@ public function setTenant(?int $tenant): bool
*
* Get tenant to use for shared tables
*
* @return ?int
* @return int|string|null
*/
public function getTenant(): ?int
public function getTenant(): int|string|null
{
return $this->tenant;
}
Expand Down
6 changes: 3 additions & 3 deletions src/Database/Adapter/Mongo.php
Original file line number Diff line number Diff line change
Expand Up @@ -3601,13 +3601,13 @@ public function getSchemaAttributes(string $collection): array

/**
* @param string $collection
* @param array<int> $tenants
* @return int|null|array<string, array<int>>
* @param array<int|string> $tenants
* @return int|string|null|array<string, array<int|string|null>>
*/
public function getTenantFilters(
string $collection,
array $tenants = [],
): int|null|array {
): int|string|null|array {
$values = [];
if (!$this->sharedTables) {
return $values;
Expand Down
24 changes: 18 additions & 6 deletions src/Database/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -920,6 +920,18 @@ public function getNamespace(): string
return $this->adapter->getNamespace();
}

/**
* Get ID Attribute Type.
*
* Returns the type of the internal ID attribute (e.g. VAR_INTEGER for SQL, VAR_UUID7 for MongoDB)
*
* @return string
*/
public function getIdAttributeType(): string
{
return $this->adapter->getIdAttributeType();
}

/**
* Set database to use for current scope
*
Expand Down Expand Up @@ -1224,10 +1236,10 @@ public function setSharedTables(bool $sharedTables): static
*
* Set tenant to use if tables are shared
*
* @param ?int $tenant
* @param int|string|null $tenant
* @return static
*/
public function setTenant(?int $tenant): static
public function setTenant(int|string|null $tenant): static
{
$this->adapter->setTenant($tenant);

Expand All @@ -1239,9 +1251,9 @@ public function setTenant(?int $tenant): static
*
* Get tenant to use if tables are shared
*
* @return ?int
* @return int|string|null
*/
public function getTenant(): ?int
public function getTenant(): int|string|null
{
return $this->adapter->getTenant();
}
Expand All @@ -1251,11 +1263,11 @@ public function getTenant(): ?int
*
* Execute a callback with a specific tenant
*
* @param int|null $tenant
* @param int|string|null $tenant
* @param callable $callback
* @return mixed
*/
public function withTenant(?int $tenant, callable $callback): mixed
public function withTenant(int|string|null $tenant, callable $callback): mixed
{
$previous = $this->adapter->getTenant();
$this->adapter->setTenant($tenant);
Expand Down
10 changes: 5 additions & 5 deletions src/Database/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,17 +173,17 @@ public function getUpdatedAt(): ?string
}

/**
* @return int|null
* @return int|string|null
*/
public function getTenant(): ?int
public function getTenant(): int|string|null
{
$tenant = $this->getAttribute('$tenant');

if ($tenant === null) {
return null;
if (\is_numeric($tenant)) {
return (int) $tenant;
}

return (int) $tenant;
return $tenant;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Database/Mirror.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public function setSharedTables(bool $sharedTables): static
return $this;
}

public function setTenant(?int $tenant): static
public function setTenant(int|string|null $tenant): static
{
$this->delegate(__FUNCTION__, \func_get_args());

Expand Down
Loading