refac: brandonwamboldt/utilphp 의존 코드 수정
- 실제 의존성 제거는 이후에에
This commit is contained in:
+1
-1
@@ -31,7 +31,7 @@ $queryMap = [
|
||||
];
|
||||
|
||||
if ($reqQueryType === null || !key_exists($reqQueryType, $queryMap)) {
|
||||
$reqQueryType = Util::array_first_key($queryMap);
|
||||
$reqQueryType = array_key_first($queryMap);
|
||||
}
|
||||
|
||||
//로그인 검사
|
||||
|
||||
@@ -559,7 +559,7 @@ function checkStatistic()
|
||||
|
||||
$nationHist = '';
|
||||
foreach (GameConst::$availableNationType as $nationType) {
|
||||
if (!Util::array_get($nationHists[$nationType])) {
|
||||
if (!($nationHists[$nationType] ?? null)) {
|
||||
$nationHists[$nationType] = '-';
|
||||
}
|
||||
$nationHist .= getNationType($nationType) . "({$nationHists[$nationType]}), ";
|
||||
|
||||
+2
-2
@@ -138,7 +138,7 @@ function JSCitiesBasedOnDistance(int $cityNo, int $maxDistance = 1): array{
|
||||
$distanceList = searchDistance($cityNo, $maxDistance, true);
|
||||
$result = [];
|
||||
for ($dist = 1; $dist <= $maxDistance; $dist++) {
|
||||
$result[$dist] = Util::array_get($distanceList[$dist], []);
|
||||
$result[$dist] = $distanceList[$dist] ?? [];
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
@@ -152,7 +152,7 @@ function printCitiesBasedOnDistance(int $cityNo, int $maxDistance = 1): string
|
||||
for ($dist = 1; $dist <= $maxDistance; $dist++) {
|
||||
$cityList = array_map(function ($cityID) {
|
||||
return CityConst::byID($cityID)->name;
|
||||
}, Util::array_get($distanceList[$dist], []));
|
||||
}, $distanceList[$dist] ?? []);
|
||||
|
||||
$cityStr = join(', ', $cityList);
|
||||
|
||||
|
||||
+1
-1
@@ -526,7 +526,7 @@ function DeleteConflict($nation)
|
||||
function getConquerNation($city): int
|
||||
{
|
||||
$conflict = Json::decode($city['conflict']);
|
||||
return Util::array_first_key($conflict);
|
||||
return array_key_first($conflict);
|
||||
}
|
||||
|
||||
function ConquerCity(array $admin, General $general, array $city, array $defenderCityGeneralList)
|
||||
|
||||
@@ -33,7 +33,7 @@ class event_전투특기_공성 extends \sammo\BaseItem{
|
||||
}
|
||||
|
||||
public function onCalcStat(General $general, string $statName, $value, $aux=null){
|
||||
if(\sammo\Util::starts_with($statName, 'dex')){
|
||||
if(str_starts_with($statName, 'dex')){
|
||||
$myArmType = 'dex'.GameUnitConst::T_SIEGE;
|
||||
$opposeArmType = 'dex'.$aux['opposeType']->armType;;
|
||||
if($aux['isAttacker'] && $opposeArmType === $statName){
|
||||
|
||||
@@ -28,7 +28,7 @@ class event_전투특기_궁병 extends \sammo\BaseItem{
|
||||
if($statName === 'warAvoidRatio'){
|
||||
return $value + 0.2;
|
||||
}
|
||||
if(\sammo\Util::starts_with($statName, 'dex')){
|
||||
if(str_starts_with($statName, 'dex')){
|
||||
$myArmType = 'dex'.GameUnitConst::T_ARCHER;
|
||||
$opposeArmType = 'dex'.$aux['opposeType']->armType;;
|
||||
if($aux['isAttacker'] && $opposeArmType === $statName){
|
||||
|
||||
@@ -28,7 +28,7 @@ class event_전투특기_귀병 extends \sammo\BaseItem{
|
||||
if($statName === 'warMagicSuccessProb'){
|
||||
return $value + 0.2;
|
||||
}
|
||||
if(\sammo\Util::starts_with($statName, 'dex')){
|
||||
if(str_starts_with($statName, 'dex')){
|
||||
$myArmType = 'dex'.GameUnitConst::T_WIZARD;
|
||||
$opposeArmType = 'dex'.$aux['opposeType']->armType;;
|
||||
if($aux['isAttacker'] && $opposeArmType === $statName){
|
||||
|
||||
@@ -32,7 +32,7 @@ class event_전투특기_기병 extends \sammo\BaseItem{
|
||||
}
|
||||
|
||||
public function onCalcStat(General $general, string $statName, $value, $aux=null){
|
||||
if(\sammo\Util::starts_with($statName, 'dex')){
|
||||
if(str_starts_with($statName, 'dex')){
|
||||
$myArmType = 'dex'.GameUnitConst::T_CAVALRY;
|
||||
$opposeArmType = 'dex'.$aux['opposeType']->armType;;
|
||||
if($aux['isAttacker'] && $opposeArmType === $statName){
|
||||
|
||||
@@ -33,7 +33,7 @@ class event_전투특기_보병 extends \sammo\BaseItem{
|
||||
}
|
||||
|
||||
public function onCalcStat(General $general, string $statName, $value, $aux=null){
|
||||
if(\sammo\Util::starts_with($statName, 'dex')){
|
||||
if(str_starts_with($statName, 'dex')){
|
||||
$myArmType = 'dex'.GameUnitConst::T_FOOTMAN;
|
||||
$opposeArmType = 'dex'.$aux['opposeType']->armType;;
|
||||
if($aux['isAttacker'] && $opposeArmType === $statName){
|
||||
|
||||
@@ -35,7 +35,7 @@ class che_event_공성 extends \sammo\BaseSpecial{
|
||||
}
|
||||
|
||||
public function onCalcStat(General $general, string $statName, $value, $aux=null){
|
||||
if(\sammo\Util::starts_with($statName, 'dex')){
|
||||
if(str_starts_with($statName, 'dex')){
|
||||
$myArmType = 'dex'.GameUnitConst::T_SIEGE;
|
||||
$opposeArmType = 'dex'.$aux['opposeType']->armType;;
|
||||
if($aux['isAttacker'] && $opposeArmType === $statName){
|
||||
|
||||
@@ -31,7 +31,7 @@ class che_event_궁병 extends \sammo\BaseSpecial{
|
||||
if($statName === 'warAvoidRatio'){
|
||||
return $value + 0.2;
|
||||
}
|
||||
if(\sammo\Util::starts_with($statName, 'dex')){
|
||||
if(str_starts_with($statName, 'dex')){
|
||||
$myArmType = 'dex'.GameUnitConst::T_ARCHER;
|
||||
$opposeArmType = 'dex'.$aux['opposeType']->armType;;
|
||||
if($aux['isAttacker'] && $opposeArmType === $statName){
|
||||
|
||||
@@ -30,7 +30,7 @@ class che_event_귀병 extends \sammo\BaseSpecial{
|
||||
if($statName === 'warMagicSuccessProb'){
|
||||
return $value + 0.2;
|
||||
}
|
||||
if(\sammo\Util::starts_with($statName, 'dex')){
|
||||
if(str_starts_with($statName, 'dex')){
|
||||
$myArmType = 'dex'.GameUnitConst::T_WIZARD;
|
||||
$opposeArmType = 'dex'.$aux['opposeType']->armType;;
|
||||
if($aux['isAttacker'] && $opposeArmType === $statName){
|
||||
|
||||
@@ -35,7 +35,7 @@ class che_event_기병 extends \sammo\BaseSpecial{
|
||||
}
|
||||
|
||||
public function onCalcStat(General $general, string $statName, $value, $aux=null){
|
||||
if(\sammo\Util::starts_with($statName, 'dex')){
|
||||
if(str_starts_with($statName, 'dex')){
|
||||
$myArmType = 'dex'.GameUnitConst::T_CAVALRY;
|
||||
$opposeArmType = 'dex'.$aux['opposeType']->armType;;
|
||||
if($aux['isAttacker'] && $opposeArmType === $statName){
|
||||
|
||||
@@ -35,7 +35,7 @@ class che_event_보병 extends \sammo\BaseSpecial{
|
||||
}
|
||||
|
||||
public function onCalcStat(General $general, string $statName, $value, $aux=null){
|
||||
if(\sammo\Util::starts_with($statName, 'dex')){
|
||||
if(str_starts_with($statName, 'dex')){
|
||||
$myArmType = 'dex'.GameUnitConst::T_FOOTMAN;
|
||||
$opposeArmType = 'dex'.$aux['opposeType']->armType;;
|
||||
if($aux['isAttacker'] && $opposeArmType === $statName){
|
||||
|
||||
@@ -35,7 +35,7 @@ class che_공성 extends \sammo\BaseSpecial{
|
||||
}
|
||||
|
||||
public function onCalcStat(General $general, string $statName, $value, $aux=null){
|
||||
if(\sammo\Util::starts_with($statName, 'dex')){
|
||||
if(str_starts_with($statName, 'dex')){
|
||||
$myArmType = 'dex'.GameUnitConst::T_SIEGE;
|
||||
$opposeArmType = 'dex'.$aux['opposeType']->armType;;
|
||||
if($aux['isAttacker'] && $opposeArmType === $statName){
|
||||
|
||||
@@ -31,7 +31,7 @@ class che_궁병 extends \sammo\BaseSpecial{
|
||||
if($statName === 'warAvoidRatio'){
|
||||
return $value + 0.2;
|
||||
}
|
||||
if(\sammo\Util::starts_with($statName, 'dex')){
|
||||
if(str_starts_with($statName, 'dex')){
|
||||
$myArmType = 'dex'.GameUnitConst::T_ARCHER;
|
||||
$opposeArmType = 'dex'.$aux['opposeType']->armType;;
|
||||
if($aux['isAttacker'] && $opposeArmType === $statName){
|
||||
|
||||
@@ -30,7 +30,7 @@ class che_귀병 extends \sammo\BaseSpecial{
|
||||
if($statName === 'warMagicSuccessProb'){
|
||||
return $value + 0.2;
|
||||
}
|
||||
if(\sammo\Util::starts_with($statName, 'dex')){
|
||||
if(str_starts_with($statName, 'dex')){
|
||||
$myArmType = 'dex'.GameUnitConst::T_WIZARD;
|
||||
$opposeArmType = 'dex'.$aux['opposeType']->armType;;
|
||||
if($aux['isAttacker'] && $opposeArmType === $statName){
|
||||
|
||||
@@ -35,7 +35,7 @@ class che_기병 extends \sammo\BaseSpecial{
|
||||
}
|
||||
|
||||
public function onCalcStat(General $general, string $statName, $value, $aux=null){
|
||||
if(\sammo\Util::starts_with($statName, 'dex')){
|
||||
if(str_starts_with($statName, 'dex')){
|
||||
$myArmType = 'dex'.GameUnitConst::T_CAVALRY;
|
||||
$opposeArmType = 'dex'.$aux['opposeType']->armType;;
|
||||
if($aux['isAttacker'] && $opposeArmType === $statName){
|
||||
|
||||
@@ -35,7 +35,7 @@ class che_보병 extends \sammo\BaseSpecial{
|
||||
}
|
||||
|
||||
public function onCalcStat(General $general, string $statName, $value, $aux=null){
|
||||
if(\sammo\Util::starts_with($statName, 'dex')){
|
||||
if(str_starts_with($statName, 'dex')){
|
||||
$myArmType = 'dex'.GameUnitConst::T_FOOTMAN;
|
||||
$opposeArmType = 'dex'.$aux['opposeType']->armType;;
|
||||
if($aux['isAttacker'] && $opposeArmType === $statName){
|
||||
|
||||
@@ -208,7 +208,7 @@ class che_랜덤임관 extends Command\GeneralCommand
|
||||
foreach ($rawGeneralsCnt as $nation) {
|
||||
$calcCnt = $nation['warpower'] + $nation['develpower'];
|
||||
|
||||
if ($general->getNPCType() < 2 && Util::starts_with($nation['name'], 'ⓤ')) {
|
||||
if ($general->getNPCType() < 2 && str_starts_with($nation['name'], 'ⓤ')) {
|
||||
$calcCnt *= 100;
|
||||
}
|
||||
|
||||
|
||||
@@ -164,7 +164,7 @@ class che_출병 extends Command\GeneralCommand
|
||||
|
||||
$currDist = 999;
|
||||
|
||||
$minDist = Util::array_first_key($distanceList);
|
||||
$minDist = array_key_first($distanceList);
|
||||
do {
|
||||
//1: 최단 거리 도시 중 공격 대상이 있는가 확인
|
||||
//2: 최단 거리 + 1 도시 중 공격 대상이 있는가 확인
|
||||
|
||||
@@ -127,7 +127,7 @@ class ChangeCity extends \sammo\Event\Action{
|
||||
return DB::db()->sqleval('ROUND(%b * %d, 0)', $keyMax, $value/100);
|
||||
}
|
||||
|
||||
if(Util::ends_with($key, '_max') && preg_match(self::REGEXP_MATH, $value, $matches)){
|
||||
if(str_ends_with($key, '_max') && preg_match(self::REGEXP_MATH, $value, $matches)){
|
||||
//key가 아예 최대치에 대한 값이면 연산은 결과값이 0보다만 높게.
|
||||
$op = $matches[1];
|
||||
$value = $matches[2];
|
||||
|
||||
@@ -2084,7 +2084,7 @@ class GeneralAI
|
||||
}
|
||||
}
|
||||
|
||||
$finalCityID = Util::array_first_key($cityScoreList);
|
||||
$finalCityID = array_key_first($cityScoreList);
|
||||
$dist = $distanceList[$capital][$finalCityID];
|
||||
$targetCityID = $finalCityID;
|
||||
if ($dist > 1) {
|
||||
|
||||
@@ -62,7 +62,7 @@ abstract class TriggerCaller{
|
||||
return $this;
|
||||
}
|
||||
|
||||
$lastKey = Util::array_last_key($this->triggerListByPriority);
|
||||
$lastKey = array_key_last($this->triggerListByPriority);
|
||||
if($lastKey < $priority){
|
||||
$this->triggerListByPriority[$priority] = [$uniqueID=>$trigger];
|
||||
return $this;
|
||||
|
||||
+2
-2
@@ -174,7 +174,7 @@ function tryNpmInstall()
|
||||
|
||||
tryComposerInstall();
|
||||
if (tryNpmInstall()) {
|
||||
genJS(Util::array_last_key(ServConfig::getServerList()));
|
||||
genJS(array_key_last(ServConfig::getServerList()));
|
||||
}
|
||||
$session = Session::requireLogin(null)->setReadOnly();
|
||||
|
||||
@@ -227,7 +227,7 @@ if (!$allowFullUpdate || !$target) {
|
||||
$target = $request['target'];
|
||||
}
|
||||
|
||||
$baseServerName = Util::array_last_key(ServConfig::getServerList());
|
||||
$baseServerName = array_key_last(ServConfig::getServerList());
|
||||
|
||||
if (!$target && $server != $baseServerName) {
|
||||
Json::die([
|
||||
|
||||
@@ -109,16 +109,16 @@ if($expires < $nowDate){
|
||||
$access_token = $result['access_token'];
|
||||
$expires = TimeUtil::nowAddSeconds($result['expires_in']);
|
||||
if(isset($result['refresh_token'])){
|
||||
$refresh_token = Util::array_get($result['refresh_token']);
|
||||
$refresh_token = $result['refresh_token'] ?? null;
|
||||
$refresh_token_expires = TimeUtil::nowAddSeconds($result['refresh_token_expires_in']);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$signupResult = $restAPI->signup();
|
||||
$kakaoID = Util::array_get($signupResult['id']);
|
||||
$kakaoID = $signupResult['id'] ?? null;
|
||||
|
||||
if(!$kakaoID && Util::array_get($signupResult['msg'])!='already registered'){
|
||||
if(!$kakaoID && ($signupResult['msg'] ?? null) !='already registered'){
|
||||
Json::die([
|
||||
'result'=>false,
|
||||
'reason'=>'카카오 로그인 과정 중 앱 연결 절차를 실패했습니다'.Json::encode($signupResult)
|
||||
@@ -126,7 +126,7 @@ if(!$kakaoID && Util::array_get($signupResult['msg'])!='already registered'){
|
||||
}
|
||||
|
||||
$me = $restAPI->meWithEmail();
|
||||
$me['code'] = Util::array_get($me['code'], 0);
|
||||
$me['code'] = $me['code'] ?? 0;
|
||||
$kakao_account = $me['kakao_account']??[];
|
||||
if ($me['code']< 0) {
|
||||
$restAPI->unlink();
|
||||
|
||||
@@ -88,9 +88,9 @@ class Setting
|
||||
$tail = new FileTail($this->versionFile);
|
||||
$version = 'noVersionJson';
|
||||
foreach ($tail->smart(5, 100, true) as $line) {
|
||||
if (Util::starts_with($line, '//{')) {
|
||||
if (str_starts_with($line, '//{')) {
|
||||
$version = Json::decode(substr($line, 2));
|
||||
$version = Util::array_get($version['version'], 'noVersionValue');
|
||||
$version = $version['version'] ?? 'noVersionValue';
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -106,8 +106,8 @@ class Setting
|
||||
$templates = new \League\Plates\Engine(__DIR__.'/templates');
|
||||
//TODO: .htaccess가 서버 오픈에도 사용될 수 있으니 별도의 방법이 필요함
|
||||
$allow_ip = Util::get_client_ip(false);
|
||||
if (Util::starts_with($allow_ip, '192.168.') ||
|
||||
Util::starts_with($allow_ip, '10.')) {
|
||||
if (str_starts_with($allow_ip, '192.168.') ||
|
||||
str_starts_with($allow_ip, '10.')) {
|
||||
//172.16~172.31은 코딩하기 귀찮으니까 안할거다
|
||||
$allow_ip = Util::get_client_ip(true);
|
||||
}
|
||||
|
||||
+107
-1
@@ -3,7 +3,7 @@ namespace sammo;
|
||||
|
||||
use Iterator;
|
||||
|
||||
class Util extends \utilphp\util
|
||||
class Util
|
||||
{
|
||||
|
||||
/**
|
||||
@@ -889,4 +889,110 @@ class Util extends \utilphp\util
|
||||
}
|
||||
return join('|', $result);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* http://github.com/brandonwamboldt/utilphp/ 의 구버전 코드에서 이식함
|
||||
* 일부 코드는 수정
|
||||
* 해당 라이선스: MIT
|
||||
*/
|
||||
|
||||
/**
|
||||
* Returns the first element in an array.
|
||||
* PHP 8.5부터 array_first 사용 가능
|
||||
*
|
||||
* @param array $array
|
||||
* @return mixed
|
||||
*/
|
||||
public static function array_first(array $array)
|
||||
{
|
||||
return $array[array_key_first($array)];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the last element in an array.
|
||||
* PHP 8.5부터 array_last 사용 가능
|
||||
*
|
||||
* @param array $array
|
||||
* @return mixed
|
||||
*/
|
||||
public static function array_last(array $array)
|
||||
{
|
||||
return $array[array_key_last($array)];
|
||||
}
|
||||
|
||||
/**
|
||||
* Flatten a multi-dimensional array into a one dimensional array.
|
||||
*
|
||||
* Contributed by Theodore R. Smith of PHP Experts, Inc. <http://www.phpexperts.pro/>
|
||||
*
|
||||
* @param array $array The array to flatten
|
||||
* @param boolean $preserve_keys Whether or not to preserve array keys.
|
||||
* Keys from deeply nested arrays will
|
||||
* overwrite keys from shallowy nested arrays
|
||||
* @return array
|
||||
*/
|
||||
public static function array_flatten(array $array, $preserve_keys = true)
|
||||
{
|
||||
$flattened = array();
|
||||
|
||||
array_walk_recursive($array, function($value, $key) use (&$flattened, $preserve_keys) {
|
||||
if ($preserve_keys && !is_int($key)) {
|
||||
$flattened[$key] = $value;
|
||||
} else {
|
||||
$flattened[] = $value;
|
||||
}
|
||||
});
|
||||
|
||||
return $flattened;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the IP address of the client.
|
||||
*
|
||||
* @param boolean $trust_proxy_headers Whether or not to trust the
|
||||
* proxy headers HTTP_CLIENT_IP
|
||||
* and HTTP_X_FORWARDED_FOR. ONLY
|
||||
* use if your server is behind a
|
||||
* proxy that sets these values
|
||||
* @return string
|
||||
*/
|
||||
public static function get_client_ip($trust_proxy_headers = false)
|
||||
{
|
||||
if (!$trust_proxy_headers) {
|
||||
return $_SERVER['REMOTE_ADDR'];
|
||||
}
|
||||
|
||||
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
|
||||
$ip = $_SERVER['HTTP_CLIENT_IP'];
|
||||
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
|
||||
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
|
||||
} else {
|
||||
$ip = $_SERVER['REMOTE_ADDR'];
|
||||
}
|
||||
|
||||
return $ip;
|
||||
}
|
||||
|
||||
/**
|
||||
* Access an array index, retrieving the value stored there if it
|
||||
* exists or a default if it does not. This function allows you to
|
||||
* concisely access an index which may or may not exist without
|
||||
* raising a warning.
|
||||
*
|
||||
* @deprecated PHP 7.0 이상에서는 null 병합 연산자 사용을 권장
|
||||
*
|
||||
* @param array $var Array value to access
|
||||
* @param mixed $default Default value to return if the key is not
|
||||
* present in the array
|
||||
* @return mixed
|
||||
*/
|
||||
public static function array_get(&$var, $default = null)
|
||||
{
|
||||
if (isset($var)) {
|
||||
return $var;
|
||||
}
|
||||
|
||||
return $default;
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user