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

Class: Console_CommandLine_Option

Source Location: /Console_CommandLine-1.0.0RC3/CommandLine/Option.php

Class Overview

Console_CommandLine_Element
   |
   --Console_CommandLine_Option

Class that represent a commandline option.


Author(s):

Version:

  • Release: 1.0.0RC3

Copyright:

  • 2007 David JEAN LOUIS

Variables

Methods


Inherited Variables

Inherited Methods

Class: Console_CommandLine_Element

Console_CommandLine_Element::__construct()
Constructor.
Console_CommandLine_Element::toString()
Return the string representation of the argument.
Console_CommandLine_Element::validate()
Validate the option instance.

Class Details

[line 42]
Class that represent a commandline option.


[ Top ]


Class Variables

$action =  'StoreString'

[line 68]

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

Type:   int


[ Top ]

$action_params = array()

[line 133]

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

  • Access: public

Type:   array


[ Top ]

$argument_optional =  false

[line 142]

For options that expect an argument, this property tells the parser if the argument is optional and can be ommited
  • Access: public

Type:   boolean


[ Top ]

$callback =

[line 107]

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

  • Access: public

Type:   mixed


[ Top ]

$choices = array()

[line 86]

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.

  • Access: public

Type:   array


[ Top ]

$default =

[line 76]

The default value of the option if not provided on the command line.
  • Access: public

Type:   mixed


[ Top ]

$long_name =

[line 60]

The option long name (ex: --verbose).
  • Access: public

Type:   string


[ Top ]

$short_name =

[line 52]

The option short name (ex: -v).
  • Access: public

Type:   string


[ Top ]



Method Detail

__construct (Constructor)   [line 155]

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

Constructor.
  • Access: public

Overrides Console_CommandLine_Element::__construct() (Constructor.)

Parameters:

string   $name   —  the name of the element
array   $params   —  an optional array of parameters

[ Top ]

dispatchAction   [line 228]

void dispatchAction( mixed $value, object $result, object $parser)

Format the value $value according to the action of the option and update the passed Console_CommandLine_Result object.
  • Access: public

Parameters:

mixed   $value   —  the value to format
object   $result   —  a Console_CommandLine_Result instance
object   $parser   —  a Console_CommandLine instance

[ Top ]

expectsArgument   [line 204]

boolean expectsArgument( )

Return true if the option requires one or more argument and false otherwise.
  • Access: public

[ Top ]

toString   [line 174]

string toString( )

Return the string representation of the option.
  • Access: public

Overrides Console_CommandLine_Element::toString() (Return the string representation of the argument.)
[ Top ]

validate   [line 259]

void validate( )

Validate the option instance.
  • Access: public

Overrides Console_CommandLine_Element::validate() (Validate the option instance.)
[ Top ]


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