Path

ez components / documentation / api reference / 1.0 / consoletools


eZ Components 1.0

ConsoleTools: ezcConsoleOption

[ Tutorial ] [ Class tree ] [ Element index ] [ ChangeLog ] [ Credits ]

Class: ezcConsoleOption

Struct like class to store data about a single option for ezcConsoleInput. [source]
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.

Member Variables

public bool $arguments = true
Whether arguments to the program are allowed, when this parameter is submitted.
public mixed $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 sepcified here.
protected array(string=>ezcConsoleParamemterRule) $dependencies = array()
Dependency rules of this parameter.
protected array(string=>ezcConsoleParamemterRule) $exclusions = array()
Exclusion rules of this parameter.
public string $longhelp = 'Sorry, there is no help text available for this parameter.'
Long help text. Ususally displayed when showing parameter detailed help.
public bool $mandatory = false
Wether a parameter is mandatory to be set.

If this flag is true, the parameter must be submitted whenever the program is run.
public bool $multiple = false
Is the submition of multiple instances of this parameters allowed?
protected array(string) $properties = array(
'short' => '',
'long' => '',
)

Properties, which provide only read access.

Stores the short and long name of a parameter which are readonly after being set once during construction.
public string $shorthelp = 'No help available.'
Short help text. Ususally displayed when showing parameter help overview.
public int $type = ezcConsoleInput::TYPE_NONE
Value type of this parameter, default is ezcConsoleInput::TYPE_NONE.
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 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] )
Create a new parameter struct.
public void addDependency( $rule )
public void addExclusion( $rule )
public array getDependencies( )
Returns the dependency rules registered with this parameter.
public array getExclusions( )
Returns the exclusion rules registered with this parameter.
public bool hasDependency( $param, $rule )
Returns if a given dependency rule is registered with the parameter.
public bool hasExclusion( $param, $rule )
Returns if a given exclusion rule is registered with the parameter.
public void removeAllDependencies( $param )
Remove all dependency rule refering to a parameter.
public void removeAllExclusions( $param )
Remove all exclusion rule refering to a parameter.
public void removeDependency( $rule )
Remove a dependency rule from a parameter.
public void removeExclusion( $rule )
Remove a exclusion rule from a parameter.
public void resetDependencies( )
Reset existing dependency rules.
public void resetExclusions( )
Reset existing exclusion rules.
public static bool validateOptionName( $name )
Returns if a given name if valid for use as a parameter name a paremeter.
public mixed __get( $key )
Property read access.
public bool __isset( $key )
Property isset access.
public void __set( $key, $val )
Property write access.

Methods

__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] )
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(int=>ezcConsoleOptionRule) Dependency rules.
$exclusions array(int=>ezcConsoleOptionRule) Exclusion rules.
$arguments bool Whether supplying arguments is allowed when this parameter is set.
$mandatory bool Whether the parameter must be always submitted.

addDependency

void addDependency( ezcConsoleOptionRule $rule )

Parameters

Name Type Description
$rule ezcConsoleOptionRule  

addExclusion

void addExclusion( ezcConsoleOptionRule $rule )

Parameters

Name Type Description
$rule ezcConsoleOptionRule  

getDependencies

array getDependencies( )
Returns the dependency rules registered with this parameter.
Returns an array of registered dependencies.
For example:
1.  array(
2.       => ezcConsoleOptionRule,
3.       => ezcConsoleOptionRule,
4.       => ezcConsoleOptionRule,
5.  );

getExclusions

array getExclusions( )
Returns the exclusion rules registered with this parameter.
Returns an array of registered exclusions.
For example:
1.  array(
2.       => ezcConsoleOptionRule,
3.       => ezcConsoleOptionRule,
4.       => ezcConsoleOptionRule,
5.  );

hasDependency

bool hasDependency( ezcConsoleOption $param, ezcConsoleOptionRule $rule )
Returns if a given dependency rule is registered with the parameter.
Returns true if the given rule is registered with this parameter, otherwise false.

Parameters

Name Type Description
$rule ezcConsoleOptionRule The rule to be removed.
$param ezcConsoleOption  

hasExclusion

bool hasExclusion( ezcConsoleOption $param, ezcConsoleOptionRule $rule )
Returns if a given exclusion rule is registered with the parameter.
Returns true if the given rule is registered with this parameter, otherwise false.

Parameters

Name Type Description
$rule ezcConsoleOptionRule The rule to be removed.
$param ezcConsoleOption  

removeAllDependencies

void removeAllDependencies( ezcConsoleOption $param )
Remove all dependency rule refering 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 refering to a parameter.
This removes all exclusion 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.

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

resetDependencies

void resetDependencies( )
Reset existing dependency rules.
Deletes all registered dependency rules from the parameter definition.

resetExclusions

void resetExclusions( )
Reset existing exclusion rules.
Deletes all registered exclusion rules from the parameter definition.

validateOptionName

bool validateOptionName( string $name )
Returns if a given name if valid for use as a parameter name a paremeter.
Checks if a given parameter name is generaly 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.

__get

mixed __get( string $key )
Property read access.
Provies read access to the properties of the object.

Parameters

Name Type Description
$key string The name of the property.

__isset

bool __isset( string $key )
Property isset access.

Parameters

Name Type Description
$key string Name of the property.

__set

void __set( string $key, mixed $val )
Property write access.

Parameters

Name Type Description
$key string Name of the property.
$val mixed The value for the property.

Throws

ClassDescription
ezcBasePropertyPermissionException If the property you try to access is read-only.

Last updated: Thu, 31 Jan 2008