38 lines
1.0 KiB
PHP
38 lines
1.0 KiB
PHP
<?php
|
|
|
|
namespace App\DTOs;
|
|
|
|
use App\Libraries\AuthContext;
|
|
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 byAuthContext(AuthContext $authContext): self
|
|
{
|
|
return new self(
|
|
[
|
|
'isLogin' => $authContext->isLoggedIn(),
|
|
'uid' => $authContext->getUID(),
|
|
'name' => $authContext->getName(),
|
|
'role' => $authContext->getRole(), //배열(array|null)을 반환합니다.
|
|
]
|
|
);
|
|
}
|
|
}
|