BaseCommand에 '대상이 지정되지 않아' 대략적으로 가능성을 추측해야하는 경우 추가

This commit is contained in:
2018-09-15 00:39:03 +09:00
parent 2a461e53b1
commit 96b8b8fd07
+30 -8
View File
@@ -31,6 +31,7 @@ abstract class BaseCommand{
protected $reason = null; protected $reason = null;
protected $constraints = null; protected $constraints = null;
protected $constraintsLight = null;
protected $logger; protected $logger;
@@ -41,8 +42,14 @@ abstract class BaseCommand{
$this->arg = $arg; $this->arg = $arg;
$this->init(); $this->init();
} }
protected function resetTestCache():void{
$this->reason = null;
$this->available = null;
}
protected function setCity(array $args=null){ protected function setCity(array $args=null){
$this->resetTestCache();
$db = DB::db(); $db = DB::db();
if($args == null){ if($args == null){
$this->city = $this->generalObj->getRawCity(); $this->city = $this->generalObj->getRawCity();
@@ -60,6 +67,7 @@ abstract class BaseCommand{
} }
protected function setNation(?array $args = null){ protected function setNation(?array $args = null){
$this->resetTestCache();
if($args == null){ if($args == null){
$this->nation = $this->generalObj->getStaticNation(); $this->nation = $this->generalObj->getStaticNation();
return; return;
@@ -70,15 +78,18 @@ abstract class BaseCommand{
} }
protected function setDestGeneralFromObj(General $destGeneral){ protected function setDestGeneralFromObj(General $destGeneral){
$this->resetTestCache();
$this->destGeneral = $destGeneral->getRaw(); $this->destGeneral = $destGeneral->getRaw();
} }
protected function setDestGeneral(int $generalNo, array $args){ protected function setDestGeneral(int $generalNo, array $args){
$this->resetTestCache();
$db = DB::db(); $db = DB::db();
$this->destGeneral = $db->queryFirstRow('SELECT %lb FROM general WHERE no=%i', $args, $generalNo); $this->destGeneral = $db->queryFirstRow('SELECT %lb FROM general WHERE no=%i', $args, $generalNo);
} }
protected function setDestCity(int $cityNo, ?array $args){ protected function setDestCity(int $cityNo, ?array $args){
$this->resetTestCache();
$db = DB::db(); $db = DB::db();
if($args == null){ if($args == null){
$this->destCity = $db->queryFirstRow('SELECT * FROM city WHERE city=%i', $cityNo); $this->destCity = $db->queryFirstRow('SELECT * FROM city WHERE city=%i', $cityNo);
@@ -88,6 +99,7 @@ abstract class BaseCommand{
} }
protected function setDestNation(int $nationNo, ?array $args = null){ protected function setDestNation(int $nationNo, ?array $args = null){
$this->resetTestCache();
if($args == null){ if($args == null){
$this->destNation = getNationStaticInfo($nationNo); $this->destNation = getNationStaticInfo($nationNo);
return; return;
@@ -107,12 +119,16 @@ abstract class BaseCommand{
return $this->logger; return $this->logger;
} }
public function test():?string{ public function test(bool $fullCheck):?string{
if($this->constraints === null){ if($this->constraints === null){
throw new \InvalidArgumentException('인자가 제대로 설정되지 않았습니다'); throw new \InvalidArgumentException('인자가 제대로 설정되지 않았습니다');
} }
$this->reason = Constraint::testAll($this->constraints, [ if($this->reason){
return $this->reason;
}
$constraintInput = [
'general'=>$this->generalObj->getRaw(), 'general'=>$this->generalObj->getRaw(),
'city'=>$this->city, 'city'=>$this->city,
'nation'=>$this->city, 'nation'=>$this->city,
@@ -121,17 +137,23 @@ abstract class BaseCommand{
'destGeneral'=>$this->destGeneral, 'destGeneral'=>$this->destGeneral,
'destCity'=>$this->destCity, 'destCity'=>$this->destCity,
'destNation'=>$this->destNation, 'destNation'=>$this->destNation,
]); ];
if(!$fullCheck && $this->constraintsLight){
return Constraint::testAll($this->constraintsLight, $constraintInput);
}
$this->reason = Constraint::testAll($this->constraints, $constraintInput);
$this->available = $this->reason === null; $this->available = $this->reason === null;
return $this->reason; return $this->reason;
} }
public function isAvailable():bool { public function isAvailable(bool $fullCheck=true):bool {
if($this->available === null){ if($this->available !== null){
$this->test(); return $this->available;
} }
return $this->available;
return $this->test($fullCheck) === null;
} }
abstract public function getCost():array; abstract public function getCost():array;