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

misc improvements - stronger types, exception refactor

This commit is contained in:
Samuel Štancl 2022-08-26 21:35:17 +02:00
parent ddc7cf49c3
commit 55d0a9ab87
34 changed files with 179 additions and 209 deletions

View file

@ -6,11 +6,16 @@ namespace Stancl\Tenancy\Contracts;
use Stancl\Tenancy\DatabaseConfig;
// todo possibly move to Database namespace, along with other classes
interface ManagesDatabaseUsers extends TenantDatabaseManager
{
/** Create a database user. */
public function createUser(DatabaseConfig $databaseConfig): bool;
/** Delete a database user. */
public function deleteUser(DatabaseConfig $databaseConfig): bool;
/** Does a database user exist? */
public function userExists(string $username): bool;
}

View file

@ -7,6 +7,8 @@ namespace Stancl\Tenancy\Contracts;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
// todo move all resource syncing-related things to a separate namespace?
/**
* @property-read Tenant[]|Collection $tenants
*/

View file

@ -4,11 +4,11 @@ declare(strict_types=1);
namespace Stancl\Tenancy\Contracts;
use Closure;
/**
* @see \Stancl\Tenancy\Database\Models\Tenant
*
* @method __call(string $method, array $parameters) IDE support. This will be a model.
* @method static __callStatic(string $method, array $parameters) IDE support. This will be a model.
* @mixin \Illuminate\Database\Eloquent\Model
*/
interface Tenant
@ -17,14 +17,14 @@ interface Tenant
public function getTenantKeyName(): string;
/** Get the value of the key used for identifying the tenant. */
public function getTenantKey();
public function getTenantKey(): int|string;
/** Get the value of an internal key. */
public function getInternal(string $key);
public function getInternal(string $key): mixed;
/** Set the value of an internal key. */
public function setInternal(string $key, $value);
public function setInternal(string $key, mixed $value): static;
/** Run a callback in this tenant's environment. */
public function run(callable $callback);
public function run(Closure $callback): mixed;
}

View file

@ -5,7 +5,50 @@ declare(strict_types=1);
namespace Stancl\Tenancy\Contracts;
use Exception;
use Facade\IgnitionContracts\BaseSolution;
use Facade\IgnitionContracts\ProvidesSolution;
use Facade\IgnitionContracts\Solution;
abstract class TenantCouldNotBeIdentifiedException extends Exception
abstract class TenantCouldNotBeIdentifiedException extends Exception implements ProvidesSolution
{
/** Default solution title. */
protected string $solutionTitle = 'Tenant could not be identified';
/** Default solution description. */
protected string $solutionDescription = 'Are you sure this tenant exists?';
/** Set the message. */
protected function tenantCouldNotBeIdentified(string $how): static
{
$this->message = "Tenant could not be identified " . $how;
return $this;
}
/** Set the solution title. */
protected function title(string $solutionTitle): static
{
$this->solutionTitle = $solutionTitle;
return $this;
}
/** Set the solution description. */
protected function description(string $solutionDescription): static
{
$this->solutionDescription = $solutionDescription;
return $this;
}
/** Get the Ignition description. */
public function getSolution(): Solution
{
return BaseSolution::create($this->solutionTitle)
->setSolutionDescription($this->solutionDescription)
->setDocumentationLinks([
'Tenants' => 'https://tenancyforlaravel.com/docs/v3/tenants',
'Tenant Identification' => 'https://tenancyforlaravel.com/docs/v3/tenant-identification',
]);
}
}

View file

@ -8,24 +8,16 @@ use Stancl\Tenancy\Exceptions\NoConnectionSetException;
interface TenantDatabaseManager
{
/**
* Create a database.
*/
/** Create a database. */
public function createDatabase(TenantWithDatabase $tenant): bool;
/**
* Delete a database.
*/
/** Delete a database. */
public function deleteDatabase(TenantWithDatabase $tenant): bool;
/**
* Does a database exist.
*/
/** Does a database exist? */
public function databaseExists(string $name): bool;
/**
* Make a DB connection config array.
*/
/** Construct a DB connection config array. */
public function makeConnectionConfig(array $baseConfig, string $databaseName): array;
/**

View file

@ -11,5 +11,5 @@ interface TenantWithDatabase extends Tenant
public function database(): DatabaseConfig;
/** Get an internal key. */
public function getInternal(string $key);
public function getInternal(string $key): mixed;
}