mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 18:04:03 +00:00
Clean up
This commit is contained in:
parent
cbaa775876
commit
c9903cd43c
19 changed files with 212 additions and 215 deletions
|
|
@ -13,14 +13,14 @@ class CacheManager extends BaseCacheManager
|
|||
$tags = [config('tenancy.cache.tag_base') . tenant('id')];
|
||||
|
||||
if ($method === 'tags') {
|
||||
if (\count($parameters) !== 1) {
|
||||
if (count($parameters) !== 1) {
|
||||
throw new \Exception("Method tags() takes exactly 1 argument. {count($parameters)} passed.");
|
||||
}
|
||||
|
||||
$names = $parameters[0];
|
||||
$names = (array) $names; // cache()->tags('foo') https://laravel.com/docs/5.7/cache#removing-tagged-cache-items
|
||||
|
||||
return $this->store()->tags(\array_merge($tags, $names));
|
||||
return $this->store()->tags(array_merge($tags, $names));
|
||||
}
|
||||
|
||||
return $this->store()->tags($tags)->$method(...$parameters);
|
||||
|
|
|
|||
|
|
@ -36,21 +36,21 @@ class Install extends Command
|
|||
]);
|
||||
$this->info('✔️ Created config/tenancy.php');
|
||||
|
||||
$newKernel = \str_replace(
|
||||
$newKernel = str_replace(
|
||||
'protected $middlewarePriority = [',
|
||||
"protected \$middlewarePriority = [
|
||||
\Stancl\Tenancy\Middleware\PreventAccessFromTenantDomains::class,
|
||||
\Stancl\Tenancy\Middleware\InitializeTenancy::class,",
|
||||
\file_get_contents(app_path('Http/Kernel.php'))
|
||||
file_get_contents(app_path('Http/Kernel.php'))
|
||||
);
|
||||
|
||||
$newKernel = \str_replace("'web' => [", "'web' => [
|
||||
$newKernel = str_replace("'web' => [", "'web' => [
|
||||
\Stancl\Tenancy\Middleware\PreventAccessFromTenantDomains::class,", $newKernel);
|
||||
|
||||
\file_put_contents(app_path('Http/Kernel.php'), $newKernel);
|
||||
file_put_contents(app_path('Http/Kernel.php'), $newKernel);
|
||||
$this->info('✔️ Set middleware priority');
|
||||
|
||||
\file_put_contents(
|
||||
file_put_contents(
|
||||
base_path('routes/tenant.php'),
|
||||
"<?php
|
||||
|
||||
|
|
@ -82,8 +82,8 @@ Route::get('/', function () {
|
|||
$this->info('✔️ Created migration.');
|
||||
}
|
||||
|
||||
if (! \is_dir(database_path('migrations/tenant'))) {
|
||||
\mkdir(database_path('migrations/tenant'));
|
||||
if (! is_dir(database_path('migrations/tenant'))) {
|
||||
mkdir(database_path('migrations/tenant'));
|
||||
$this->info('✔️ Created database/migrations/tenant folder.');
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ class Run extends Command
|
|||
|
||||
$callback = function ($prefix = '') {
|
||||
return function ($arguments, $argument) use ($prefix) {
|
||||
[$key, $value] = \explode('=', $argument, 2);
|
||||
[$key, $value] = explode('=', $argument, 2);
|
||||
$arguments[$prefix . $key] = $value;
|
||||
|
||||
return $arguments;
|
||||
|
|
@ -47,13 +47,13 @@ class Run extends Command
|
|||
};
|
||||
|
||||
// Turns ['foo=bar', 'abc=xyz=zzz'] into ['foo' => 'bar', 'abc' => 'xyz=zzz']
|
||||
$arguments = \array_reduce($this->option('argument'), $callback(), []);
|
||||
$arguments = array_reduce($this->option('argument'), $callback(), []);
|
||||
|
||||
// Turns ['foo=bar', 'abc=xyz=zzz'] into ['--foo' => 'bar', '--abc' => 'xyz=zzz']
|
||||
$options = \array_reduce($this->option('option'), $callback('--'), []);
|
||||
$options = array_reduce($this->option('option'), $callback('--'), []);
|
||||
|
||||
// Run command
|
||||
$this->call($this->argument('commandname'), \array_merge($arguments, $options));
|
||||
$this->call($this->argument('commandname'), array_merge($arguments, $options));
|
||||
|
||||
tenancy()->endTenancy();
|
||||
});
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ use Stancl\Tenancy\Tenant;
|
|||
|
||||
interface TenancyBootstrapper
|
||||
{
|
||||
public function start(Tenant $tenant); // todo2 TenantManager instead of Tenant
|
||||
public function start(Tenant $tenant);
|
||||
|
||||
public function end();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ class TelescopeTags implements Feature
|
|||
if (in_array('tenancy', optional(request()->route())->middleware() ?? [])) {
|
||||
$tags = array_merge($tags, [
|
||||
'tenant:' . tenant('id'),
|
||||
// todo2 domain?
|
||||
// todo3 domain?
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -19,8 +19,8 @@ class PreventAccessFromTenantDomains
|
|||
{
|
||||
// If the domain is not in exempt domains, it's a tenant domain.
|
||||
// Tenant domains can't have routes without tenancy middleware.
|
||||
if (! \in_array(request()->getHost(), config('tenancy.exempt_domains')) &&
|
||||
! \in_array('tenancy', request()->route()->middleware())) {
|
||||
if (! in_array(request()->getHost(), config('tenancy.exempt_domains')) &&
|
||||
! in_array('tenancy', request()->route()->middleware())) {
|
||||
abort(404);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ class FilesystemTenancyBootstrapper implements TenancyBootstrapper
|
|||
foreach ($this->app['config']['tenancy.filesystem.disks'] as $disk) {
|
||||
$this->originalPaths['disks'][$disk] = Storage::disk($disk)->getAdapter()->getPathPrefix();
|
||||
|
||||
if ($root = \str_replace('%storage_path%', storage_path(), $this->app['config']["tenancy.filesystem.root_override.{$disk}"])) {
|
||||
if ($root = str_replace('%storage_path%', storage_path(), $this->app['config']["tenancy.filesystem.root_override.{$disk}"])) {
|
||||
Storage::disk($disk)->getAdapter()->setPathPrefix($root);
|
||||
} else {
|
||||
$root = $this->app['config']["filesystems.disks.{$disk}.root"];
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ class QueueTenancyBootstrapper implements TenancyBootstrapper
|
|||
|
||||
$this->app['queue']->createPayloadUsing([$this, 'createPayload']);
|
||||
$this->app['events']->listen(\Illuminate\Queue\Events\JobProcessing::class, function ($event) {
|
||||
if (\array_key_exists('tenant_id', $event->job->payload())) {
|
||||
if (array_key_exists('tenant_id', $event->job->payload())) {
|
||||
tenancy()->initById($event->job->payload()['tenant_id']);
|
||||
}
|
||||
});
|
||||
|
|
@ -50,7 +50,7 @@ class QueueTenancyBootstrapper implements TenancyBootstrapper
|
|||
'tenant_id' => $id,
|
||||
'tags' => [
|
||||
"tenant:$id",
|
||||
// todo2 domain
|
||||
// todo3 domain
|
||||
],
|
||||
];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@ use Stancl\Tenancy\Contracts\UniqueIdentifierGenerator;
|
|||
use Stancl\Tenancy\Exceptions\TenantStorageException;
|
||||
|
||||
// todo2 write tests for updating the tenant
|
||||
// todo2 addDomain(), removeDomain()
|
||||
|
||||
/**
|
||||
* @internal Class is subject to breaking changes in minor and patch versions.
|
||||
|
|
|
|||
|
|
@ -11,8 +11,8 @@ class TenantRouteServiceProvider extends RouteServiceProvider
|
|||
{
|
||||
public function map()
|
||||
{
|
||||
if (! \in_array(request()->getHost(), $this->app['config']['tenancy.exempt_domains'] ?? [])
|
||||
&& \file_exists(base_path('routes/tenant.php'))) {
|
||||
if (! in_array(request()->getHost(), $this->app['config']['tenancy.exempt_domains'] ?? [])
|
||||
&& file_exists(base_path('routes/tenant.php'))) {
|
||||
Route::middleware(['web', 'tenancy'])
|
||||
->namespace($this->app['config']['tenant_route_namespace'] ?? 'App\Http\Controllers')
|
||||
->group(base_path('routes/tenant.php'));
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ trait HasATenantsOption
|
|||
{
|
||||
protected function getOptions()
|
||||
{
|
||||
return \array_merge([
|
||||
return array_merge([
|
||||
['tenants', null, InputOption::VALUE_IS_ARRAY | InputOption::VALUE_OPTIONAL, '', null],
|
||||
], parent::getOptions());
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue