mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-17 03:44:06 +00:00
* Laravel 7 support * Remove language from travis.yml * Fix travis.yml * Consistent indentation in travis.yml * Use dev-master for phpcov * Cleanup * switch up envs * verify both laravel versions are used * 6 -> 7 * Fix travis yml * Use stable phpcov * Different installation for Laravel 7 * Indentation * Fix dockerfile * Fix indentation * Fix tests * Remove fail() calls
104 lines
3.7 KiB
PHP
104 lines
3.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Stancl\Tenancy\Commands;
|
|
|
|
use Illuminate\Console\Command;
|
|
|
|
class Install extends Command
|
|
{
|
|
/**
|
|
* The name and signature of the console command.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $signature = 'tenancy:install';
|
|
|
|
/**
|
|
* The console command description.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $description = 'Install stancl/tenancy.';
|
|
|
|
/**
|
|
* Execute the console command.
|
|
*
|
|
* @return mixed
|
|
*/
|
|
public function handle()
|
|
{
|
|
$this->comment('Installing stancl/tenancy...');
|
|
$this->callSilent('vendor:publish', [
|
|
'--provider' => 'Stancl\Tenancy\TenancyServiceProvider',
|
|
'--tag' => 'config',
|
|
]);
|
|
$this->info('✔️ Created config/tenancy.php');
|
|
|
|
$newKernel = $this->setMiddlewarePriority();
|
|
|
|
$newKernel = str_replace("'web' => [", "'web' => [
|
|
\Stancl\Tenancy\Middleware\PreventAccessFromTenantDomains::class,", $newKernel);
|
|
|
|
$newKernel = str_replace("'api' => [", "'api' => [
|
|
\Stancl\Tenancy\Middleware\PreventAccessFromTenantDomains::class,", $newKernel);
|
|
|
|
file_put_contents(app_path('Http/Kernel.php'), $newKernel);
|
|
$this->info('✔️ Set middleware priority');
|
|
|
|
if (! file_exists(base_path('routes/tenant.php'))) {
|
|
file_put_contents(base_path('routes/tenant.php'), file_get_contents(__DIR__ . '/../../assets/tenant_routes.php.stub'));
|
|
$this->info('✔️ Created routes/tenant.php');
|
|
} else {
|
|
$this->info('Found routes/tenant.php.');
|
|
}
|
|
|
|
$this->line('');
|
|
$this->line('This package lets you store data about tenants either in Redis or in a relational database like MySQL. To store data about tenants in a relational database, you need a few database tables.');
|
|
if ($this->confirm('Do you wish to publish the migrations that create these tables?', true)) {
|
|
$this->callSilent('vendor:publish', [
|
|
'--provider' => 'Stancl\Tenancy\TenancyServiceProvider',
|
|
'--tag' => 'migrations',
|
|
]);
|
|
$this->info('✔️ Created migrations. Remember to run [php artisan migrate]!');
|
|
}
|
|
|
|
if (! is_dir(database_path('migrations/tenant'))) {
|
|
mkdir(database_path('migrations/tenant'));
|
|
$this->info('✔️ Created database/migrations/tenant folder.');
|
|
}
|
|
|
|
$this->comment('✨️ stancl/tenancy installed successfully.');
|
|
}
|
|
|
|
protected function setMiddlewarePriority(): string
|
|
{
|
|
if (app()->version()[0] === '6') {
|
|
return str_replace(
|
|
'protected $middlewarePriority = [',
|
|
"protected \$middlewarePriority = [
|
|
\Stancl\Tenancy\Middleware\PreventAccessFromTenantDomains::class,
|
|
\Stancl\Tenancy\Middleware\InitializeTenancy::class,",
|
|
file_get_contents(app_path('Http/Kernel.php'))
|
|
);
|
|
} else {
|
|
return str_replace(
|
|
"];\n}",
|
|
"];\n\n protected \$middlewarePriority = [
|
|
\Stancl\Tenancy\Middleware\PreventAccessFromTenantDomains::class,
|
|
\Stancl\Tenancy\Middleware\InitializeTenancy::class,
|
|
\Illuminate\Session\Middleware\StartSession::class,
|
|
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
|
|
\Illuminate\Contracts\Auth\Middleware\AuthenticatesRequests::class,
|
|
\Illuminate\Routing\Middleware\ThrottleRequests::class,
|
|
\Illuminate\Session\Middleware\AuthenticateSession::class,
|
|
\Illuminate\Routing\Middleware\SubstituteBindings::class,
|
|
\Illuminate\Auth\Middleware\Authorize::class,
|
|
];
|
|
}",
|
|
file_get_contents(app_path('Http/Kernel.php'))
|
|
);
|
|
}
|
|
}
|
|
}
|