You are here

function extract_arguments in Coder 7.2

Same name and namespace in other branches
  1. 7 coder_upgrade/scripts/coder_upgrade.run.php \extract_arguments()

Returns command line arguments.

Return value

mixed String or array of command line arguments.

1 call to extract_arguments()
coder_upgrade.run.php in coder_upgrade/scripts/coder_upgrade.run.php

File

coder_upgrade/scripts/coder_upgrade.run.php, line 140

Code

function extract_arguments() {
  switch (php_sapi_name()) {
    case 'apache':
    case 'apache2handler':

      // This is the value when running curl.
      if (!isset($_GET['file'])) {
        echo 'file parameter is not set';
        return;
      }
      $filename = $_GET['file'];
      $action = isset($_GET['action']) ? $_GET['action'] : '';
      break;
    case 'cli':
      $skip_args = 2;
      if ($_SERVER['argc'] == 2) {
        $skip_args = 1;
      }
      elseif ($_SERVER['argc'] < 2) {
        echo 'CLI-1: file parameter is not set' . "\n";
        return;
      }
      foreach ($_SERVER['argv'] as $index => $arg) {

        // First two arguments are usually script filename and '--'.
        // Sometimes the '--' is omitted.
        if ($index < $skip_args) {
          continue;
        }
        list($key, $value) = explode('=', $arg);
        $arguments[$key] = $value;
      }
      if (!isset($arguments['file'])) {
        echo 'CLI-2: file parameter is not set' . "\n";
        return;
      }
      $filename = $arguments['file'];
      $action = isset($arguments['action']) ? $arguments['action'] : '';
      break;
  }
  return $filename;
}