1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2025-12-12 11:14:04 +00:00

Merge branch 'master' of github.com:stancl/tenancy

This commit is contained in:
Samuel Štancl 2020-05-22 11:10:05 +02:00
commit d7c04d304d
133 changed files with 379 additions and 203 deletions

View file

@ -1,14 +1,16 @@
<?php
declare(strict_types=1);
namespace App\Providers;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\Route;
use Illuminate\Support\ServiceProvider;
use Stancl\JobPipeline\JobPipeline;
use Stancl\Tenancy\Listeners;
use Stancl\Tenancy\Events;
use Stancl\Tenancy\Jobs;
use Stancl\Tenancy\Listeners;
use Stancl\Tenancy\Middleware;
class TenancyServiceProvider extends ServiceProvider
@ -81,7 +83,7 @@ class TenancyServiceProvider extends ServiceProvider
public function register()
{
//
//
}
public function boot()

View file

@ -9,7 +9,7 @@ return [
'tenant_model' => Tenant::class,
'internal_prefix' => 'tenancy_',
'id_generator' => Stancl\Tenancy\UUIDGenerator::class,
'domain_model' => Domain::class,
'central_domains' => [
'127.0.0.1',

View file

@ -6,4 +6,4 @@ use Illuminate\Support\Facades\Route;
Route::get('/tenancy/assets/{path?}', 'Stancl\Tenancy\Controllers\TenantAssetsController@asset')
->where('path', '(.*)')
->name('stancl.tenancy.asset');
->name('stancl.tenancy.asset');

View file

@ -5,10 +5,10 @@ declare(strict_types=1);
namespace Stancl\Tenancy\Bootstrappers;
use Stancl\Tenancy\Contracts\TenancyBootstrapper;
use Stancl\Tenancy\Contracts\Tenant;
use Stancl\Tenancy\Contracts\TenantWithDatabase;
use Stancl\Tenancy\DatabaseManager;
use Stancl\Tenancy\Exceptions\TenantDatabaseDoesNotExistException;
use Stancl\Tenancy\Contracts\TenantWithDatabase;
use Stancl\Tenancy\Contracts\Tenant;
class DatabaseTenancyBootstrapper implements TenancyBootstrapper
{
@ -23,7 +23,6 @@ class DatabaseTenancyBootstrapper implements TenancyBootstrapper
public function bootstrap(Tenant $tenant)
{
/** @var TenantWithDatabase $tenant */
$database = $tenant->database()->getName();
if (! $tenant->database()->manager()->databaseExists($database)) {
throw new TenantDatabaseDoesNotExistException($database);

View file

@ -7,11 +7,10 @@ namespace Stancl\Tenancy\Commands;
use Illuminate\Console\Command;
use Illuminate\Database\Console\Migrations\MigrateCommand;
use Illuminate\Database\Migrations\Migrator;
use Stancl\Tenancy\Contracts\TenantWithDatabase;
use Stancl\Tenancy\DatabaseManager;
use Stancl\Tenancy\Events\DatabaseMigrated;
use Stancl\Tenancy\Concerns\DealsWithMigrations;
use Stancl\Tenancy\Concerns\HasATenantsOption;
use Stancl\Tenancy\DatabaseManager;
use Stancl\Tenancy\Events\DatabaseMigrated;
use Stancl\Tenancy\Events\MigratingDatabase;
class Migrate extends MigrateCommand
@ -62,7 +61,7 @@ class Migrate extends MigrateCommand
$this->line("Tenant: {$tenant['id']}");
event(new MigratingDatabase($tenant));
// Migrate
parent::handle();

View file

@ -5,7 +5,6 @@ declare(strict_types=1);
namespace Stancl\Tenancy\Commands;
use Illuminate\Console\Command;
use Stancl\Tenancy\Contracts\TenantWithDatabase;
use Stancl\Tenancy\Concerns\DealsWithMigrations;
use Stancl\Tenancy\Concerns\HasATenantsOption;

View file

@ -7,11 +7,10 @@ namespace Stancl\Tenancy\Commands;
use Illuminate\Console\Command;
use Illuminate\Database\Console\Migrations\RollbackCommand;
use Illuminate\Database\Migrations\Migrator;
use Stancl\Tenancy\Contracts\TenantWithDatabase;
use Stancl\Tenancy\DatabaseManager;
use Stancl\Tenancy\Events\DatabaseRolledBack;
use Stancl\Tenancy\Concerns\DealsWithMigrations;
use Stancl\Tenancy\Concerns\HasATenantsOption;
use Stancl\Tenancy\DatabaseManager;
use Stancl\Tenancy\Events\DatabaseRolledBack;
class Rollback extends RollbackCommand
{

View file

@ -6,10 +6,9 @@ namespace Stancl\Tenancy\Commands;
use Illuminate\Database\ConnectionResolverInterface;
use Illuminate\Database\Console\Seeds\SeedCommand;
use Stancl\Tenancy\Contracts\TenantWithDatabase;
use Stancl\Tenancy\Concerns\HasATenantsOption;
use Stancl\Tenancy\DatabaseManager;
use Stancl\Tenancy\Events\DatabaseSeeded;
use Stancl\Tenancy\Concerns\HasATenantsOption;
use Stancl\Tenancy\Events\SeedingDatabase;
class Seed extends SeedCommand

View file

@ -39,6 +39,6 @@ class TenantList extends Command
->cursor()
->each(function (Tenant $tenant) {
$this->line("[Tenant] id: {$tenant['id']} @ " . implode('; ', $tenant->domains ?? []));
});
});
}
}

View file

@ -4,9 +4,9 @@ declare(strict_types=1);
namespace Stancl\Tenancy\Concerns;
use Stancl\Tenancy\Contracts\Tenant;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Stancl\Tenancy\Contracts\Tenant;
trait TenantAwareCommand
{

View file

@ -1,10 +1,12 @@
<?php
declare(strict_types=1);
namespace Stancl\Tenancy\Contracts;
/**
* @property-read Tenant $tenant
*
*
* @see \Stancl\Tenancy\Database\Models\Domain
*/
interface Domain

View file

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace Stancl\Tenancy\Contracts;
use Illuminate\Database\Eloquent\Collection;
@ -11,5 +13,6 @@ use Illuminate\Database\Eloquent\Relations\BelongsToMany;
interface SyncMaster extends Syncable
{
public function tenants(): BelongsToMany;
public function getTenantModelName(): string;
}

View file

@ -1,11 +1,16 @@
<?php
declare(strict_types=1);
namespace Stancl\Tenancy\Contracts;
interface Syncable
{
public function getGlobalIdentifierKeyName(): string;
public function getGlobalIdentifierKey(): string;
public function getCentralModelName(): string;
public function getSyncedAttributeNames(): array;
}

View file

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace Stancl\Tenancy\Contracts;
/**

View file

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace Stancl\Tenancy\Contracts;
use Exception;

View file

@ -37,7 +37,7 @@ interface TenantDatabaseManager
/**
* Set the DB connection that should be used by the tenant database manager.
*
*
* @throws NoConnectionSetException
*
* @param string $connection

View file

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace Stancl\Tenancy\Contracts;
interface TenantResolver

View file

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace Stancl\Tenancy\Contracts;
use Stancl\Tenancy\DatabaseConfig;

View file

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace Stancl\Tenancy\Database\Concerns;
use Stancl\Tenancy\Database\ParentModelScope;

View file

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace Stancl\Tenancy\Database\Concerns;
use Stancl\Tenancy\Contracts\Tenant;

View file

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace Stancl\Tenancy\Database\Concerns;
trait CentralConnection

View file

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace Stancl\Tenancy\Database\Concerns;
use Stancl\Tenancy\Contracts\UniqueIdentifierGenerator;

View file

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace Stancl\Tenancy\Database\Concerns;
/**

View file

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace Stancl\Tenancy\Database\Concerns;
use Stancl\Tenancy\Contracts\TenantWithDatabase;

View file

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace Stancl\Tenancy\Database\Concerns;
use Stancl\Tenancy\Contracts\Domain;

View file

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace Stancl\Tenancy\Database\Concerns;
use Illuminate\Validation\Rules\Exists;
@ -16,4 +18,4 @@ trait HasScopedValidationRules
{
return (new Exists($table, $column))->where(BelongsToTenant::$tenantIdColumn, $this->getTenantKey());
}
}
}

View file

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace Stancl\Tenancy\Database\Concerns;
use Carbon\Carbon;
@ -15,4 +17,4 @@ trait MaintenanceMode
'allowed' => $data['allowed'] ?? [],
]]);
}
}
}

View file

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace Stancl\Tenancy\Database\Concerns;
/**

View file

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace Stancl\Tenancy\Database\Concerns;
use Stancl\Tenancy\Contracts\Syncable;
@ -12,7 +14,6 @@ trait ResourceSyncing
{
static::saved(function (Syncable $model) {
/** @var ResourceSyncing $model */
$model->triggerSyncEvent();
});

View file

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace Stancl\Tenancy\Database\Concerns;
trait TenantConnection

View file

@ -1,13 +1,15 @@
<?php
declare(strict_types=1);
namespace Stancl\Tenancy\Database\Models;
use Illuminate\Database\Eloquent\Model;
use Stancl\Tenancy\Contracts;
use Stancl\Tenancy\Contracts\Tenant;
use Stancl\Tenancy\Database\Concerns\CentralConnection;
use Stancl\Tenancy\Events;
use Stancl\Tenancy\Exceptions\DomainOccupiedByOtherTenantException;
use Stancl\Tenancy\Contracts;
use Stancl\Tenancy\Database\Concerns\CentralConnection;
/**
* @property string $domain
@ -25,8 +27,8 @@ class Domain extends Model implements Contracts\Domain
{
parent::boot();
$ensureDomainIsNotOccupied = function (Domain $self) {
if ($domain = Domain::where('domain', $self->domain)->first()) {
$ensureDomainIsNotOccupied = function (self $self) {
if ($domain = self::where('domain', $self->domain)->first()) {
if ($domain->getKey() !== $self->getKey()) {
throw new DomainOccupiedByOtherTenantException($self->domain);
}

View file

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace Stancl\Tenancy\Database\Models;
use Carbon\Carbon;
@ -38,4 +40,4 @@ class ImpersonationToken extends Model
$model->auth_guard = $model->auth_guard ?? config('auth.defaults.guard');
});
}
}
}

View file

@ -1,20 +1,22 @@
<?php
declare(strict_types=1);
namespace Stancl\Tenancy\Database\Models;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;
use Stancl\Tenancy\Events;
use Stancl\Tenancy\Contracts;
use Stancl\Tenancy\Database\TenantCollection;
use Stancl\Tenancy\Database\Concerns;
use Stancl\Tenancy\Database\TenantCollection;
use Stancl\Tenancy\Events;
/**
* @property string|int $id
* @property Carbon $created_at
* @property Carbon $updated_at
* @property array $data
*
*
* @method TenantCollection all()
*/
class Tenant extends Model implements Contracts\Tenant

View file

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace Stancl\Tenancy\Database\Models;
use Illuminate\Database\Eloquent\Relations\Pivot;
@ -19,4 +21,4 @@ class TenantPivot extends Pivot
}
});
}
}
}

