Console_Getopt
[ class tree: Console_Getopt ] [ index: Console_Getopt ] [ all elements ]

Class: Console_Getopt

Source Location: /Console_Getopt-1.4.3/Console/Getopt.php

Class Overview


Command-line options parsing class.


Author(s):

Methods


Inherited Variables

Inherited Methods


Class Details

[line 32]
Command-line options parsing class.


[ Top ]


Method Detail

doGetopt   [line 102]

array doGetopt( int $version, array $args, string $short_options, [array $long_options = null], [boolean $skip_unknown = false])

The actual implementation of the argument parsing code.
  • Access: public

Parameters:

int   $version   —  Version to use
array   $args   —  an array of command-line arguments
string   $short_options   —  specifies the list of allowed short options
array   $long_options   —  specifies the list of allowed long options
boolean   $skip_unknown   —  suppresses Console_Getopt: unrecognized option

[ Top ]

getopt   [line 86]

array getopt( array $args, string $short_options, [array $long_options = null], [ $skip_unknown = false])

This function expects $args to start with the script name (POSIX-style).

Preserved for backwards compatibility.

  • Return: two-element array containing the list of parsed options and the non-option arguments
  • See: Console_Getopt::getopt2()
  • Access: public

Parameters:

array   $args   —  an array of command-line arguments
string   $short_options   —  specifies the list of allowed short options
array   $long_options   —  specifies the list of allowed long options
   $skip_unknown   — 

[ Top ]

getopt2   [line 69]

array getopt2( array $args, string $short_options, [array $long_options = null], [boolean $skip_unknown = false])

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().

  • Return: two-element array containing the list of parsed options and the non-option arguments
  • Access: public

Parameters:

array   $args   —  an array of command-line arguments
string   $short_options   —  specifies the list of allowed short options
array   $long_options   —  specifies the list of allowed long options
boolean   $skip_unknown   —  suppresses Console_Getopt: unrecognized option

[ Top ]

readPHPArgv   [line 349]

mixed readPHPArgv( )

Safely read the $argv PHP array across different PHP configurations.

Will take care on register_globals and register_argc_argv ini directives

  • Return: the $argv PHP array or PEAR error if not registered
  • Access: public

[ Top ]

_isLongOpt   [line 255]

bool _isLongOpt( string $arg)

Checks if an argument is a long option
  • Access: protected

Parameters:

string   $arg   —  Argument to check

[ Top ]

_isShortOpt   [line 242]

bool _isShortOpt( string $arg)

Checks if an argument is a short option
  • Access: protected

Parameters:

string   $arg   —  Argument to check

[ Top ]

_parseLongOption   [line 272]

void|PEAR_Error _parseLongOption( string $arg, string[] $long_options, string[][] &$opts, int &$argIdx, string[] $args, $skip_unknown)

Parse long option
  • Access: protected

Parameters:

string   $arg   —  Argument
string[]   $long_options   —  Available long options
string[][]   &$opts   — 
int   &$argIdx   — 
string[]   $args   — 
   $skip_unknown   — 

[ Top ]

_parseShortOption   [line 186]

void _parseShortOption( string $arg, string[] $short_options, string[][] &$opts, int &$argIdx, string[] $args, boolean $skip_unknown)

Parse short option
  • Access: protected

Parameters:

string   $arg   —  Argument
string[]   $short_options   —  Available short options
string[][]   &$opts   — 
int   &$argIdx   — 
string[]   $args   — 
boolean   $skip_unknown   —  suppresses Console_Getopt: unrecognized option

[ Top ]


Documentation generated on Wed, 20 Nov 2019 13:32:06 -0500 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.