From 2d1aceb100b66715de1079dada1b43eeb034422f Mon Sep 17 00:00:00 2001 From: Dmitry Mamontov Date: Mon, 23 Nov 2015 10:01:46 -0500 Subject: [PATCH] refactoring custom getopt --- retailcrm/src/Helpers/DataHelper.php | 36 ++++++++++++++++++---------- 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/retailcrm/src/Helpers/DataHelper.php b/retailcrm/src/Helpers/DataHelper.php index bdcfe24..9932aea 100644 --- a/retailcrm/src/Helpers/DataHelper.php +++ b/retailcrm/src/Helpers/DataHelper.php @@ -86,29 +86,41 @@ class DataHelper } $result = array(); + $params = $_SERVER['argv']; - while (list(, $p) = each($params)) { - if ($p{0} == '-') { - $pname = substr($p, 1); + foreach ($params as $key => $param) { + if ($param{0} == '-') { + $name = substr($param, 1); $value = true; - if ($pname{0} == '-') { - $pname = substr($pname, 1); - if (strpos($p, '=') !== false) { - list($pname, $value) = explode('=', substr($p, 2), 2); + + if ($name{0} == '-') { + $name = substr($name, 1); + if (strpos($param, '=') !== false) { + $long = explode('=', substr($param, 2), 2); + $name = $long[0]; + $value = $long[1]; + unset($long); } } - $nextparm = current($params); - if ($value === true && $nextparm !== false && $nextparm{0} != '-') { - list(, $value) = each($params); + if ( + isset($params[$key + 1]) && + $value === true && + $params[$key + 1] !== false && + $params[$key + 1]{0} != '-' + ) { + $value = $params[$key + 1]; } - $result[$pname] = $value; + + $result[$name] = $value; } else { - $result[] = $p; + $result[] = $param; } } + unset($params); + return empty($result) ? false : $result; } }