You are here

protected static function PHPUnit_Util_Getopt::parseLongOption in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/phpunit/phpunit/src/Util/Getopt.php \PHPUnit_Util_Getopt::parseLongOption()
1 call to PHPUnit_Util_Getopt::parseLongOption()
PHPUnit_Util_Getopt::getopt in vendor/phpunit/phpunit/src/Util/Getopt.php

File

vendor/phpunit/phpunit/src/Util/Getopt.php, line 110

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");
        }
      }
    }
    elseif ($opt_arg) {
      throw new PHPUnit_Framework_Exception("option --{$opt} doesn't allow an argument");
    }
    $full_option = '--' . preg_replace('/={1,2}$/', '', $long_opt);
    $opts[] = array(
      $full_option,
      $opt_arg,
    );
    return;
  }
  throw new PHPUnit_Framework_Exception("unrecognized option --{$opt}");
}