You are here

public static function PHPUnit_Util_Getopt::getopt in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/phpunit/phpunit/src/Util/Getopt.php \PHPUnit_Util_Getopt::getopt()
3 calls to PHPUnit_Util_Getopt::getopt()
PHPUnit_TextUI_Command::handleArguments in vendor/phpunit/phpunit/src/TextUI/Command.php
Handles the command-line arguments.
Util_GetoptTest::testItIncludeTheLongOptionsAfterTheArgument in vendor/phpunit/phpunit/tests/Util/GetoptTest.php
Util_GetoptTest::testItIncludeTheShortOptionsAfterTheArgument in vendor/phpunit/phpunit/tests/Util/GetoptTest.php

File

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

Class

PHPUnit_Util_Getopt
Command-line options parsing class.

Code

public static function getopt(array $args, $short_options, $long_options = null) {
  if (empty($args)) {
    return array(
      array(),
      array(),
    );
  }
  $opts = array();
  $non_opts = array();
  if ($long_options) {
    sort($long_options);
  }
  if (isset($args[0][0]) && $args[0][0] != '-') {
    array_shift($args);
  }
  reset($args);
  array_map('trim', $args);
  while (list($i, $arg) = each($args)) {
    if ($arg == '') {
      continue;
    }
    if ($arg == '--') {
      $non_opts = array_merge($non_opts, array_slice($args, $i + 1));
      break;
    }
    if ($arg[0] != '-' || strlen($arg) > 1 && $arg[1] == '-' && !$long_options) {
      $non_opts[] = $args[$i];
      continue;
    }
    elseif (strlen($arg) > 1 && $arg[1] == '-') {
      self::parseLongOption(substr($arg, 2), $long_options, $opts, $args);
    }
    else {
      self::parseShortOption(substr($arg, 1), $short_options, $opts, $args);
    }
  }
  return array(
    $opts,
    $non_opts,
  );
}