From 00cb10f029162ac92b10b8fce8867be222d16916 Mon Sep 17 00:00:00 2001 From: hide_d Date: Sat, 15 Sep 2018 00:39:03 +0900 Subject: [PATCH] =?UTF-8?q?BaseCommand=EC=97=90=20'=EB=8C=80=EC=83=81?= =?UTF-8?q?=EC=9D=B4=20=EC=A7=80=EC=A0=95=EB=90=98=EC=A7=80=20=EC=95=8A?= =?UTF-8?q?=EC=95=84'=20=EB=8C=80=EB=9E=B5=EC=A0=81=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=EA=B0=80=EB=8A=A5=EC=84=B1=EC=9D=84=20=EC=B6=94=EC=B8=A1?= =?UTF-8?q?=ED=95=B4=EC=95=BC=ED=95=98=EB=8A=94=20=EA=B2=BD=EC=9A=B0=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hwe/sammo/Command/BaseCommand.php | 38 ++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/hwe/sammo/Command/BaseCommand.php b/hwe/sammo/Command/BaseCommand.php index a38c4436..3ac092d2 100644 --- a/hwe/sammo/Command/BaseCommand.php +++ b/hwe/sammo/Command/BaseCommand.php @@ -31,6 +31,7 @@ abstract class BaseCommand{ protected $reason = null; protected $constraints = null; + protected $constraintsLight = null; protected $logger; @@ -41,8 +42,14 @@ abstract class BaseCommand{ $this->arg = $arg; $this->init(); } + + protected function resetTestCache():void{ + $this->reason = null; + $this->available = null; + } protected function setCity(array $args=null){ + $this->resetTestCache(); $db = DB::db(); if($args == null){ $this->city = $this->generalObj->getRawCity(); @@ -60,6 +67,7 @@ abstract class BaseCommand{ } protected function setNation(?array $args = null){ + $this->resetTestCache(); if($args == null){ $this->nation = $this->generalObj->getStaticNation(); return; @@ -70,15 +78,18 @@ abstract class BaseCommand{ } protected function setDestGeneralFromObj(General $destGeneral){ + $this->resetTestCache(); $this->destGeneral = $destGeneral->getRaw(); } protected function setDestGeneral(int $generalNo, array $args){ + $this->resetTestCache(); $db = DB::db(); $this->destGeneral = $db->queryFirstRow('SELECT %lb FROM general WHERE no=%i', $args, $generalNo); } protected function setDestCity(int $cityNo, ?array $args){ + $this->resetTestCache(); $db = DB::db(); if($args == null){ $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){ + $this->resetTestCache(); if($args == null){ $this->destNation = getNationStaticInfo($nationNo); return; @@ -107,12 +119,16 @@ abstract class BaseCommand{ return $this->logger; } - public function test():?string{ + public function test(bool $fullCheck):?string{ if($this->constraints === null){ throw new \InvalidArgumentException('인자가 제대로 설정되지 않았습니다'); } - $this->reason = Constraint::testAll($this->constraints, [ + if($this->reason){ + return $this->reason; + } + + $constraintInput = [ 'general'=>$this->generalObj->getRaw(), 'city'=>$this->city, 'nation'=>$this->city, @@ -121,17 +137,23 @@ abstract class BaseCommand{ 'destGeneral'=>$this->destGeneral, 'destCity'=>$this->destCity, '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; return $this->reason; } - public function isAvailable():bool { - if($this->available === null){ - $this->test(); + public function isAvailable(bool $fullCheck=true):bool { + if($this->available !== null){ + return $this->available; } - return $this->available; - + + return $this->test($fullCheck) === null; } abstract public function getCost():array;