mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-13 04:04:04 +00:00
misc improvements - stronger types, exception refactor
This commit is contained in:
parent
ddc7cf49c3
commit
55d0a9ab87
34 changed files with 179 additions and 209 deletions
|
|
@ -1,28 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Stancl\Tenancy\Exceptions;
|
||||
|
||||
use Facade\IgnitionContracts\BaseSolution;
|
||||
use Facade\IgnitionContracts\ProvidesSolution;
|
||||
use Facade\IgnitionContracts\Solution;
|
||||
use Stancl\Tenancy\Contracts\TenantCouldNotBeIdentifiedException;
|
||||
|
||||
// todo: in v4 this should be suffixed with Exception
|
||||
class TenantCouldNotBeIdentifiedById extends TenantCouldNotBeIdentifiedException implements ProvidesSolution
|
||||
{
|
||||
public function __construct($tenant_id)
|
||||
{
|
||||
parent::__construct("Tenant could not be identified with tenant_id: $tenant_id");
|
||||
}
|
||||
|
||||
public function getSolution(): Solution
|
||||
{
|
||||
return BaseSolution::create('Tenant could not be identified with that ID')
|
||||
->setSolutionDescription('Are you sure the ID is correct and the tenant exists?')
|
||||
->setDocumentationLinks([
|
||||
'Initializing Tenants' => 'https://tenancyforlaravel.com/docs/v3/tenants',
|
||||
]);
|
||||
}
|
||||
}
|
||||
18
src/Exceptions/TenantCouldNotBeIdentifiedByIdException.php
Normal file
18
src/Exceptions/TenantCouldNotBeIdentifiedByIdException.php
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Stancl\Tenancy\Exceptions;
|
||||
|
||||
use Stancl\Tenancy\Contracts\TenantCouldNotBeIdentifiedException;
|
||||
|
||||
class TenantCouldNotBeIdentifiedByIdException extends TenantCouldNotBeIdentifiedException
|
||||
{
|
||||
public function __construct(int|string $tenant_id)
|
||||
{
|
||||
$this
|
||||
->tenantCouldNotBeIdentified("by tenant id: $tenant_id")
|
||||
->title('Tenant could not be identified with that ID')
|
||||
->description('Are you sure the ID is correct and the tenant exists?');
|
||||
}
|
||||
}
|
||||
|
|
@ -4,24 +4,15 @@ declare(strict_types=1);
|
|||
|
||||
namespace Stancl\Tenancy\Exceptions;
|
||||
|
||||
use Facade\IgnitionContracts\BaseSolution;
|
||||
use Facade\IgnitionContracts\ProvidesSolution;
|
||||
use Facade\IgnitionContracts\Solution;
|
||||
use Stancl\Tenancy\Contracts\TenantCouldNotBeIdentifiedException;
|
||||
|
||||
class TenantCouldNotBeIdentifiedByPathException extends TenantCouldNotBeIdentifiedException implements ProvidesSolution
|
||||
class TenantCouldNotBeIdentifiedByPathException extends TenantCouldNotBeIdentifiedException
|
||||
{
|
||||
public function __construct($tenant_id)
|
||||
public function __construct(int|string $tenant_id)
|
||||
{
|
||||
parent::__construct("Tenant could not be identified on path with tenant_id: $tenant_id");
|
||||
}
|
||||
|
||||
public function getSolution(): Solution
|
||||
{
|
||||
return BaseSolution::create('Tenant could not be identified on this path')
|
||||
->setSolutionDescription('Did you forget to create a tenant for this path?')
|
||||
->setDocumentationLinks([
|
||||
'Creating Tenants' => 'https://tenancyforlaravel.com/docs/v3/tenants/',
|
||||
]);
|
||||
$this
|
||||
->tenantCouldNotBeIdentified("on path with tenant id: $tenant_id")
|
||||
->title('Tenant could not be identified on this path')
|
||||
->description('Did you forget to create a tenant for this path?');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,24 +4,15 @@ declare(strict_types=1);
|
|||
|
||||
namespace Stancl\Tenancy\Exceptions;
|
||||
|
||||
use Facade\IgnitionContracts\BaseSolution;
|
||||
use Facade\IgnitionContracts\ProvidesSolution;
|
||||
use Facade\IgnitionContracts\Solution;
|
||||
use Stancl\Tenancy\Contracts\TenantCouldNotBeIdentifiedException;
|
||||
|
||||
class TenantCouldNotBeIdentifiedByRequestDataException extends TenantCouldNotBeIdentifiedException implements ProvidesSolution
|
||||
class TenantCouldNotBeIdentifiedByRequestDataException extends TenantCouldNotBeIdentifiedException
|
||||
{
|
||||
public function __construct($tenant_id)
|
||||
public function __construct(mixed $payload)
|
||||
{
|
||||
parent::__construct("Tenant could not be identified by request data with payload: $tenant_id");
|
||||
}
|
||||
|
||||
public function getSolution(): Solution
|
||||
{
|
||||
return BaseSolution::create('Tenant could not be identified with this request data')
|
||||
->setSolutionDescription('Did you forget to create a tenant with this id?')
|
||||
->setDocumentationLinks([
|
||||
'Creating Tenants' => 'https://tenancyforlaravel.com/docs/v3/tenants/',
|
||||
]);
|
||||
$this
|
||||
->tenantCouldNotBeIdentified("by request data with payload: $payload")
|
||||
->title('Tenant could not be identified using this request data')
|
||||
->description('Did you forget to create a tenant with this id?');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,24 +4,15 @@ declare(strict_types=1);
|
|||
|
||||
namespace Stancl\Tenancy\Exceptions;
|
||||
|
||||
use Facade\IgnitionContracts\BaseSolution;
|
||||
use Facade\IgnitionContracts\ProvidesSolution;
|
||||
use Facade\IgnitionContracts\Solution;
|
||||
use Stancl\Tenancy\Contracts\TenantCouldNotBeIdentifiedException;
|
||||
|
||||
class TenantCouldNotBeIdentifiedOnDomainException extends TenantCouldNotBeIdentifiedException implements ProvidesSolution
|
||||
class TenantCouldNotBeIdentifiedOnDomainException extends TenantCouldNotBeIdentifiedException
|
||||
{
|
||||
public function __construct($domain)
|
||||
public function __construct(string $domain)
|
||||
{
|
||||
parent::__construct("Tenant could not be identified on domain $domain");
|
||||
}
|
||||
|
||||
public function getSolution(): Solution
|
||||
{
|
||||
return BaseSolution::create('Tenant could not be identified on this domain')
|
||||
->setSolutionDescription('Did you forget to create a tenant for this domain?')
|
||||
->setDocumentationLinks([
|
||||
'Creating Tenants' => 'https://tenancyforlaravel.com/docs/v3/tenants/',
|
||||
]);
|
||||
$this
|
||||
->tenantCouldNotBeIdentified("on domain $domain")
|
||||
->title('Tenant could not be identified on this domain')
|
||||
->description('Did you forget to create a tenant for this domain?');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,18 +8,14 @@ use Stancl\Tenancy\Contracts\TenantCannotBeCreatedException;
|
|||
|
||||
class TenantDatabaseAlreadyExistsException extends TenantCannotBeCreatedException
|
||||
{
|
||||
/** @var string */
|
||||
protected $database;
|
||||
public function __construct(
|
||||
protected string $database,
|
||||
) {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function reason(): string
|
||||
{
|
||||
return "Database {$this->database} already exists.";
|
||||
}
|
||||
|
||||
public function __construct(string $database)
|
||||
{
|
||||
$this->database = $database;
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ use Exception;
|
|||
|
||||
class TenantDatabaseDoesNotExistException extends Exception
|
||||
{
|
||||
public function __construct($database)
|
||||
public function __construct(string $database)
|
||||
{
|
||||
parent::__construct("Database $database does not exist.");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,18 +8,14 @@ use Stancl\Tenancy\Contracts\TenantCannotBeCreatedException;
|
|||
|
||||
class TenantDatabaseUserAlreadyExistsException extends TenantCannotBeCreatedException
|
||||
{
|
||||
/** @var string */
|
||||
protected $user;
|
||||
public function __construct(
|
||||
protected string $user,
|
||||
) {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function reason(): string
|
||||
{
|
||||
return "Database user {$this->user} already exists.";
|
||||
}
|
||||
|
||||
public function __construct(string $user)
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->user = $user;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue