mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 21:54:03 +00:00
phpstan improvements
This commit is contained in:
parent
87212e5390
commit
d463e2da61
10 changed files with 18 additions and 27 deletions
|
|
@ -8,7 +8,7 @@ use Exception;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Illuminate\Support\LazyCollection;
|
use Illuminate\Support\LazyCollection;
|
||||||
use Stancl\Tenancy\Concerns\DealsWithTenantSymlinks;
|
use Stancl\Tenancy\Concerns\DealsWithTenantSymlinks;
|
||||||
use Stancl\Tenancy\Database\Models\Tenant;
|
use Stancl\Tenancy\Contracts\Tenant;
|
||||||
use Stancl\Tenancy\Events\CreatingStorageSymlink;
|
use Stancl\Tenancy\Events\CreatingStorageSymlink;
|
||||||
use Stancl\Tenancy\Events\StorageSymlinkCreated;
|
use Stancl\Tenancy\Events\StorageSymlinkCreated;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ namespace Stancl\Tenancy\Actions;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Illuminate\Support\LazyCollection;
|
use Illuminate\Support\LazyCollection;
|
||||||
use Stancl\Tenancy\Concerns\DealsWithTenantSymlinks;
|
use Stancl\Tenancy\Concerns\DealsWithTenantSymlinks;
|
||||||
use Stancl\Tenancy\Database\Models\Tenant;
|
use Stancl\Tenancy\Contracts\Tenant;
|
||||||
use Stancl\Tenancy\Events\RemovingStorageSymlink;
|
use Stancl\Tenancy\Events\RemovingStorageSymlink;
|
||||||
use Stancl\Tenancy\Events\StorageSymlinkRemoved;
|
use Stancl\Tenancy\Events\StorageSymlinkRemoved;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,8 @@ trait DealsWithTenantSymlinks
|
||||||
* Tenants can have a symlink for each disk registered in the tenancy.filesystem.url_override config.
|
* Tenants can have a symlink for each disk registered in the tenancy.filesystem.url_override config.
|
||||||
*
|
*
|
||||||
* This is used for creating all possible tenant symlinks and removing all existing tenant symlinks.
|
* This is used for creating all possible tenant symlinks and removing all existing tenant symlinks.
|
||||||
|
*
|
||||||
|
* @return Collection<string, string>
|
||||||
*/
|
*/
|
||||||
protected static function possibleTenantSymlinks(Tenant $tenant): Collection
|
protected static function possibleTenantSymlinks(Tenant $tenant): Collection
|
||||||
{
|
{
|
||||||
|
|
@ -33,7 +35,7 @@ trait DealsWithTenantSymlinks
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return $symlinks->mapWithKeys(fn ($item) => $item);
|
return $symlinks->mapWithKeys(fn ($item) => $item); // [[a => b], [c => d]] -> [a => b, c => d]
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Determine if the provided path is an existing symlink. */
|
/** Determine if the provided path is an existing symlink. */
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ use Exception;
|
||||||
|
|
||||||
class DomainOccupiedByOtherTenantException extends Exception
|
class DomainOccupiedByOtherTenantException extends Exception
|
||||||
{
|
{
|
||||||
public function __construct($domain)
|
public function __construct(string $domain)
|
||||||
{
|
{
|
||||||
parent::__construct("The $domain domain is occupied by another tenant.");
|
parent::__construct("The $domain domain is occupied by another tenant.");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ use Exception;
|
||||||
|
|
||||||
class TenancyNotInitializedException extends Exception
|
class TenancyNotInitializedException extends Exception
|
||||||
{
|
{
|
||||||
public function __construct($message = '')
|
public function __construct(string $message = '')
|
||||||
{
|
{
|
||||||
parent::__construct($message ?: 'Tenancy is not initialized.');
|
parent::__construct($message ?: 'Tenancy is not initialized.');
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ class CreateDatabase implements ShouldQueue
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function handle(DatabaseManager $databaseManager)
|
public function handle(DatabaseManager $databaseManager): bool
|
||||||
{
|
{
|
||||||
event(new CreatingDatabase($this->tenant));
|
event(new CreatingDatabase($this->tenant));
|
||||||
|
|
||||||
|
|
@ -38,5 +38,7 @@ class CreateDatabase implements ShouldQueue
|
||||||
$this->tenant->database()->manager()->createDatabase($this->tenant);
|
$this->tenant->database()->manager()->createDatabase($this->tenant);
|
||||||
|
|
||||||
event(new DatabaseCreated($this->tenant));
|
event(new DatabaseCreated($this->tenant));
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,24 +16,11 @@ class CreateStorageSymlinks implements ShouldQueue
|
||||||
{
|
{
|
||||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||||
|
|
||||||
public Tenant $tenant;
|
public function __construct(
|
||||||
|
public Tenant $tenant,
|
||||||
|
) {}
|
||||||
|
|
||||||
/**
|
public function handle(): void
|
||||||
* Create a new job instance.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function __construct(Tenant $tenant)
|
|
||||||
{
|
|
||||||
$this->tenant = $tenant;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute the job.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function handle()
|
|
||||||
{
|
{
|
||||||
CreateStorageSymlinksAction::handle($this->tenant);
|
CreateStorageSymlinksAction::handle($this->tenant);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,14 +9,12 @@ use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Foundation\Bus\Dispatchable;
|
use Illuminate\Foundation\Bus\Dispatchable;
|
||||||
use Illuminate\Queue\InteractsWithQueue;
|
use Illuminate\Queue\InteractsWithQueue;
|
||||||
use Illuminate\Queue\SerializesModels;
|
use Illuminate\Queue\SerializesModels;
|
||||||
use Stancl\Tenancy\Database\Concerns\HasDomains;
|
|
||||||
use Stancl\Tenancy\Database\Contracts\TenantWithDatabase;
|
use Stancl\Tenancy\Database\Contracts\TenantWithDatabase;
|
||||||
|
|
||||||
class DeleteDomains
|
class DeleteDomains
|
||||||
{
|
{
|
||||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||||
|
|
||||||
/** @var TenantWithDatabase&Model&HasDomains */ // todo unresolvable type for phpstan
|
|
||||||
protected TenantWithDatabase&Model $tenant;
|
protected TenantWithDatabase&Model $tenant;
|
||||||
|
|
||||||
public function __construct(TenantWithDatabase&Model $tenant)
|
public function __construct(TenantWithDatabase&Model $tenant)
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ declare(strict_types=1);
|
||||||
namespace Stancl\Tenancy\Middleware;
|
namespace Stancl\Tenancy\Middleware;
|
||||||
|
|
||||||
use Closure;
|
use Closure;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
use Stancl\Tenancy\Contracts\TenantCouldNotBeIdentifiedException;
|
use Stancl\Tenancy\Contracts\TenantCouldNotBeIdentifiedException;
|
||||||
use Stancl\Tenancy\Contracts\TenantResolver;
|
use Stancl\Tenancy\Contracts\TenantResolver;
|
||||||
use Stancl\Tenancy\Tenancy;
|
use Stancl\Tenancy\Tenancy;
|
||||||
|
|
@ -17,7 +18,8 @@ abstract class IdentificationMiddleware
|
||||||
{
|
{
|
||||||
public static ?Closure $onFail = null;
|
public static ?Closure $onFail = null;
|
||||||
|
|
||||||
public function initializeTenancy($request, $next, ...$resolverArguments)
|
/** @return \Illuminate\Http\Response|mixed */
|
||||||
|
public function initializeTenancy(Request $request, Closure $next, mixed ...$resolverArguments): mixed
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$this->tenancy->initialize(
|
$this->tenancy->initialize(
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ use Stancl\Tenancy\Exceptions\TenancyNotInitializedException;
|
||||||
|
|
||||||
class ScopeSessions
|
class ScopeSessions
|
||||||
{
|
{
|
||||||
public static $tenantIdKey = '_tenant_id';
|
public static string $tenantIdKey = '_tenant_id';
|
||||||
|
|
||||||
/** @return \Illuminate\Http\Response|mixed */
|
/** @return \Illuminate\Http\Response|mixed */
|
||||||
public function handle(Request $request, Closure $next): mixed
|
public function handle(Request $request, Closure $next): mixed
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue