[ Index ]

PHP Cross Reference of phool

title

Body

[close]

/Phool/Options/ -> Getopt.php (summary)

(no description)

Copyright: Francois Laupretre <phool@tekwire.net>
License: http://www.apache.org/licenses/LICENSE-2.0 Apache License, V 2.0
File Size: 249 lines (10 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

Getopt:: (6 methods):
  getopt2()
  getopt()
  doGetopt()
  _parseShortOption()
  _parseLongOption()
  readPHPArgv()


Class: Getopt  - X-Ref

Command-line options parsing class.

getopt2($args, $short_options, $long_options = null)   X-Ref
Parses the command-line options.

The first parameter to this function should be the list of command-line
arguments without the leading reference to the running program.

The second parameter is a string of allowed short options. Each of the
option letters can be followed by a colon ':' to specify that the option
requires an argument, or a double colon '::' to specify that the option
takes an optional argument.

The third argument is an optional array of allowed long options. The
leading '--' should not be included in the option name. Options that
require an argument should be followed by '=', and options that take an
option argument should be followed by '=='.

The return value is an array of two elements: the list of parsed
options and the list of non-option command-line arguments. Each entry in
the list of parsed options is a pair of elements - the first one
specifies the option, and the second one specifies the option argument,
if there was one.

Long and short options can be mixed.

Most of the semantics of this function are based on GNU getopt_long().

Changes from original version:
- switch to PHP 5 object syntax
- make independant from PEAR error handling using exceptions

param: array  $args           an array of command-line arguments
param: string $short_options  specifies the list of allowed short options
param: array  $long_options   specifies the list of allowed long options
return: array two-element array containing the list of parsed options and

getopt($args, $short_options, $long_options = null)   X-Ref
This function expects $args to start with the script name (POSIX-style).
Preserved for backwards compatibility.


doGetopt($version, $args, $short_options, $long_options = null)   X-Ref
The actual implementation of the argument parsing code.


_parseShortOption($arg, $short_options, &$opts, &$args)   X-Ref
No description

_parseLongOption($arg, $long_options, &$opts, &$args)   X-Ref
No description

readPHPArgv()   X-Ref
Safely read the $argv PHP array across different PHP configurations.
Will take care on register_globals and register_argc_argv ini directives

return: array the $argv PHP array



Generated: Thu Jun 4 19:17:11 2015 Cross-referenced by PHPXref 0.7.1