Apache Zeta Components - high quality PHP components

Apache Zeta Components Manual :: Docs For Class ezcConsoleOption

ConsoleTools::ezcConsoleOption

Class ezcConsoleOption

Objects of this class store data about a single option for ezcConsoleInput.

This class represents a single command line option, which can be handled by the ezcConsoleInput class. This classes only purpose is the storage of the parameter data, the handling of options and arguments is done by the class ezcConsoleInput.

Source for this file: /ConsoleTools/src/input/option.php

Version:   //autogen//

Properties

bool read/write $arguments
Whether arguments to the program are allowed, when this parameter is submitted.
mixed read/write $default
Default value if the parameter is submitted without value. If a parameter is eg. of type ezcConsoleInput::TYPE_STRING and therefore expects a value when being submitted, it may be submitted without a value and automatically get the default value specified here.
bool read/write $isHelpOption
Whether a parameter is a help option. If this flag is true, and the parameter is set, all options marked as mandatory may be skipped.
string read $long
Long name of the parameter without '--' (eg. 'file').
string read/write $longhelp
Long help text. Usually displayed when showing parameter detailed help.
bool read/write $mandatory
Whether a parameter is mandatory to be set. If this flag is true, the parameter must be submitted whenever the program is run.
bool read/write $multiple
Is the submission of multiple instances of this parameters allowed?
string read $short
Short name of the parameter without '-' (eg. 'f').
string read/write $shorthelp
Short help text. Usually displayed when showing parameter help overview.
int read/write $type
Value type of this parameter, default is ezcConsoleInput::TYPE_NONE. See ezcConsoleInput::TYPE_NONE, ezcConsoleInput::TYPE_INT and ezcConsoleInput::TYPE_STRING.

Member Variables

protected array(string=>ezcConsoleParamemterRule) $dependencies = array()
Dependency rules of this parameter.
protected array(string=>ezcConsoleParamemterRule) $exclusions = array()
Exclusion rules of this parameter.
protected array(string=>mixed) $properties
Container to hold the properties
public mixed $value = false
The value the parameter was assigned to when being submitted.

Boolean false indicates the parameter was not submitted, boolean true means the parameter was submitted, but did not have a value. In any other case, this caries the submitted value.

Method Summary

public static bool validateOptionName( $name )
Returns if a given name if valid for use as a parameter name a parameter.
public ezcConsoleOption __construct( [ $short = ''] , $long , [ $type = ezcConsoleInput::TYPE_NONE] , [ $default = null] , [ $multiple = false] , [ $shorthelp = 'No help available.'] , [ $longhelp = 'Sorry, there is no help text available for this parameter.'] , [ $dependencies = array()] , [ $exclusions = array()] , [ $arguments = true] , [ $mandatory = false] , [ $isHelpOption = false] )
Create a new parameter struct.
public void addDependency( $rule )
Add a new dependency for a parameter.
public void addExclusion( $rule )
Add a new exclusion for an option.
public array(ezcConsoleOptionRule) getDependencies( )
Returns the dependency rules registered with this parameter.
public array(ezcConsoleOptionRule) getExclusions( )
Returns the exclusion rules registered with this parameter.
public bool hasDependency( $param )
Returns if a dependency to the given option exists.
public bool hasExclusion( $param )
Returns if a given exclusion rule is registered with the option.
public void removeAllDependencies( $param )
Remove all dependency rule referring to a parameter.
public void removeAllExclusions( $param )
Remove all exclusion rule referring to a option.
public void removeDependency( $rule )
Remove a dependency rule from a parameter.
public void removeExclusion( $rule )
Remove a exclusion rule from a option.
public void resetDependencies( )
Reset existing dependency rules.
public void resetExclusions( )
Reset existing exclusion rules.

Methods

validateOptionName

static bool validateOptionName( string $name )

Returns if a given name if valid for use as a parameter name a parameter.

Checks if a given parameter name is generally valid for use. It checks a) that the name does not start with '-' or '--' and b) if it contains whitespaces. Note, that this method does not check any conflicts with already used parameter names.

Parameters:
Name Type Description
$name string The name to check.

__construct

ezcConsoleOption __construct( [string $short = ''] , string $long , [int $type = ezcConsoleInput::TYPE_NONE] , [mixed $default = null] , [bool $multiple = false] , [string $shorthelp = 'No help available.'] , [string $longhelp = 'Sorry, there is no help text available for this parameter.'] , [ $dependencies = array()] , [ $exclusions = array()] , [bool $arguments = true] , [bool $mandatory = false] , [bool $isHelpOption = false] )

Create a new parameter struct.

Creates a new basic parameter struct with the base information "$short" (the short name of the parameter) and "$long" (the long version). You simply apply these parameters as strings (without '-' or '--'). So

  1.  $param = new ezcConsoleOption( 'f', 'file' );

