From: Michael Wallner Date: Fri, 2 Mar 2018 09:54:52 +0000 (+0100) Subject: add support for multiple arguments and mutually exclusive params X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=165f61f020ee6de84051c4a463e7f8b7d1f87958;p=m6w6%2Ftravis-pecl add support for multiple arguments and mutually exclusive params --- diff --git a/gen-matrix.php b/gen-matrix.php index 90e0011..e7ded67 100644 --- a/gen-matrix.php +++ b/gen-matrix.php @@ -1,26 +1,52 @@ $values) { - if (is_numeric($key) && is_string($values)) { - $key = $values; - $values = ["no","yes"]; - } - if (empty($apc)) { - // seed - foreach ($values as $val) { - $apc[] = "$key=$val"; +return function() { + $process = function($apc, $key, $values = ["no", "yes"]) { + + return $apc; + }; + + foreach (func_get_args() as $array) { + $apc = []; + foreach ($array as $key => $values) { + if (is_numeric($key) && is_string($values)) { + // switch on yes/no + $key = $values; + $values = ["no", "yes"]; + } else if (is_numeric($key) && is_array($values)) { + // mutually enasbled options + $vpc = []; + foreach ($values as $yes) { + $mpc = "$yes=yes "; + foreach ($values as $no) { + if ($yes === $no) { + continue; + } + $mpc .= "$no=no "; + } + $vpc[] = $mpc; + } + $key = null; + $values = $vpc; } - } else { - // combine - $cpc = $apc; - $apc = []; - foreach ($values as $val) { - foreach ($cpc as $e) { - $apc[] = "$e $key=$val"; + + if (empty($apc)) { + // seed + foreach ((array) $values as $val) { + $apc[] = strlen($key) ? "$key=$val" : $val; + } + } else { + // combine + $cpc = $apc; + $apc = []; + foreach ((array) $values as $val) { + foreach ($cpc as $e) { + $apc[] = strlen($key) ? "$e $key=$val" : "$e $val"; + } } } } + $xpc[] = $apc; } - return $apc; + return $xpc; };