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

Class: Console_CommandLine_Option

Source Location: /Console_CommandLine-1.2.0/Console/CommandLine/Option.php

Class Overview

Console_CommandLine_Element
   |
   --Console_CommandLine_Option

Class that represent a commandline option.


Author(s):

Version:

  • Release: 1.2.0

Copyright:

  • 2007 David JEAN LOUIS

Variables

Methods


Inherited Variables

Inherited Methods

Class: Console_CommandLine_Element

Console_CommandLine_Element::__construct()
Constructor.
Console_CommandLine_Element::toString()
Returns the string representation of the element.
Console_CommandLine_Element::validate()
Validates the element instance and set it's default values.

Class Details

[line 43]
Class that represent a commandline option.


[ Top ]


Class Variables

$action =  'StoreString'

[line 66]

The option action, defaults to "StoreString".
  • Var: Option action
  • Access: public

Type:   string


[ Top ]

$action_params = array()

[line 120]

An associative array of additional params to pass to the class corresponding to the action, this array will also be passed to the callback defined for an action of type Callback, Example:

  1.  // for a custom action
  2.  $parser->addOption('myoption'array(
  3.      'short_name'    => '-m',
  4.      'long_name'     => '--myoption',
  5.      'action'        => 'MyCustomAction',
  6.      'action_params' => array('foo'=>true'bar'=>false)
  7.  ));
  8.  
  9.  // if the user type:
  10.  // $ <yourprogram> -m spam
  11.  // in your MyCustomAction class the execute() method will be called
  12.  // with the value 'spam' as first parameter and
  13.  // array('foo'=>true, 'bar'=>false) as second parameter

  • Var: Additional parameters to pass to the action
  • Access: public

Type:   array


[ Top ]

$add_list_option =  false

[line 137]

For options that uses the "choice" property only.

Adds a --list-<choice> option to the parser that displays the list of choices for the option.

  • Var: Whether to add a list option or not
  • Access: public

Type:   bool


[ Top ]

$argument_optional =  false

[line 128]

For options that expect an argument, this property tells the parser if the option argument is optional and can be ommited.
  • Var: Whether the option arg is optional or not
  • Access: public

Type:   bool


[ Top ]

$callback =

[line 95]

The callback function (or method) to call for an action of type Callback, this can be any callable supported by the php function call_user_func.

Example:

  1.  $parser->addOption('myoption'array(
  2.      'short_name' => '-m',
  3.      'long_name'  => '--myoption',
  4.      'action'     => 'Callback',
  5.      'callback'   => 'myCallbackFunction'
  6.  ));

  • Var: The option callback
  • Access: public

Type:   callable


[ Top ]

$choices = array()

[line 75]

An array of possible values for the option. If this array is not empty and the value passed is not in the array an exception is raised.

This only make sense for actions that accept values of course.

  • Var: Valid choices for the option
  • Access: public

Type:   array


[ Top ]

$long_name =

[line 59]

The option long name (ex: --verbose).
  • Var: Long name of the option
  • Access: public

Type:   string


[ Top ]

$short_name =

[line 52]

The option short name (ex: -v).
  • Var: Short name of the option
  • Access: public

Type:   string


[ Top ]



Method Detail

__construct (Constructor)   [line 160]

void __construct( [string $name = null], [array $params = array()])

Constructor.
  • Access: public

Overrides Console_CommandLine_Element::__construct() (Constructor.)

Parameters:

string   $name   —  The name of the option
array   $params   —  An optional array of parameters

[ Top ]

dispatchAction   [line 234]

void dispatchAction( mixed $value, Console_CommandLine_Result $result, Console_CommandLine $parser)

Formats the value $value according to the action of the option and updates the passed Console_CommandLine_Result object.
  • Throws: Console_CommandLine_Exception
  • Access: public

Parameters:

mixed   $value   —  The value to format
Console_CommandLine_Result   $result   —  The result instance
Console_CommandLine   $parser   —  The parser instance

[ Top ]

expectsArgument   [line 210]

bool expectsArgument( )

Returns true if the option requires one or more argument and false otherwise.
  • Return: Whether the option expects an argument or not
  • Access: public

[ Top ]

setDefaults   [line 337]

void setDefaults( )

Set the default value according to the configured action.

Note that for backward compatibility issues this method is only called when the 'force_options_defaults' is set to true, it will become the default behaviour in the next major release of Console_CommandLine.

  • Access: public

[ Top ]

toString   [line 181]

string toString( [string $delim = ", "])

Returns the string representation of the option.
  • Return: The string representation of the option
  • Todo: use __toString() instead
  • Access: public

Overrides Console_CommandLine_Element::toString() (Returns the string representation of the element.)

Parameters:

string   $delim   —  Delimiter to use between short and long option

[ Top ]

validate   [line 273]

void validate( )

Validates the option instance.
  • Todo: use exceptions instead
  • Throws: Console_CommandLine_Exception
  • Access: public

Overrides Console_CommandLine_Element::validate() (Validates the element instance and set it's default values.)
[ Top ]


Documentation generated on Mon, 11 Mar 2019 15:51:32 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.