Back to index

php5  5.3.10
Public Member Functions | Protected Member Functions | Protected Attributes
gtCommandLineOptions Class Reference

Parse command line options. More...

List of all members.

Public Member Functions

 isValidOptionArg ($array, $index)
 parse ($argv)
 getOption ($option)
 hasOption ($option)
 Check whether an option exists.

Protected Member Functions

 isShortOption ($arg)

Protected Attributes

 $shortOptions
 $shortOptionsWithArgs
 $options

Detailed Description

Parse command line options.

Definition at line 7 of file gtCommandLineOptions.php.


Member Function Documentation

Definition at line 79 of file gtCommandLineOptions.php.

  {
    if (!isset($this->options[$option])) {
      return false;
    }
    return $this->options[$option];
  }

Here is the call graph for this function:

Check whether an option exists.

Definition at line 91 of file gtCommandLineOptions.php.

  {
    return isset($this->options[$option]);
  }

Here is the call graph for this function:

gtCommandLineOptions::isShortOption ( arg) [protected]

Definition at line 28 of file gtCommandLineOptions.php.

  {
    return (substr($arg, 0, 1) == '-') && (substr($arg, 1, 1) != '-');
  }

Here is the caller graph for this function:

gtCommandLineOptions::isValidOptionArg ( array,
index 
)

Definition at line 33 of file gtCommandLineOptions.php.

                                                   {
    if (!isset($array[$index]))
    {
      return false;
    }
    return substr($array[$index], 0, 1) != '-';
  }

Here is the caller graph for this function:

Definition at line 42 of file gtCommandLineOptions.php.

  {
    if(count($argv) < 2) {
      throw new gtMissingOptionsException('Command line options are required');
    }
    
    for ($i=1; $i<count($argv); $i++) {

      if ($this->isShortOption($argv[$i])) {
        $option = substr($argv[$i], 1);
      } else {
        throw new gtUnknownOptionException('Unrecognised command line option ' . $argv[$i]);
      }

      if (!in_array($option, array_merge($this->shortOptions, $this->shortOptionsWithArgs)))
      {
        throw new gtUnknownOptionException('Unknown option ' . $argv[$i]);
      }

      if (in_array($option, $this->shortOptions)) {
        $this->options[$option] = true;
        continue;
      }

      if (!$this->isValidOptionArg($argv, $i + 1))
      {
        throw new gtMissingArgumentException('Missing argument for command line option ' . $argv[$i]);
      }

      $i++;
      $this->options[$option] = $argv[$i];
    }
  }

Here is the call graph for this function:


Member Data Documentation

Definition at line 26 of file gtCommandLineOptions.php.

Initial value:
 array(
    'b',
    'e',
    'v',
    'h',
  )

Definition at line 9 of file gtCommandLineOptions.php.

Initial value:
 array(
    'c',
    'm',
    'f',
    'i',
    's',
    'x',
    'k',
  )

Definition at line 16 of file gtCommandLineOptions.php.


The documentation for this class was generated from the following file: