mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-15 17:04:03 +00:00
* Using laravel components * Ensure commands returns success * update tests * clean * bump EndBug version * Update ci.yml * Update ci.yml * Update ci.yml * revert CI changes * Update ci.yml * Update ci.yml * Update ci.yml * revert CI changes to it's original state * fix typos, improve code * improve Install & TenantList commands * php-cs-fixer * type GitHub properly Co-authored-by: Abrar Ahmad <abrar.dev99@gmail.com> Co-authored-by: Samuel Štancl <samuel@archte.ch> Co-authored-by: Samuel Štancl <samuel.stancl@gmail.com>
49 lines
1.3 KiB
PHP
49 lines
1.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Stancl\Tenancy\Commands;
|
|
|
|
use Illuminate\Console\Command;
|
|
use Illuminate\Database\Eloquent\Collection;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Stancl\Tenancy\Contracts\Tenant;
|
|
|
|
class TenantList extends Command
|
|
{
|
|
protected $signature = 'tenants:list';
|
|
|
|
protected $description = 'List tenants.';
|
|
|
|
public function handle(): int
|
|
{
|
|
$tenants = tenancy()->query()->cursor();
|
|
|
|
$this->components->info("Listing {$tenants->count()} tenants.");
|
|
|
|
foreach ($tenants as $tenant) {
|
|
/** @var Model&Tenant $tenant */
|
|
$this->components->twoColumnDetail($this->tenantCLI($tenant), $this->domainsCLI($tenant->domains));
|
|
}
|
|
|
|
$this->newLine();
|
|
|
|
return 0;
|
|
}
|
|
|
|
/** Generate the visual CLI output for the tenant name. */
|
|
protected function tenantCLI(Model&Tenant $tenant): string
|
|
{
|
|
return "<fg=yellow>{$tenant->getTenantKeyName()}: {$tenant->getTenantKey()}</>";
|
|
}
|
|
|
|
/** Generate the visual CLI output for the domain names. */
|
|
protected function domainsCLI(?Collection $domains): ?string
|
|
{
|
|
if (! $domains) {
|
|
return null;
|
|
}
|
|
|
|
return "<fg=blue;options=bold>{$domains->pluck('domain')->implode(' / ')}</>";
|
|
}
|
|
}
|