protected static function PHPUnit_Util_Getopt::parseLongOption

1 call to PHPUnit_Util_Getopt::parseLongOption()
PHPUnit_Util_Getopt::getopt in drupal/core/vendor/phpunit/phpunit/PHPUnit/Util/Getopt.php

File

drupal/core/vendor/phpunit/phpunit/PHPUnit/Util/Getopt.php, line 154

Class

PHPUnit_Util_Getopt
Command-line options parsing class.

Code

protected static function parseLongOption($arg, $long_options, &$opts, &$args) {
  $count = count($long_options);
  $list = explode('=', $arg);
  $opt = $list[0];
  $opt_arg = NULL;
  if (count($list) > 1) {
    $opt_arg = $list[1];
  }
  $opt_len = strlen($opt);
  for ($i = 0; $i < $count; $i++) {
    $long_opt = $long_options[$i];
    $opt_start = substr($long_opt, 0, $opt_len);
    if ($opt_start != $opt) {
      continue;
    }
    $opt_rest = substr($long_opt, $opt_len);
    if ($opt_rest != '' && $opt[0] != '=' && $i + 1 < $count && $opt == substr($long_options[$i + 1], 0, $opt_len)) {
      throw new PHPUnit_Framework_Exception("option --{$opt} is ambiguous");
    }
    if (substr($long_opt, -1) == '=') {
      if (substr($long_opt, -2) != '==') {
        if (!strlen($opt_arg) && !(list(, $opt_arg) = each($args))) {
          throw new PHPUnit_Framework_Exception("option --{$opt} requires an argument");
        }
      }
    }
    else {
      if ($opt_arg) {
        throw new PHPUnit_Framework_Exception("option --{$opt} doesn't allow an argument");
      }
    }
    $opts[] = array(
      '--' . $opt,
      $opt_arg,
    );
    return;
  }
  throw new PHPUnit_Framework_Exception("unrecognized option --{$opt}");
}