trafficmonitor/app/DTOs/CertificationDTO.php

38 lines
1.0 KiB
PHP

<?php
namespace App\DTOs;
use App\Services\Auth\AuthService;
use CodeIgniter\Entity\Entity; // DTO가 Entity를 상속받지 않는 경우, 필요한 경우 CommonDTO 또는 Entity 상속을 유지합니다.
class CertificationDTO extends Entity // DTO가 Entity를 상속받는 것으로 가정합니다.
{
// 💡 role의 타입을 ?string에서 ?array로 변경합니다.
public ?string $uid = null;
public ?bool $isLogin = null;
public ?string $name = null;
public ?array $role = null;
public function __construct(array $datas = [])
{
parent::__construct();
foreach ($datas as $key => $value) {
if (property_exists($this, $key)) {
$this->{$key} = $value;
}
}
}
public static function fromByAuthService(AuthService $service): self
{
return new self(
[
'isLogin' => $service->isLoggedIn(),
'uid' => $service->getUID(),
'name' => $service->getName(),
'role' => $service->getRole(), //배열(array|null)을 반환합니다.
]
);
}
}