36 lines
1.0 KiB
PHP
36 lines
1.0 KiB
PHP
<?php
|
|
|
|
namespace App\Integrations\Domain\Transformers;
|
|
|
|
use App\Integrations\Domain\DTOs\DnsServerData;
|
|
|
|
class DnsServerTransformer
|
|
{
|
|
public function transform(array|object $row): DnsServerData
|
|
{
|
|
$row = (array) $row;
|
|
|
|
return new DnsServerData(
|
|
legacyId: (int) $row['id'],
|
|
name: $row['name'] ?: null,
|
|
ipAddress: $row['ip_address'],
|
|
username: $row['username'] ?: 'root',
|
|
// source ciphertext was encrypted with a different app's APP_KEY, Crypt::decryptString() will fail until re-entered
|
|
password: $row['password'],
|
|
apiKey: $row['api_key'] ?: null,
|
|
status: $row['status'] ?: 'activated',
|
|
createdAt: $this->nullableDate($row['created_at'] ?? null),
|
|
updatedAt: $this->nullableDate($row['updated_at'] ?? null),
|
|
);
|
|
}
|
|
|
|
private function nullableDate(?string $value): ?string
|
|
{
|
|
if (! $value || (int) substr($value, 0, 4) < 1970) {
|
|
return null;
|
|
}
|
|
|
|
return $value;
|
|
}
|
|
}
|