forked from devsam/core
- null && key_exists 버그 - or assign이 integer 대상이므로 직접 연산 - false 대신 0 입력한 곳 수정 - 자체 Deprecate 처리한 함수 회피 - 초기화되지 않은 [] 확인하여 처리 - sleep은 정수만 받으므로 usleep으로 변경 - 선언하지 않고 그냥 사용하던 member 변수 선언 - boolean operation 순서 틀린 부분 수정
67 lines
2.0 KiB
PHP
67 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace sammo\Constraint;
|
|
|
|
use \sammo\JosaUtil;
|
|
use \sammo\DB;
|
|
class AllowDiplomacyStatus extends Constraint{
|
|
const REQ_VALUES = Constraint::REQ_ARRAY_ARG;
|
|
|
|
protected $nationID;
|
|
protected $allowStatus = [];
|
|
protected $errMsg = null;
|
|
|
|
public function checkInputValues(bool $throwExeception=true):bool{
|
|
if(!parent::checkInputValues($throwExeception) && !$throwExeception){
|
|
return false;
|
|
}
|
|
|
|
if(count($this->arg) != 3){
|
|
if(!$throwExeception){return false; }
|
|
throw new \InvalidArgumentException("require nationID, allowStatus, errMsg tuple");
|
|
}
|
|
|
|
[$this->nationID, $this->allowStatus, $this->errMsg] = $this->arg;
|
|
if(!is_int($this->nationID)){
|
|
if(!$throwExeception){return false; }
|
|
throw new \InvalidArgumentException("nationID {$this->nationID} must be int");
|
|
}
|
|
|
|
if(!is_array($this->allowStatus)){
|
|
if(!$throwExeception){return false; }
|
|
throw new \InvalidArgumentException("allowStatus {$this->allowStatus} must be array");
|
|
}
|
|
|
|
if(!is_string($this->errMsg)){
|
|
if(!$throwExeception){return false; }
|
|
throw new \InvalidArgumentException("allowStatus {$this->errMsg} must be string");
|
|
}
|
|
|
|
foreach($this->allowStatus as $dipCode){
|
|
if(!is_int($dipCode)){
|
|
if(!$throwExeception){return false; }
|
|
throw new \InvalidArgumentException("dipCode $dipCode must be int");
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
public function test():bool{
|
|
$this->checkInputValues();
|
|
$this->tested = true;
|
|
|
|
$db = DB::db();
|
|
|
|
$state = $db->queryFirstField(
|
|
'SELECT state FROM diplomacy WHERE me = %i AND `state` IN %li LIMIT 1',
|
|
$this->nationID,
|
|
$this->allowStatus
|
|
);
|
|
if($state !== null){
|
|
return true;
|
|
}
|
|
$this->reason = $this->errMsg;
|
|
return false;
|
|
}
|
|
} |