Overview

Namespaces

  • PHP
  • PhpOptions
    • Types

Classes

  • Arguments
  • Option
  • Options

Exceptions

  • InvalidArgumentException
  • LogicException
  • UserBadCallException
  • Overview
  • Namespace
  • Class
  • Tree
  • Todo

Class Option

Class for bettwer work with one PHP comman-line option

Namespace: PhpOptions
Author: Viktor Mašíček <viktor@masicek.net>
Located at Option.php
Methods summary
public
# __construct( string $name )
Set name of option and default short and long variant in command-line

Set name of option and default short and long variant in command-line

Parameters

$name
string
Name of option

Throws

PhpOptions\InvalidArgumentException
Name of option cannot be empty.

Todo

accept array as second parameere for setting all object
public static PhpOptions\Option
# make( string $name )
Create new option

Create new option

Parameters

$name
string
Name of option

Returns

PhpOptions\Option

See

PhpOptions\Option::__construct()
public static PhpOptions\Option
# __callStatic( string $type, array $settings )
Create new option of specific type. The typed option have required value as default.

Create new option of specific type. The typed option have required value as default.

Parameters

$type
string
$name Name of option
$settings
array
Specific settings for selected type

Returns

PhpOptions\Option

See

PhpOptions\Option::make()
public static
# registerType( string $name, string $className, string $classPath )
Register new type. It has to by child of abstract class AType. It is possible rewrite already registered types (so defaults too).

Register new type. It has to by child of abstract class AType. It is possible rewrite already registered types (so defaults too).

Parameters

$name
string
Name of type
$className
string
Name of class of type with namespace
$classPath
string
Full path of file contains class of type
public PhpOptions\Option
# short( string $short = NULL )
Set short variant of option in command-line

Set short variant of option in command-line

Parameters

$short
string

Returns

PhpOptions\Option

Throws

PhpOptions\LogicException
Short and long varint cannot be undefined together.
PhpOptions\InvalidArgumentException
Short variant have to be only one character.
public PhpOptions\Option
# long( string $long = NULL )
Set long variant of option in command-line

Set long variant of option in command-line

Parameters

$long
string

Returns

PhpOptions\Option

Throws

PhpOptions\LogicException
Short and long varint cannot be undefined together.
public PhpOptions\Option
# defaults( mixed $defaults = NULL )
Set default value of option

Set default value of option

Parameters

$defaults
mixed
$default

Returns

PhpOptions\Option

Throws

PhpOptions\LogicException
The default value makes sense only for options with optional value or optional option with optional or required value.
public PhpOptions\Option
# required( boolean $required = TRUE )
Set flag of requirement of option

Set flag of requirement of option

Parameters

$required
boolean

Returns

PhpOptions\Option

Throws

PhpOptions\LogicException
The required option does not make sense for option with default value and required value
public PhpOptions\Option
# value( boolean $value = TRUE )
Set type of requirement of value of option TRUE = require FALSE = optional

Set type of requirement of value of option TRUE = require FALSE = optional

Parameters

$value
boolean

Returns

PhpOptions\Option

Throws

PhpOptions\LogicException
The require/non value make sense only for option without default value.
public PhpOptions\Option
# description( string $description = '' )
Set description of option used in help

Set description of option used in help

Parameters

$description
string

Returns

PhpOptions\Option
public
# dependences( array $needed )
Set needed options by this option

Set needed options by this option

Parameters

$needed
array
Needed options
public string
# getName( )
Return name of option

Return name of option

Returns

string
public string
# getShort( )
Return short varian of option in command-line

Return short varian of option in command-line

Returns

string
public string
# getLong( )
Return long varian of option in command-line

Return long varian of option in command-line

Returns

string
public mixed
# getDefaults( )
Return default value of option in command-line

Return default value of option in command-line

Returns

mixed
public mixed
# getValue( boolean $isDefaultSet = FALSE )
Return value of option FALSE = not set TRUE = set without value other = value form command-line of default value

Return value of option FALSE = not set TRUE = set without value other = value form command-line of default value

Parameters

$isDefaultSet
boolean
$isDefaiultSet Flag if default option is set

Returns

mixed
public string
# getOptions( string $value = '' )
Return short and long option in one string

Return short and long option in one string

Parameters

$value
string
Value of options (typically type of value)

Returns

string
public string
# getHelp( integer $maxLength, $indent = 0 )
Return help for option

Return help for option

Parameters

$maxLength
integer
$indent Level of indent of text
$indent

Returns

string
Constants summary
string VALUE_NO 'value_no'
#
Type of value requirement - no value

Type of value requirement - no value

string VALUE_REQUIRE 'value_require'
#
Type of value requirement - require value

Type of value requirement - require value

string VALUE_OPTIONAL 'value_optional'
#
Type of value requirement - optional value

Type of value requirement - optional value

integer HELP_INDENT_LENGTH 4
#
Length of indent in printed help

Length of indent in printed help

PhpOptions API documentation generated by ApiGen.
Generated using the TokenReflection library.