114 lines
3.5 KiB
PHP
114 lines
3.5 KiB
PHP
<?php
|
|
|
|
namespace App\Models\Cloudflare;
|
|
|
|
use App\Entities\Cloudflare\ZoneEntity;
|
|
use App\Entities\Cloudflare\FirewallEntity;
|
|
use App\Models\CommonModel;
|
|
|
|
class FirewallModel extends CommonModel
|
|
{
|
|
const TABLE = "cloudflarefirewall";
|
|
const PK = "uid";
|
|
const TITLE = "description";
|
|
const PARENT = "zone_uid";
|
|
protected $table = self::TABLE;
|
|
protected $primaryKey = self::PK;
|
|
protected $useAutoIncrement = false;
|
|
protected $returnType = FirewallEntity::class; //object,array,entity명::class
|
|
protected $allowedFields = [self::PK, self::PARENT, 'rulesetid', self::TITLE, 'mode', 'description', 'expression', 'enabled', 'updated_at', 'crated_at'];
|
|
protected $useTimestamps = true;
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
}
|
|
public function getTitleField(): string
|
|
{
|
|
return self::TITLE;
|
|
}
|
|
public function getFields(): array
|
|
{
|
|
return [self::PARENT, 'mode', 'description', 'expression', 'enabled'];
|
|
}
|
|
public function getFilterFields(): array
|
|
{
|
|
return [self::PARENT, 'mode', 'enabled'];
|
|
}
|
|
public function getBatchJobFields(): array
|
|
{
|
|
return [];
|
|
}
|
|
public function getFieldRule(string $action, string $field): string
|
|
{
|
|
switch ($field) {
|
|
case self::PK:
|
|
$rule = "required|trim|alpha_numeric";
|
|
$rule .= $action == "create" ? "|is_unique[{$this->table}.{$field}]" : "";
|
|
break;
|
|
case self::PARENT:
|
|
$rule = "required|trim|alpha_numeric";
|
|
break;
|
|
case 'rulesetid':
|
|
$rule = "required|trim|alpha_numeric";
|
|
break;
|
|
case self::TITLE:
|
|
case "mode":
|
|
case "expression":
|
|
$rule = "required|trim|string";
|
|
break;
|
|
case "ref":
|
|
$rule = "if_exist|trim|string";
|
|
break;
|
|
case "enabled":
|
|
$rule = "required|in_list[on,off]";
|
|
break;
|
|
default:
|
|
$rule = parent::getFieldRule($action, $field);
|
|
break;
|
|
}
|
|
return $rule;
|
|
}
|
|
public function getFormFieldInputOption(string $field, array $options = []): array
|
|
{
|
|
switch ($field) {
|
|
default:
|
|
$this->orderBy(self::TITLE, 'asc');
|
|
$options = parent::getFormFieldInputOption($field, $options);
|
|
break;
|
|
}
|
|
return $options;
|
|
}
|
|
public function getEntityByPK(string $uid): null|FirewallEntity
|
|
{
|
|
$this->where(self::PK, $uid);
|
|
return $this->getEntity();
|
|
}
|
|
public function getEntityByID(string $id): null|FirewallEntity
|
|
{
|
|
$this->where(self::TITLE, $id);
|
|
return $this->getEntity();
|
|
}
|
|
public function getEntitysByParent(ZoneEntity $zone_entity)
|
|
{
|
|
$this->where(self::PARENT, $zone_entity->getPK());
|
|
return $this->getEntitys();
|
|
}
|
|
//create용
|
|
public function create(array $formDatas = []): FirewallEntity
|
|
{
|
|
return $this->create_process(new FirewallEntity(), $formDatas);
|
|
}
|
|
//modify용
|
|
public function modify(FirewallEntity $entity, array $formDatas): FirewallEntity
|
|
{
|
|
return $this->modify_process($entity, $formDatas);
|
|
}
|
|
//List 검색용
|
|
public function setList_WordFilter(string $word): void
|
|
{
|
|
$this->orLike(self::TABLE . "." . self::TITLE, $word, 'both');
|
|
$this->orLike(self::TABLE . '.expression', $word, 'both');
|
|
}
|
|
}
|