diff options
author | Christian Schneider | 2021-02-03 10:30:22 +0100 |
---|---|---|
committer | Christian Schneider | 2021-02-03 10:30:22 +0100 |
commit | 21ccdefc4aea4c2439f7d41ece7d8216d8ba8b40 (patch) | |
tree | 3cb6969d9e34580fb0b2eaa64016850e048afb56 /it.class | |
parent | 039792e13581ebfd0ddc05bb115bc5f6bfa9cf46 (diff) | |
download | itools-21ccdefc4aea4c2439f7d41ece7d8216d8ba8b40.tar.gz itools-21ccdefc4aea4c2439f7d41ece7d8216d8ba8b40.tar.bz2 itools-21ccdefc4aea4c2439f7d41ece7d8216d8ba8b40.zip |
Code cleanup: Switch to new style varargs
Diffstat (limited to 'it.class')
-rw-r--r-- | it.class | 33 |
1 files changed, 14 insertions, 19 deletions
@@ -72,12 +72,11 @@ static function &cloneobj(&$object) /** * Append all arguments to a logfile (tab separated). Date will be added to filename and line * @param $name Name of logfile. Will be in log/ of service unless it starts with / - * @param $args... Varargs to log, will be tab separated. + * @param $args Varargs to log, will be tab separated. */ -static function log($name /* ... */) +static function log($name, ...$args) { - $args = func_get_args(); - $line = date("Y-m-d H:i:s") . "\t" . implode("\t", array_slice($args, 1)); + $line = date("Y-m-d H:i:s") . "\t" . implode("\t", $args); self::log_line($name, $line); return $line; } @@ -627,13 +626,12 @@ static function filter_keys($array, $keys, $p = array()) * {0} .. {n} quotes and inserts positional arguments * {-opts} array of opts => {value,true,false,null}: it::exec('ls {-opts}', ['-opts' => ["-l" => true]]); * @param $cmd Format string with {keywords} a la ET() - * @param $values varargs, contains key => val arrays for filling in cmd line. val=null expands to nothing + * @param $args varargs, contains key => val arrays for filling in cmd line. val=null expands to nothing * @return output of command. shell errors not detectable, consider it::system or see /www/server/log/error_log */ -static function exec(/* $cmd, $values1 = array(), ... */) +static function exec($cmd, ...$args) { - $args = func_get_args(); - $cmd = call_user_func_array('it::shell_command', $args); + $cmd = it::shell_command($cmd, ...$args); $before = gettimeofday(true); $result = EDC('noexec') ? "" : (string)shell_exec("set +o posix\n" . $cmd); @@ -649,10 +647,9 @@ static function exec(/* $cmd, $values1 = array(), ... */) * See ::exec above for usage * @return exit code of last command: zero for success, nonzero for failure */ -static function system(/* $cmd, $values1 = array(), ... */) +static function system($cmd, ...$args) { - $args = func_get_args(); - $cmd = call_user_func_array('it::shell_command', $args); + $cmd = it::shell_command($cmd, ...$args); $before = gettimeofday(true); if (!EDC('noexec')) @@ -670,13 +667,11 @@ static function system(/* $cmd, $values1 = array(), ... */) * Keywords {keyword} are replace a la ET(), * {-opts} array of opts => {value,true,false,null}: it::exec('ls {-opts}', ['-opts' => ["-l" => true]]); * @param $cmd Format string with {keywords} replace a la ET() - * @param $values (zero, one or more arrays can be passed) + * @param $args (zero, one or more arrays can be passed) * @return output of command. shell errors not detectable, see error_log in /www/server/log */ -static function shell_command(/* $cmd, $values1 = array(), ... */) +static function shell_command($cmd, ...$args) { - $args = func_get_args(); - $cmd = array_shift($args); $values = array(); # Merge values into one array @@ -686,10 +681,10 @@ static function shell_command(/* $cmd, $values1 = array(), ... */) # for escapeshellarg in it::_exec_quotevalue $oldlocale = setlocale(LC_CTYPE, 0); setlocale(LC_CTYPE, 'de_CH'); - foreach (it::match('({(-?)([a-z0-9]\w*)})', $cmd, array('all' => true)) as $tags) + foreach (it::match('({(-?)([a-z0-9]\w*)})', $cmd, ['all' => true]) as $tags) { list($tag, $option, $key) = $tags; - $parts = array(); + $parts = []; if ($option) { @@ -734,9 +729,9 @@ static function _exec_quotevalue($value, $errmsg = "") * @params see it::exec() * @see it::exec, /opt/ultra/bin/cdist */ -static function cexec(/* $cmd, $values1 = array(), ... */) +static function cexec($cmd, ...$args) { - return it::exec('cdist -c {CMD}', array('CMD' => call_user_func_array('it::shell_command', func_get_args()))); + return it::exec('cdist -c {cmd}', ['cmd' => it::shell_command($cmd, ...$args)]); } |