View file

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace Stancl\Tenancy\Database;
use Illuminate\Database\Eloquent\Builder;

View file

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace Stancl\Tenancy\Database;
use Illuminate\Database\Eloquent\Collection;
@ -20,4 +22,4 @@ class TenantCollection extends Collection
return $this;
}
}
}

View file

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace Stancl\Tenancy\Database;
use Illuminate\Database\Eloquent\Builder;

View file

@ -9,8 +9,8 @@ use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Str;
use Stancl\Tenancy\Contracts\ManagesDatabaseUsers;
use Stancl\Tenancy\Contracts\TenantDatabaseManager;
use Stancl\Tenancy\Exceptions\DatabaseManagerNotRegisteredException;
use Stancl\Tenancy\Contracts\TenantWithDatabase as Tenant;
use Stancl\Tenancy\Exceptions\DatabaseManagerNotRegisteredException;
class DatabaseConfig
{

View file

@ -4,17 +4,13 @@ declare(strict_types=1);
namespace Stancl\Tenancy;
use Closure;
use Illuminate\Config\Repository;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Database\DatabaseManager as BaseDatabaseManager;
use Illuminate\Foundation\Application;
use Stancl\Tenancy\Contracts\TenantCannotBeCreatedException;
use Stancl\Tenancy\Contracts\TenantWithDatabase;
use Stancl\Tenancy\Exceptions\DatabaseManagerNotRegisteredException;
use Stancl\Tenancy\Exceptions\TenantDatabaseAlreadyExistsException;
use Stancl\Tenancy\Jobs\QueuedTenantDatabaseCreator;
use Stancl\Tenancy\Jobs\QueuedTenantDatabaseDeleter;
/**
* @internal Class is subject to breaking changes in minor and patch versions.

View file

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace Stancl\Tenancy\Events;
class BootstrappingTenancy extends Contracts\TenancyEvent

View file

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace Stancl\Tenancy\Events\Contracts;
use Illuminate\Queue\SerializesModels;

View file

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace Stancl\Tenancy\Events\Contracts;
use Stancl\Tenancy\Tenancy;
@ -13,4 +15,4 @@ abstract class TenancyEvent
{
$this->tenancy = $tenancy;
}
}
}

View file

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace Stancl\Tenancy\Events\Contracts;
use Illuminate\Queue\SerializesModels;

View file

@ -1,6 +1,9 @@
<?php
declare(strict_types=1);
namespace Stancl\Tenancy\Events;
class CreatingDatabase extends Contracts\TenantEvent
{}
{
}

View file

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace Stancl\Tenancy\Events;
class CreatingDomain extends Contracts\DomainEvent

View file

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace Stancl\Tenancy\Events;
class CreatingTenant extends Contracts\TenantEvent

View file

@ -1,7 +1,9 @@
<?php
declare(strict_types=1);
namespace Stancl\Tenancy\Events;
class DatabaseCreated extends Contracts\TenantEvent
{
}
}

View file

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace Stancl\Tenancy\Events;
class DatabaseDeleted extends Contracts\TenantEvent

View file

@ -1,6 +1,9 @@
<?php
declare(strict_types=1);
namespace Stancl\Tenancy\Events;
class DatabaseMigrated extends Contracts\TenantEvent
{}
{
}

View file

@ -1,6 +1,9 @@
<?php
declare(strict_types=1);
namespace Stancl\Tenancy\Events;
class DatabaseRolledBack extends Contracts\TenantEvent
{}
{
}

View file

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace Stancl\Tenancy\Events;
class DatabaseSeeded extends Contracts\TenantEvent

View file

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace Stancl\Tenancy\Events;
class DeletingDomain extends Contracts\DomainEvent

View file

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace Stancl\Tenancy\Events;
class DeletingTenant extends Contracts\TenantEvent

View file

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace Stancl\Tenancy\Events;
class DomainCreated extends Contracts\DomainEvent

View file

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace Stancl\Tenancy\Events;
class DomainDeleted extends Contracts\DomainEvent

View file

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace Stancl\Tenancy\Events;
class DomainSaved extends Contracts\DomainEvent

View file

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace Stancl\Tenancy\Events;
class DomainUpdated extends Contracts\DomainEvent

View file

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace Stancl\Tenancy\Events;
class EndingTenancy extends Contracts\TenancyEvent

View file

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace Stancl\Tenancy\Events;
class InitializingTenancy extends Contracts\TenancyEvent

View file

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace Stancl\Tenancy\Events;
class MigratingDatabase extends Contracts\TenantEvent

View file

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace Stancl\Tenancy\Events;
class RevertedToCentralContext extends Contracts\TenancyEvent

View file

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace Stancl\Tenancy\Events;
class RevertingToCentralContext extends Contracts\TenancyEvent

View file

@ -1,6 +1,9 @@
<?php
declare(strict_types=1);
namespace Stancl\Tenancy\Events;
class SavedDomain extends Contracts\DomainEvent
{}
{
}

View file

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace Stancl\Tenancy\Events;
class SavedTenant extends Contracts\TenantEvent

View file

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace Stancl\Tenancy\Events;
class SavingDomain extends Contracts\DomainEvent

View file

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace Stancl\Tenancy\Events;
class SavingTenant extends Contracts\TenantEvent

View file

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace Stancl\Tenancy\Events;
class SeedingDatabase extends Contracts\TenantEvent

View file

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace Stancl\Tenancy\Events;
use Stancl\Tenancy\Contracts\Syncable;

View file

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace Stancl\Tenancy\Events;
use Illuminate\Database\Eloquent\Model;

View file

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace Stancl\Tenancy\Events;
class TenancyBootstrapped extends Contracts\TenancyEvent

View file

@ -1,7 +1,9 @@
<?php
declare(strict_types=1);
namespace Stancl\Tenancy\Events;
class TenancyEnded extends Contracts\TenancyEvent
{
}
}

View file

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace Stancl\Tenancy\Events;
class TenancyInitialized extends Contracts\TenancyEvent

View file

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace Stancl\Tenancy\Events;
class TenantCreated extends Contracts\TenantEvent

View file

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace Stancl\Tenancy\Events;
class TenantDeleted extends Contracts\TenantEvent

View file

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace Stancl\Tenancy\Events;
class TenantSaved extends Contracts\TenantEvent

View file

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace Stancl\Tenancy\Events;
class TenantUpdated extends Contracts\TenantEvent

View file

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace Stancl\Tenancy\Events;
class UpdatingDomain extends Contracts\DomainEvent

View file

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace Stancl\Tenancy\Events;
class UpdatingTenant extends Contracts\TenantEvent

View file

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace Stancl\Tenancy\Exceptions;
use Exception;
@ -10,4 +12,4 @@ class ModelNotSyncMasterException extends Exception
{
parent::__construct("Model of $class class is not an SyncMaster model. Make sure you're using the central model to make changes to synced resouces when you're in the central context");
}
}
}

View file

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace Stancl\Tenancy\Exceptions;
use Exception;
@ -10,4 +12,4 @@ class NoConnectionSetException extends Exception
{
parent::__construct("No connection was set on this $manager instance.");
}
}
}

View file

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace Stancl\Tenancy\Exceptions;
use Exception;
@ -10,4 +12,4 @@ class NotASubdomainException extends Exception
{
parent::__construct("Hostname $hostname does not include a subdomain.");
}
}
}

View file

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace Stancl\Tenancy\Exceptions;
use Exception;
@ -13,4 +15,4 @@ class RouteIsMissingTenantParameterException extends Exception
parent::__construct("The route's first argument is not the tenant id (configured paramter name: $parameter).");
}
}
}

View file

@ -1,13 +1,15 @@
<?php
declare(strict_types=1);
namespace Stancl\Tenancy\Exceptions;
use Exception;
class TenancyNotInitializedException extends Exception
{
public function __construct($message = "")
public function __construct($message = '')
{
parent::__construct($message ?: 'Tenancy is not initialized.');
}
}
}

View file

@ -45,4 +45,4 @@ class TelescopeTags implements Feature
return $callback($entry);
}
}
}

View file

@ -7,10 +7,10 @@ namespace Stancl\Tenancy\Features;
use Illuminate\Contracts\Config\Repository;
use Illuminate\Support\Facades\Event;
use Stancl\Tenancy\Contracts\Feature;
use Stancl\Tenancy\Contracts\Tenant;
use Stancl\Tenancy\Events\RevertedToCentralContext;
use Stancl\Tenancy\Events\TenancyBootstrapped;
use Stancl\Tenancy\Tenancy;
use Stancl\Tenancy\Contracts\Tenant;
class TenantConfig implements Feature
{

View file

@ -1,13 +1,15 @@
<?php
declare(strict_types=1);
namespace Stancl\Tenancy\Features;
use Carbon\Carbon;
use Illuminate\Http\RedirectResponse;
use Illuminate\Support\Facades\Auth;
use Stancl\Tenancy\Contracts\Feature;
use Stancl\Tenancy\Database\Models\ImpersonationToken;
use Stancl\Tenancy\Contracts\Tenant;
use Stancl\Tenancy\Database\Models\ImpersonationToken;
use Stancl\Tenancy\Tenancy;
class UserImpersonation implements Feature
@ -16,8 +18,7 @@ class UserImpersonation implements Feature
public function bootstrap(Tenancy $tenancy): void
{
$tenancy->macro('impersonate', function (Tenant $tenant, string $userId, string $redirectUrl, string $authGuard = null): ImpersonationToken
{
$tenancy->macro('impersonate', function (Tenant $tenant, string $userId, string $redirectUrl, string $authGuard = null): ImpersonationToken {
return ImpersonationToken::create([
'tenant_id' => $tenant->getTenantKey(),
'user_id' => $userId,

View file

@ -10,8 +10,8 @@ use Illuminate\Database\Eloquent\Model;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Stancl\Tenancy\Contracts\TenantWithDatabase;
use Stancl\Tenancy\Contracts\Tenant;
use Stancl\Tenancy\Contracts\TenantWithDatabase;
use Stancl\Tenancy\DatabaseManager;
use Stancl\Tenancy\Events\CreatingDatabase;
use Stancl\Tenancy\Events\DatabaseCreated;

View file

@ -9,7 +9,6 @@ use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Stancl\Tenancy\Contracts\TenantDatabaseManager;
use Stancl\Tenancy\Database\Models\Tenant;
use Stancl\Tenancy\Events\DatabaseDeleted;

View file

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace Stancl\Tenancy\Listeners;
use Stancl\Tenancy\Events\BootstrappingTenancy;

View file

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace Stancl\Tenancy\Listeners;
use Illuminate\Contracts\Queue\ShouldQueue;

View file

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace Stancl\Tenancy\Listeners;
use Stancl\Tenancy\Events\RevertedToCentralContext;
@ -17,5 +19,5 @@ class RevertToCentralContext
}
event(new RevertedToCentralContext($event->tenancy));
}
}
}

View file

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace Stancl\Tenancy\Listeners;
use Illuminate\Database\Eloquent\Model;
@ -70,7 +72,7 @@ class UpdateSyncedResource extends QueueableListener
$mappingExists = $centralModel->tenants->contains($currentTenantMapping);
if (!$mappingExists) {
if (! $mappingExists) {
// Here we should call TenantPivot, but we call general Pivot, so that this works
// even if people use their own pivot model that is not based on our TenantPivot
Pivot::withoutEvents(function () use ($centralModel, $event) {
@ -80,7 +82,7 @@ class UpdateSyncedResource extends QueueableListener
return $centralModel->tenants->filter(function ($model) use ($currentTenantMapping) {
// Remove the mapping for the current tenant.
return !$currentTenantMapping($model);
return ! $currentTenantMapping($model);
});
}

View file

@ -1,11 +1,12 @@
<?php
declare(strict_types=1);
namespace Stancl\Tenancy\Middleware;
use Closure;
use Illuminate\Foundation\Http\Exceptions\MaintenanceModeException;
use Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode;
use Illuminate\Http\Request;
use Stancl\Tenancy\Exceptions\TenancyNotInitializedException;
use Symfony\Component\HttpFoundation\IpUtils;
@ -33,4 +34,4 @@ class CheckTenantForMaintenanceMode extends CheckForMaintenanceMode
return $next($request);
}
}
}

View file

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace Stancl\Tenancy\Middleware;
use Stancl\Tenancy\Contracts\TenantCouldNotBeIdentifiedException;
@ -33,4 +35,4 @@ abstract class IdentificationMiddleware
return $next($request);
}
}
}

View file

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace Stancl\Tenancy\Middleware;
use Closure;
@ -41,4 +43,4 @@ class InitializeTenancyByPath extends IdentificationMiddleware
return $next($request);
}
}
}

View file

@ -6,8 +6,8 @@ namespace Stancl\Tenancy\Middleware;
use Closure;
use Illuminate\Http\Response;
use Stancl\Tenancy\Exceptions\NotASubdomainException;
use Illuminate\Support\Str;
use Stancl\Tenancy\Exceptions\NotASubdomainException;
class InitializeTenancyBySubdomain extends InitializeTenancyByDomain
{

View file

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace Stancl\Tenancy\Middleware;
use Closure;

View file

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace Stancl\Tenancy\Middleware;
use Closure;
@ -26,4 +28,4 @@ class ScopeSessions
return $next($request);
}
}
}

View file

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace Stancl\Tenancy\Resolvers;
use Illuminate\Cache\Repository;

View file

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace Stancl\Tenancy\Resolvers;
use Stancl\Tenancy\Contracts\Domain;

Some files were not shown because too many files have changed in this diff Show more