49 lines
1.3 KiB
PHP
49 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace lib\Models;
|
|
|
|
use lib\Core\Model as Core;
|
|
|
|
abstract class CommonModel extends Core
|
|
{
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
} //
|
|
abstract public function getEntityClass(): string;
|
|
|
|
// self:: → 컴파일 타임에 결정되므로 BaseModel의 상수를 참조하게 됨.
|
|
// static:: → 실행 타임에 결정되므로 상속받은 클래스의 상수를 참조함.
|
|
final public function getTable(): string
|
|
{
|
|
return constant("static::TABLE");
|
|
}
|
|
final public function getPKField(): string
|
|
{
|
|
return constant("static::PKField");
|
|
}
|
|
final public function getTitleField(): string
|
|
{
|
|
return constant("static::TitleField");
|
|
}
|
|
public function getEntity(mixed $result = null): mixed
|
|
{
|
|
if (!$result) {
|
|
$result = $this->getResult();
|
|
if (!$result) { //결과값이 없으면 null
|
|
return $result;
|
|
}
|
|
}
|
|
$entityClass = $this->getEntityClass();
|
|
return new $entityClass($result);
|
|
}
|
|
public function getEntitys(): array
|
|
{
|
|
$entitys = [];
|
|
foreach ($this->getResults() as $result) {
|
|
$entitys[] = $this->getEntity($result);
|
|
}
|
|
return $entitys;
|
|
} //
|
|
} //Class
|