initial commit

This commit is contained in:
TheOnlyMace
2026-05-17 13:26:14 +02:00
commit 75299b723d
176 changed files with 20327 additions and 0 deletions

View 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 !== '';
}
}