76 lines
2.4 KiB
PHP
76 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace App\Models\Cloudflare;
|
|
|
|
use App\Entities\Cloudflare\AuthEntity;
|
|
use App\Models\CommonModel;
|
|
|
|
class AuthModel extends CommonModel
|
|
{
|
|
const TABLE = "cloudflareauth";
|
|
const PK = "uid";
|
|
const TITLE = "id";
|
|
protected $table = self::TABLE;
|
|
protected $primaryKey = self::PK;
|
|
protected $useAutoIncrement = false;
|
|
protected $returnType = AuthEntity::class; //object,array,entity명::class
|
|
protected $allowedFields = [self::PK, self::TITLE, 'authkey', 'oldkey', 'status', 'updated_at', 'created_at'];
|
|
protected $useTimestamps = true;
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
}
|
|
public function getTitleField(): string
|
|
{
|
|
return self::TITLE;
|
|
}
|
|
public function getFieldRule(string $action, string $field, array $rules): array
|
|
{
|
|
switch ($field) {
|
|
case self::TITLE:
|
|
$rules[$field] = "required|valid_emailvalid_email|is_unique[cloudflareauth.id]";
|
|
break;
|
|
case "authkey":
|
|
$rules[$field] = "required|regex_match[/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/]";;
|
|
break;
|
|
case "oldkey":
|
|
$rules[$field] = "if_exist|regex_match[/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/]";
|
|
break;
|
|
default:
|
|
$rules = parent::getFieldRule($action, $field, $rules);
|
|
break;
|
|
}
|
|
return $rules;
|
|
}
|
|
public function getFormFieldOption(string $field, array $options = []): array
|
|
{
|
|
switch ($field) {
|
|
default:
|
|
$this->orderBy(self::TITLE, 'asc');
|
|
$options = parent::getFormFieldOption($field, $options);
|
|
break;
|
|
}
|
|
return $options;
|
|
}
|
|
public function getEntityByPK(int $uid): null|AuthEntity
|
|
{
|
|
$this->where($this->getPKField(), $uid);
|
|
return $this->getEntity();
|
|
}
|
|
public function getEntityByID(string $id): null|AuthEntity
|
|
{
|
|
$this->where('id', $id);
|
|
return $this->getEntity();
|
|
}
|
|
//create용
|
|
public function create(array $formDatas = []): AuthEntity
|
|
{
|
|
return $this->create_process(new AuthEntity(), $formDatas);
|
|
}
|
|
//modify용
|
|
public function modify(AuthEntity $entity, array $formDatas): AuthEntity
|
|
{
|
|
return $this->modify_process($entity, $formDatas);
|
|
}
|
|
}
|