mirror of
https://github.com/retailcrm/legacy.git
synced 2024-11-25 06:46:03 +03:00
refactoring custom getopt
This commit is contained in:
parent
b079105b4f
commit
2d1aceb100
@ -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;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user