Open Journal Systems  3.3.0
Console_Getopt Class Reference

Static Public Member Functions

static doGetopt ($version, $args, $short_options, $long_options=null, $skip_unknown=false)
 
static getopt ($args, $short_options, $long_options=null, $skip_unknown=false)
 
static getopt2 ($args, $short_options, $long_options=null, $skip_unknown=false)
 
static readPHPArgv ()
 

Static Protected Member Functions

static _isLongOpt ($arg)
 
static _isShortOpt ($arg)
 
static _parseLongOption ($arg, $long_options, &$opts, &$argIdx, $args, $skip_unknown)
 
static _parseShortOption ($arg, $short_options, &$opts, &$argIdx, $args, $skip_unknown)
 

Detailed Description

Definition at line 32 of file Getopt.php.

Member Function Documentation

◆ _isLongOpt()

static Console_Getopt::_isLongOpt (   $arg)
staticprotected

Checks if an argument is a long option

Parameters
string$argArgument to check
Returns
bool

Definition at line 255 of file Getopt.php.

Referenced by _parseLongOption(), and _parseShortOption().

◆ _isShortOpt()

static Console_Getopt::_isShortOpt (   $arg)
staticprotected

Checks if an argument is a short option

Parameters
string$argArgument to check
Returns
bool

Definition at line 242 of file Getopt.php.

Referenced by _parseLongOption(), and _parseShortOption().

◆ _parseLongOption()

static Console_Getopt::_parseLongOption (   $arg,
  $long_options,
$opts,
$argIdx,
  $args,
  $skip_unknown 
)
staticprotected

Parse long option

Parameters
string$argArgument
string[]$long_optionsAvailable long options
string[][]&$opts
int&$argIdx
string[]$args
Returns
void|PEAR_Error

Definition at line 272 of file Getopt.php.

References _isLongOpt(), and _isShortOpt().

Referenced by doGetopt().

◆ _parseShortOption()

static Console_Getopt::_parseShortOption (   $arg,
  $short_options,
$opts,
$argIdx,
  $args,
  $skip_unknown 
)
staticprotected

Parse short option

Parameters
string$argArgument
string[]$short_optionsAvailable short options
string[][]&$opts
int&$argIdx
string[]$args
boolean$skip_unknownsuppresses Console_Getopt: unrecognized option
Returns
void

Definition at line 186 of file Getopt.php.

References _isLongOpt(), and _isShortOpt().

Referenced by doGetopt().

◆ doGetopt()

static Console_Getopt::doGetopt (   $version,
  $args,
  $short_options,
  $long_options = null,
  $skip_unknown = false 
)
static

The actual implementation of the argument parsing code.

Parameters
int$versionVersion to use
array$argsan array of command-line arguments
string$short_optionsspecifies the list of allowed short options
array$long_optionsspecifies the list of allowed long options
boolean$skip_unknownsuppresses Console_Getopt: unrecognized option
Returns
array

Definition at line 102 of file Getopt.php.

References _parseLongOption(), _parseShortOption(), and PEAR\isError().

Referenced by getopt(), and getopt2().

◆ getopt()

static Console_Getopt::getopt (   $args,
  $short_options,
  $long_options = null,
  $skip_unknown = false 
)
static

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

Parameters
array$argsan array of command-line arguments
string$short_optionsspecifies the list of allowed short options
array$long_optionsspecifies the list of allowed long options
See also
getopt2()
Returns
array two-element array containing the list of parsed options and the non-option arguments

Definition at line 86 of file Getopt.php.

References doGetopt().

◆ getopt2()

static Console_Getopt::getopt2 (   $args,
  $short_options,
  $long_options = null,
  $skip_unknown = false 
)
static

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

Parameters
array$argsan array of command-line arguments
string$short_optionsspecifies the list of allowed short options
array$long_optionsspecifies the list of allowed long options
boolean$skip_unknownsuppresses Console_Getopt: unrecognized option
Returns
array two-element array containing the list of parsed options and the non-option arguments

Definition at line 69 of file Getopt.php.

References doGetopt().

Referenced by System\_parseArgs().

◆ readPHPArgv()

static Console_Getopt::readPHPArgv ( )
static

Safely read the $argv PHP array across different PHP configurations. Will take care on register_globals and register_argc_argv ini directives

Returns
mixed the $argv PHP array or PEAR error if not registered

Definition at line 349 of file Getopt.php.

References $GLOBALS.


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