class CLIArgumentUtils { # TODO: discontinue private function __construct() { } public static function isOptSet($shortopt, $longopt='') { if (strlen($shortopt) > 1) return false; $shortopts = $shortopt; $longopts = (empty($longopt)) ? array() : array($longopt); $options = getopt($shortopts, $longopts); return isset($options[$shortopt]) || isset($options[$longopt]); } public static function getOptValue($shortopt, $longopt='') { if (strlen($shortopt) > 1) return false; $shortopts = $shortopt.':'; $longopts = (empty($longopt)) ? array() : array($longopt.':'); $options = getopt($shortopts, $longopts); if (isset($options[$shortopt])) { if (is_array($options[$shortopt])) $options[$shortopt] = $options[$shortopt][0]; return $options[$shortopt]; } if (isset($options[$longopt])) { if (is_array($options[$longopt])) $options[$longopt] = $options[$longopt][0]; return $options[$longopt]; } return null; } public static function countOptRepetition($shortopt, $longopt='') { if (strlen($shortopt) > 1) return false; $shortopts = $shortopt; $longopts = (empty($longopt)) ? array() : array($longopt); $options = getopt($shortopts, $longopts); $count = 0; if (isset($options[$shortopt])) { if (is_array($options[$shortopt])) { $count += count($options[$shortopt]); } else { $count += 1; } } if (isset($options[$longopt])) { if (is_array($options[$longopt])) { $count += count($options[$longopt]); } else { $count += 1; } } return $count; } }