mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 20:54:04 +00:00
* install PHP CS Fixer * Fix styling * remove StyleCI config * use config from archtechx/template * Fix styling * added `php-cs-fixer` * Update .php-cs-fixer.php * added GitHub token * Update ci.yml * Update ci.yml * Update ci.yml * php-cs-fixer workflow same as template Co-authored-by: Erik Gaal <me@erikgaal.nl> Co-authored-by: erikgaal <erikgaal@users.noreply.github.com>
This commit is contained in:
parent
627233d07a
commit
97ab483173
43 changed files with 231 additions and 111 deletions
|
|
@ -69,7 +69,7 @@ class FilesystemTenancyBootstrapper implements TenancyBootstrapper
|
|||
|
||||
if (! $finalPrefix) {
|
||||
$finalPrefix = $originalRoot
|
||||
? rtrim($originalRoot, '/') . '/'. $suffix
|
||||
? rtrim($originalRoot, '/') . '/' . $suffix
|
||||
: $suffix;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,18 +4,17 @@ declare(strict_types=1);
|
|||
|
||||
namespace Stancl\Tenancy\Bootstrappers;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Config\Repository;
|
||||
use Illuminate\Queue\QueueManager;
|
||||
use Stancl\Tenancy\Contracts\Tenant;
|
||||
use Illuminate\Contracts\Events\Dispatcher;
|
||||
use Illuminate\Contracts\Foundation\Application;
|
||||
use Illuminate\Queue\Events\JobFailed;
|
||||
use Illuminate\Queue\Events\JobProcessed;
|
||||
use Illuminate\Queue\Events\JobProcessing;
|
||||
use Illuminate\Contracts\Events\Dispatcher;
|
||||
use Illuminate\Queue\Events\JobRetryRequested;
|
||||
use Illuminate\Queue\QueueManager;
|
||||
use Illuminate\Support\Testing\Fakes\QueueFake;
|
||||
use Illuminate\Contracts\Foundation\Application;
|
||||
use Stancl\Tenancy\Contracts\TenancyBootstrapper;
|
||||
use Stancl\Tenancy\Contracts\Tenant;
|
||||
|
||||
class QueueTenancyBootstrapper implements TenancyBootstrapper
|
||||
{
|
||||
|
|
|
|||
|
|
@ -13,7 +13,6 @@ class CacheManager extends BaseCacheManager
|
|||
*
|
||||
* @param string $method
|
||||
* @param array $parameters
|
||||
* @return mixed
|
||||
*/
|
||||
public function __call($method, $parameters)
|
||||
{
|
||||
|
|
@ -21,7 +20,7 @@ class CacheManager extends BaseCacheManager
|
|||
|
||||
if ($method === 'tags') {
|
||||
$count = count($parameters);
|
||||
|
||||
|
||||
if ($count !== 1) {
|
||||
throw new \Exception("Method tags() takes exactly 1 argument. $count passed.");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,8 +24,6 @@ class Install extends Command
|
|||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -33,8 +33,6 @@ class Migrate extends MigrateCommand
|
|||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -31,8 +31,6 @@ final class MigrateFresh extends Command
|
|||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -42,8 +42,6 @@ class Rollback extends RollbackCommand
|
|||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -27,8 +27,6 @@ class Run extends Command
|
|||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -35,8 +35,6 @@ class Seed extends SeedCommand
|
|||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -21,10 +21,9 @@ class TenantDump extends DumpCommand
|
|||
$this->specifyParameters();
|
||||
}
|
||||
|
||||
|
||||
public function handle(ConnectionResolverInterface $connections, Dispatcher $dispatcher): int
|
||||
{
|
||||
$this->tenant()->run(fn() => parent::handle($connections, $dispatcher));
|
||||
$this->tenant()->run(fn () => parent::handle($connections, $dispatcher));
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,8 +25,6 @@ class TenantList extends Command
|
|||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Stancl\Tenancy\Concerns;
|
||||
|
||||
trait ExtendsLaravelCommand
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ trait HasATenantsOption
|
|||
protected function getOptions()
|
||||
{
|
||||
return array_merge([
|
||||
['tenants', null, InputOption::VALUE_IS_ARRAY | InputOption::VALUE_OPTIONAL, '', null],
|
||||
['tenants', null, InputOption::VALUE_IS_ARRAY|InputOption::VALUE_OPTIONAL, '', null],
|
||||
], parent::getOptions());
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -20,18 +20,11 @@ interface TenantDatabaseManager
|
|||
|
||||
/**
|
||||
* Does a database exist.
|
||||
*
|
||||
* @param string $name
|
||||
* @return bool
|
||||
*/
|
||||
public function databaseExists(string $name): bool;
|
||||
|
||||
/**
|
||||
* Make a DB connection config array.
|
||||
*
|
||||
* @param array $baseConfig
|
||||
* @param string $databaseName
|
||||
* @return array
|
||||
*/
|
||||
public function makeConnectionConfig(array $baseConfig, string $databaseName): array;
|
||||
|
||||
|
|
@ -39,9 +32,6 @@ interface TenantDatabaseManager
|
|||
* Set the DB connection that should be used by the tenant database manager.
|
||||
*
|
||||
* @throws NoConnectionSetException
|
||||
*
|
||||
* @param string $connection
|
||||
* @return void
|
||||
*/
|
||||
public function setConnection(string $connection): void;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,9 +11,6 @@ trait TenantRun
|
|||
/**
|
||||
* Run a callback in this tenant's context.
|
||||
* Atomic, safely reverts to previous context.
|
||||
*
|
||||
* @param callable $callback
|
||||
* @return mixed
|
||||
*/
|
||||
public function run(callable $callback)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -22,10 +22,15 @@ class ImpersonationToken extends Model
|
|||
use CentralConnection;
|
||||
|
||||
protected $guarded = [];
|
||||
|
||||
public $timestamps = false;
|
||||
|
||||
protected $primaryKey = 'token';
|
||||
|
||||
public $incrementing = false;
|
||||
|
||||
protected $table = 'tenant_user_impersonation_tokens';
|
||||
|
||||
protected $dates = [
|
||||
'created_at',
|
||||
];
|
||||
|
|
|
|||
|
|
@ -29,7 +29,9 @@ class Tenant extends Model implements Contracts\Tenant
|
|||
Concerns\InvalidatesResolverCache;
|
||||
|
||||
protected $table = 'tenants';
|
||||
|
||||
protected $primaryKey = 'id';
|
||||
|
||||
protected $guarded = [];
|
||||
|
||||
public function getTenantKeyName(): string
|
||||
|
|
|
|||
|
|
@ -80,8 +80,6 @@ class DatabaseConfig
|
|||
|
||||
/**
|
||||
* Generate DB name, username & password and write them to the tenant model.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function makeCredentials(): void
|
||||
{
|
||||
|
|
@ -113,7 +111,8 @@ class DatabaseConfig
|
|||
$templateConnection = config("database.connections.{$template}");
|
||||
|
||||
return $this->manager()->makeConnectionConfig(
|
||||
array_merge($templateConnection, $this->tenantConfig()), $this->getName()
|
||||
array_merge($templateConnection, $this->tenantConfig()),
|
||||
$this->getName()
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -33,7 +33,6 @@ class UserImpersonation implements Feature
|
|||
*
|
||||
* @param string|ImpersonationToken $token
|
||||
* @param int $ttl
|
||||
* @return RedirectResponse
|
||||
*/
|
||||
public static function makeResponse($token, int $ttl = null): RedirectResponse
|
||||
{
|
||||
|
|
|
|||
|
|
@ -48,8 +48,7 @@ class UpdateSyncedResource extends QueueableListener
|
|||
protected function updateResourceInCentralDatabaseAndGetTenants($event, $syncedAttributes)
|
||||
{
|
||||
/** @var Model|SyncMaster $centralModel */
|
||||
$centralModel = $event->model->getCentralModelName()
|
||||
::where($event->model->getGlobalIdentifierKeyName(), $event->model->getGlobalIdentifierKey())
|
||||
$centralModel = $event->model->getCentralModelName()::where($event->model->getGlobalIdentifierKeyName(), $event->model->getGlobalIdentifierKey())
|
||||
->first();
|
||||
|
||||
// We disable events for this call, to avoid triggering this event & listener again.
|
||||
|
|
|
|||
|
|
@ -5,10 +5,10 @@ declare(strict_types=1);
|
|||
namespace Stancl\Tenancy\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Symfony\Component\HttpKernel\Exception\HttpException;
|
||||
use Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode;
|
||||
use Stancl\Tenancy\Exceptions\TenancyNotInitializedException;
|
||||
use Symfony\Component\HttpFoundation\IpUtils;
|
||||
use Symfony\Component\HttpKernel\Exception\HttpException;
|
||||
|
||||
class CheckTenantForMaintenanceMode extends CheckForMaintenanceMode
|
||||
{
|
||||
|
|
|
|||
|
|
@ -29,13 +29,13 @@ class InitializeTenancyByDomain extends IdentificationMiddleware
|
|||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle($request, Closure $next)
|
||||
{
|
||||
return $this->initializeTenancy(
|
||||
$request, $next, $request->getHost()
|
||||
$request,
|
||||
$next,
|
||||
$request->getHost()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,8 +13,6 @@ class InitializeTenancyByDomainOrSubdomain
|
|||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle($request, Closure $next)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -38,7 +38,9 @@ class InitializeTenancyByPath extends IdentificationMiddleware
|
|||
// simply injected into some route controller action.
|
||||
if ($route->parameterNames()[0] === PathTenantResolver::$tenantParameterName) {
|
||||
return $this->initializeTenancy(
|
||||
$request, $next, $route
|
||||
$request,
|
||||
$next,
|
||||
$route
|
||||
);
|
||||
} else {
|
||||
throw new RouteIsMissingTenantParameterException;
|
||||
|
|
|
|||
|
|
@ -36,8 +36,6 @@ class InitializeTenancyByRequestData extends IdentificationMiddleware
|
|||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle($request, Closure $next)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -28,8 +28,6 @@ class InitializeTenancyBySubdomain extends InitializeTenancyByDomain
|
|||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle($request, Closure $next)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -75,7 +75,6 @@ abstract class CachedTenantResolver implements TenantResolver
|
|||
/**
|
||||
* Get all the arg combinations for resolve() that can be used to find this tenant.
|
||||
*
|
||||
* @param Tenant $tenant
|
||||
* @return array[]
|
||||
*/
|
||||
abstract public function getArgsForTenant(Tenant $tenant): array;
|
||||
|
|
|
|||
|
|
@ -27,7 +27,6 @@ class Tenancy
|
|||
/**
|
||||
* Initializes the tenant.
|
||||
* @param Tenant|int|string $tenant
|
||||
* @return void
|
||||
*/
|
||||
public function initialize($tenant): void
|
||||
{
|
||||
|
|
@ -106,9 +105,6 @@ class Tenancy
|
|||
/**
|
||||
* Run a callback in the central context.
|
||||
* Atomic, safely reverts to previous context.
|
||||
*
|
||||
* @param callable $callback
|
||||
* @return mixed
|
||||
*/
|
||||
public function central(callable $callback)
|
||||
{
|
||||
|
|
@ -132,7 +128,6 @@ class Tenancy
|
|||
* More performant than running $tenant->run() one by one.
|
||||
*
|
||||
* @param Tenant[]|\Traversable|string[]|null $tenants
|
||||
* @param callable $callback
|
||||
* @return void
|
||||
*/
|
||||
public function runForMultiple($tenants, callable $callback)
|
||||
|
|
|
|||
|
|
@ -15,8 +15,6 @@ class TenancyServiceProvider extends ServiceProvider
|
|||
{
|
||||
/**
|
||||
* Register services.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register(): void
|
||||
{
|
||||
|
|
@ -76,8 +74,6 @@ class TenancyServiceProvider extends ServiceProvider
|
|||
|
||||
/**
|
||||
* Bootstrap services.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot(): void
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue