initial commit
This commit is contained in:
74
app/Services/Hosting/DTO/CustomerProvisionData.php
Normal file
74
app/Services/Hosting/DTO/CustomerProvisionData.php
Normal file
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Hosting\DTO;
|
||||
|
||||
use App\Models\Customer;
|
||||
|
||||
readonly class CustomerProvisionData
|
||||
{
|
||||
public function __construct(
|
||||
public string $customer_name,
|
||||
public ?string $domain,
|
||||
public ?int $vmid = null,
|
||||
public ?string $ip = null,
|
||||
public ?string $public_ip = null,
|
||||
public int $cpu = 2,
|
||||
public int $ram = 2048,
|
||||
public int $disk = 32,
|
||||
public bool $behind_traefik = true,
|
||||
public ?int $ip_pool_id = null,
|
||||
) {}
|
||||
|
||||
public static function fromCustomer(Customer $customer): self
|
||||
{
|
||||
return new self(
|
||||
customer_name: $customer->name,
|
||||
domain: $customer->domain,
|
||||
vmid: $customer->vmid,
|
||||
ip: $customer->ip_address,
|
||||
public_ip: $customer->public_ip,
|
||||
cpu: $customer->cpu,
|
||||
ram: $customer->ram,
|
||||
disk: $customer->disk,
|
||||
behind_traefik: $customer->behind_traefik,
|
||||
ip_pool_id: $customer->ip_pool_id,
|
||||
);
|
||||
}
|
||||
|
||||
public static function fromArray(array $data): self
|
||||
{
|
||||
return new self(
|
||||
customer_name: (string) $data['customer_name'],
|
||||
domain: isset($data['domain']) ? (string) $data['domain'] : null,
|
||||
vmid: isset($data['vmid']) ? (int) $data['vmid'] : null,
|
||||
ip: isset($data['ip']) ? (string) $data['ip'] : null,
|
||||
public_ip: isset($data['public_ip']) ? (string) $data['public_ip'] : null,
|
||||
cpu: (int) ($data['cpu'] ?? config('hosting.defaults.cpu', 2)),
|
||||
ram: (int) ($data['ram'] ?? config('hosting.defaults.ram', 2048)),
|
||||
disk: (int) ($data['disk'] ?? config('hosting.defaults.disk', 32)),
|
||||
behind_traefik: (bool) ($data['behind_traefik'] ?? true),
|
||||
ip_pool_id: isset($data['ip_pool_id']) ? (int) $data['ip_pool_id'] : null,
|
||||
);
|
||||
}
|
||||
|
||||
public function subdomain(): string
|
||||
{
|
||||
if (! $this->domain) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$base = config('hosting.plesk.base_domain');
|
||||
$suffix = '.'.$base;
|
||||
|
||||
if (str_ends_with($this->domain, $suffix)) {
|
||||
return substr($this->domain, 0, -strlen($suffix));
|
||||
}
|
||||
|
||||
return explode('.', $this->domain)[0] ?? $this->customer_name;
|
||||
}
|
||||
|
||||
public function requiresTraefik(): bool
|
||||
{
|
||||
return $this->behind_traefik && $this->domain !== null && $this->domain !== '';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user