From 628a085ba8a6d139634b4ae0e457dddd5fda3768 Mon Sep 17 00:00:00 2001 From: hide_d Date: Sun, 28 Oct 2018 03:14:03 +0900 Subject: [PATCH] =?UTF-8?q?ReqEnvValue=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hwe/sammo/Constraint/ReqEnvValue.php | 93 ++++++++++++++++++++++++ hwe/sammo/Constraint/ReqGeneralValue.php | 13 +++- hwe/sammo/Constraint/ReqNationValue.php | 15 +++- 3 files changed, 114 insertions(+), 7 deletions(-) create mode 100644 hwe/sammo/Constraint/ReqEnvValue.php diff --git a/hwe/sammo/Constraint/ReqEnvValue.php b/hwe/sammo/Constraint/ReqEnvValue.php new file mode 100644 index 00000000..f7dbbe9a --- /dev/null +++ b/hwe/sammo/Constraint/ReqEnvValue.php @@ -0,0 +1,93 @@ +arg) == 4){ + [$this->key, $this->reqVal, $comp, $this->msg] = $this->arg; + + if(!in_array($comp, ['>', '>=', '==', '<=', '<', '!=', '===', '!=='])){ + if(!$throwExeception){return false; } + throw new \InvalidArgumentException("invalid comparator"); + } + } + else{ + if(!$throwExeception){return false; } + throw new \InvalidArgumentException("require key, reqVal, comp, errmsg"); + } + + $this->comp = $comp; + + if(!key_exists($this->key, $this->env)){ + if(!$throwExeception){return false; } + throw new \InvalidArgumentException("require {$this->key} in env"); + } + + return true; + } + + public function test():bool{ + $this->checkInputValues(); + $this->tested = true; + + $reqVal = $this->reqVal; + + + $compList = [ + '<'=>function($target, $src){ + return ($target < $src); + }, + '<='=>function($target, $src){ + return ($target <= $src); + }, + '=='=>function($target, $src){ + return ($target == $src); + }, + '!='=>function($targeta, $src){ + return ($target != $src); + }, + '==='=>function($target, $src){ + return ($target === $src); + }, + '!=='=>function($targeta, $src){ + return ($target !== $src); + }, + '>='=>function($target, $src){ + return ($target >= $src); + }, + '>'=>function($target, $src){ + return ($target > $src); + }, + ]; + + $comp = $compList[$this->comp]; + $result = ($comp)($this->env[$this->key], $reqVal); + + if($result === true){ + return true; + } + + $this->reason = $this->msg; + + return false; + } +} \ No newline at end of file diff --git a/hwe/sammo/Constraint/ReqGeneralValue.php b/hwe/sammo/Constraint/ReqGeneralValue.php index 93827f8a..75e6c210 100644 --- a/hwe/sammo/Constraint/ReqGeneralValue.php +++ b/hwe/sammo/Constraint/ReqGeneralValue.php @@ -15,6 +15,7 @@ class RegGeneralValue extends Constraint{ protected $maxKey; protected $keyNick; protected $reqVal; + protected $comp; public function checkInputValues(bool $throwExeception=true){ if(!parent::checkInputValues($throwExeception) && !$throwException){ @@ -24,7 +25,7 @@ class RegGeneralValue extends Constraint{ if(count($this->arg) == 4){ [$this->key, $this->keyNick, $comp, $this->reqVal] = $this->arg; - if(!in_array($comp, ['>', '>=', '==', '<=', '<', '!='])){ + if(!in_array($comp, ['>', '>=', '==', '<=', '<', '!=', '===', '!=='])){ if(!$throwExeception){return false; } throw new \InvalidArgumentException("invalid comparator"); } @@ -85,7 +86,13 @@ class RegGeneralValue extends Constraint{ return ($target == $src)?true:"올바르지 않은 {$keyNick} 입니다."; }, '!='=>function($targeta, $src)use($keyNick){ - return ($target == $src)?true:"올바르지 않은 {$keyNick} 입니다."; + return ($target != $src)?true:"올바르지 않은 {$keyNick} 입니다."; + }, + '==='=>function($target, $src)use($keyNick){ + return ($target === $src)?true:"올바르지 않은 {$keyNick} 입니다."; + }, + '!=='=>function($targeta, $src)use($keyNick){ + return ($target !== $src)?true:"올바르지 않은 {$keyNick} 입니다."; }, '>='=>function($target, $src){ if($target >= $src){ @@ -97,7 +104,7 @@ class RegGeneralValue extends Constraint{ return '부족합니다.'; }, '>'=>function($target, $src){ - return $target >= $src; + return $target > $src; if($src == 0){ return '없습니다'; } diff --git a/hwe/sammo/Constraint/ReqNationValue.php b/hwe/sammo/Constraint/ReqNationValue.php index 89f5c5ea..a35892de 100644 --- a/hwe/sammo/Constraint/ReqNationValue.php +++ b/hwe/sammo/Constraint/ReqNationValue.php @@ -8,13 +8,14 @@ use \sammo\Util; /** * 범용으로 사용 가능한 국가 변수 검사도구 */ -class RegGeneralValue extends Constraint{ +class ReqNationValue extends Constraint{ const REQ_VALUES = Constraint::REQ_NATION|Constraint::REQ_ARRAY_ARG; protected $key; protected $maxKey; protected $keyNick; protected $reqVal; + protected $comp; public function checkInputValues(bool $throwExeception=true){ if(!parent::checkInputValues($throwExeception) && !$throwException){ @@ -24,7 +25,7 @@ class RegGeneralValue extends Constraint{ if(count($this->arg) == 4){ [$this->key, $this->keyNick, $this->reqVal, $comp] = $this->arg; - if(!in_array($comp, ['>', '>=', '==', '<=', '<', '!='])){ + if(!in_array($comp, ['>', '>=', '==', '<=', '<', '!=', '===', '!=='])){ if(!$throwExeception){return false; } throw new \InvalidArgumentException("invalid comparator"); } @@ -85,7 +86,13 @@ class RegGeneralValue extends Constraint{ return ($target == $src)?true:"올바르지 않은 {$keyNick} 입니다."; }, '!='=>function($targeta, $src)use($keyNick){ - return ($target == $src)?true:"올바르지 않은 {$keyNick} 입니다."; + return ($target != $src)?true:"올바르지 않은 {$keyNick} 입니다."; + }, + '==='=>function($target, $src)use($keyNick){ + return ($target === $src)?true:"올바르지 않은 {$keyNick} 입니다."; + }, + '!=='=>function($targeta, $src)use($keyNick){ + return ($target !== $src)?true:"올바르지 않은 {$keyNick} 입니다."; }, '>='=>function($target, $src){ if($target >= $src){ @@ -97,7 +104,7 @@ class RegGeneralValue extends Constraint{ return '부족합니다.'; }, '>'=>function($target, $src){ - return $target >= $src; + return $target > $src; if($src == 0){ return '없습니다'; }