will result in a parameter that can be accessed using

  1.  $ mytool -f

or

  1.  $ mytool --file
.

The newly created parameter contains only it's 2 names and each other attribute is set to it's default value. You can simply manipulate those attributes by accessing them directly.

Parameters:
Name Type Description
$short string Short name of the parameter without '-' (eg. 'f').
$long string Long name of the parameter without '--' (eg. 'file').
$type int Value type of the parameter. One of ezcConsoleInput::TYPE_*.
$default mixed Default value the parameter holds if not submitted.
$multiple bool If the parameter may be submitted multiple times.
$shorthelp string Short help text.
$longhelp string Long help text.
$dependencies array(ezcConsoleOptionRule) Dependency rules.
$exclusions array(ezcConsoleOptionRule) Exclusion rules.
$arguments bool Whether supplying arguments is allowed when this parameter is set.
$mandatory bool Whether the parameter must be always submitted.
$isHelpOption bool Indicates that the given parameter is a help option. If a help option is set, all rule checking is skipped (dependency/exclusion/ mandatory).
Exceptions:
Type Description
ezcConsoleInvalidOptionNameException If the option names start with a "-" sign or contain whitespaces.

addDependency

void addDependency( ezcConsoleOptionRule $rule )

Add a new dependency for a parameter.

This registeres a new dependency rule with the parameter. If you try to add an already registered rule it will simply be ignored. Else, the submitted rule will be added to the parameter as a dependency.

Parameters:
Name Type Description
$rule ezcConsoleOptionRule The rule to add.

addExclusion

void addExclusion( ezcConsoleOptionRule $rule )

Add a new exclusion for an option.

This registeres a new exclusion rule with the option. If you try to add an already registered rule it will simply be ignored. Else, the submitted rule will be added to the option as a exclusion.

Parameters:
Name Type Description
$rule ezcConsoleOptionRule The rule to add.

getDependencies

array(ezcConsoleOptionRule) getDependencies( )

Returns the dependency rules registered with this parameter.

Returns an array of registered dependencies.

For example:

  1.  array(
  2.       0 => ezcConsoleOptionRule,
  3.       1 => ezcConsoleOptionRule,
  4.       2 => ezcConsoleOptionRule,
  5.  );

getExclusions

array(ezcConsoleOptionRule) getExclusions( )

Returns the exclusion rules registered with this parameter.

Returns an array of registered exclusions.

For example:

  1.  array(
  2.       0 => ezcConsoleOptionRule,
  3.       1 => ezcConsoleOptionRule,
  4.       2 => ezcConsoleOptionRule,
  5.  );

hasDependency

bool hasDependency( ezcConsoleOption $param )

Returns if a dependency to the given option exists.

Returns true if a dependency rule to the given option is registered, otherwise false.

Parameters:
Name Type Description
$param ezcConsoleOption The param to check if a dependency exists to.

hasExclusion

bool hasExclusion( ezcConsoleOption $param )

Returns if a given exclusion rule is registered with the option.

Returns true if a exclusion rule to the given option is registered, otherwise false.

Parameters:
Name Type Description
$param ezcConsoleOption The param to check if exclusions exist for.

removeAllDependencies

void removeAllDependencies( ezcConsoleOption $param )

Remove all dependency rule referring to a parameter.

This removes all dependency rules from a parameter, that refer to as specific parameter. If no rule is registered with this parameter as reference, the method call will simply be ignored.

Parameters:
Name Type Description
$param ezcConsoleOption The param to be check for rules.

removeAllExclusions

void removeAllExclusions( ezcConsoleOption $param )

Remove all exclusion rule referring to a option.

This removes all exclusion rules from a option, that refer to as specific option. If no rule is registered with this option as reference, the method call will simply be ignored.

Parameters:
Name Type Description
$param ezcConsoleOption The option to remove rule for.

removeDependency

void removeDependency( ezcConsoleOptionRule $rule )

Remove a dependency rule from a parameter.

This removes a given rule from a parameter, if it exists. If the rule is not registered with the parameter, the method call will simply be ignored.

Parameters:
Name Type Description
$rule ezcConsoleOptionRule The rule to be removed.

removeExclusion

void removeExclusion( ezcConsoleOptionRule $rule )

Remove a exclusion rule from a option.

This removes a given rule from a option, if it exists. If the rule is not registered with the option, the method call will simply be ignored.

Parameters:
Name Type Description
$rule ezcConsoleOptionRule The rule to be removed.

resetDependencies

void resetDependencies( )

Reset existing dependency rules.

Deletes all registered dependency rules from the option definition.

resetExclusions

void resetExclusions( )

Reset existing exclusion rules.

Deletes all registered exclusion rules from the option definition.

Documentation generated by phpDocumentor 1.4.3