ReqEnvValue 추가
This commit is contained in:
@@ -0,0 +1,93 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace sammo\Constraint;
|
||||||
|
|
||||||
|
use \sammo\JosaUtil;
|
||||||
|
use \sammo\Util;
|
||||||
|
use \sammo\DB;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 범용으로 사용 가능한 국가 변수 검사도구
|
||||||
|
*/
|
||||||
|
class ReqEnvValue extends Constraint{
|
||||||
|
const REQ_VALUES = Constraint::REQ_ARRAY_ARG;
|
||||||
|
|
||||||
|
protected $key;
|
||||||
|
protected $reqVal;
|
||||||
|
protected $comp;
|
||||||
|
protected $msg;
|
||||||
|
|
||||||
|
public function checkInputValues(bool $throwExeception=true){
|
||||||
|
if(!parent::checkInputValues($throwExeception) && !$throwException){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(count($this->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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -15,6 +15,7 @@ class RegGeneralValue extends Constraint{
|
|||||||
protected $maxKey;
|
protected $maxKey;
|
||||||
protected $keyNick;
|
protected $keyNick;
|
||||||
protected $reqVal;
|
protected $reqVal;
|
||||||
|
protected $comp;
|
||||||
|
|
||||||
public function checkInputValues(bool $throwExeception=true){
|
public function checkInputValues(bool $throwExeception=true){
|
||||||
if(!parent::checkInputValues($throwExeception) && !$throwException){
|
if(!parent::checkInputValues($throwExeception) && !$throwException){
|
||||||
@@ -24,7 +25,7 @@ class RegGeneralValue extends Constraint{
|
|||||||
if(count($this->arg) == 4){
|
if(count($this->arg) == 4){
|
||||||
[$this->key, $this->keyNick, $comp, $this->reqVal] = $this->arg;
|
[$this->key, $this->keyNick, $comp, $this->reqVal] = $this->arg;
|
||||||
|
|
||||||
if(!in_array($comp, ['>', '>=', '==', '<=', '<', '!='])){
|
if(!in_array($comp, ['>', '>=', '==', '<=', '<', '!=', '===', '!=='])){
|
||||||
if(!$throwExeception){return false; }
|
if(!$throwExeception){return false; }
|
||||||
throw new \InvalidArgumentException("invalid comparator");
|
throw new \InvalidArgumentException("invalid comparator");
|
||||||
}
|
}
|
||||||
@@ -85,7 +86,13 @@ class RegGeneralValue extends Constraint{
|
|||||||
return ($target == $src)?true:"올바르지 않은 {$keyNick} 입니다.";
|
return ($target == $src)?true:"올바르지 않은 {$keyNick} 입니다.";
|
||||||
},
|
},
|
||||||
'!='=>function($targeta, $src)use($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){
|
'>='=>function($target, $src){
|
||||||
if($target >= $src){
|
if($target >= $src){
|
||||||
@@ -97,7 +104,7 @@ class RegGeneralValue extends Constraint{
|
|||||||
return '부족합니다.';
|
return '부족합니다.';
|
||||||
},
|
},
|
||||||
'>'=>function($target, $src){
|
'>'=>function($target, $src){
|
||||||
return $target >= $src;
|
return $target > $src;
|
||||||
if($src == 0){
|
if($src == 0){
|
||||||
return '없습니다';
|
return '없습니다';
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
const REQ_VALUES = Constraint::REQ_NATION|Constraint::REQ_ARRAY_ARG;
|
||||||
|
|
||||||
protected $key;
|
protected $key;
|
||||||
protected $maxKey;
|
protected $maxKey;
|
||||||
protected $keyNick;
|
protected $keyNick;
|
||||||
protected $reqVal;
|
protected $reqVal;
|
||||||
|
protected $comp;
|
||||||
|
|
||||||
public function checkInputValues(bool $throwExeception=true){
|
public function checkInputValues(bool $throwExeception=true){
|
||||||
if(!parent::checkInputValues($throwExeception) && !$throwException){
|
if(!parent::checkInputValues($throwExeception) && !$throwException){
|
||||||
@@ -24,7 +25,7 @@ class RegGeneralValue extends Constraint{
|
|||||||
if(count($this->arg) == 4){
|
if(count($this->arg) == 4){
|
||||||
[$this->key, $this->keyNick, $this->reqVal, $comp] = $this->arg;
|
[$this->key, $this->keyNick, $this->reqVal, $comp] = $this->arg;
|
||||||
|
|
||||||
if(!in_array($comp, ['>', '>=', '==', '<=', '<', '!='])){
|
if(!in_array($comp, ['>', '>=', '==', '<=', '<', '!=', '===', '!=='])){
|
||||||
if(!$throwExeception){return false; }
|
if(!$throwExeception){return false; }
|
||||||
throw new \InvalidArgumentException("invalid comparator");
|
throw new \InvalidArgumentException("invalid comparator");
|
||||||
}
|
}
|
||||||
@@ -85,7 +86,13 @@ class RegGeneralValue extends Constraint{
|
|||||||
return ($target == $src)?true:"올바르지 않은 {$keyNick} 입니다.";
|
return ($target == $src)?true:"올바르지 않은 {$keyNick} 입니다.";
|
||||||
},
|
},
|
||||||
'!='=>function($targeta, $src)use($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){
|
'>='=>function($target, $src){
|
||||||
if($target >= $src){
|
if($target >= $src){
|
||||||
@@ -97,7 +104,7 @@ class RegGeneralValue extends Constraint{
|
|||||||
return '부족합니다.';
|
return '부족합니다.';
|
||||||
},
|
},
|
||||||
'>'=>function($target, $src){
|
'>'=>function($target, $src){
|
||||||
return $target >= $src;
|
return $target > $src;
|
||||||
if($src == 0){
|
if($src == 0){
|
||||||
return '없습니다';
|
return '없습니다';
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user