Param
in package
Uses
ParamOpts
A simple class representing a parameter for a command line script.
This is not used by itself, but as a child of the Params class.
Table of Contents
- DEFAULT_VALIDENT = 'value'
- OPT_ALIASES = ["valued" => "has_value", "placeholder" => "value_placeholder", "required" => "value_required", "multiple" => "toggle_multi", "present" => "toggle_true", "absent" => "toggle_false", "missing" => "value_missing", "descValue" => "value_desc", "descToggle" => "toggle_desc"]
- OPT_EXCEPTIONS = ["parent", "optname", "varname"]
- $has_value : mixed
- If true, this parameter takes a value, if false it's a toggle.
- $optname : mixed
- The name of the option.
- $toggle_desc : mixed
- For toggle parameters this is the description used.
- $toggle_false : mixed
- For a non-multi toggle parameter, this is the value that will be used in the normalized output if the parameter was not specified.
- $toggle_multi : mixed
- For any toggle parameter, if this is true the parameter can be specified more than once and it's normalized value will always be a numeric value.
- $toggle_true : mixed
- For a non-multi toggle parameter, this is the value that will be used in the normalized output if the parameter was specified.
- $value_desc : mixed
- For parameters with values this is the description used.
- $value_missing : mixed
- For a parameter with a required value, if it's not specified at all, then this will by the default value put into the normalized output.
- $value_placeholder : mixed
- If has_value is true, this will be used in the usage as the identifier.
- $value_required : mixed
- If has_value is true, and this is true, the value is required.
- $varname : mixed
- The variable name for normalized output.
- $parent : mixed
- __construct() : mixed
- Create a new Param instance.
- is_short() : mixed
- Returns true if this is a short parameter.
- syntax() : mixed
- Return the full option syntax.
- __construct_opts() : mixed
- Set instance properties based on an array of options.
Constants
DEFAULT_VALIDENT
public
mixed
DEFAULT_VALIDENT
= 'value'
OPT_ALIASES
public
mixed
OPT_ALIASES
= ["valued" => "has_value", "placeholder" => "value_placeholder", "required" => "value_required", "multiple" => "toggle_multi", "present" => "toggle_true", "absent" => "toggle_false", "missing" => "value_missing", "descValue" => "value_desc", "descToggle" => "toggle_desc"]
OPT_EXCEPTIONS
public
mixed
OPT_EXCEPTIONS
= ["parent", "optname", "varname"]
Properties
$has_value
If true, this parameter takes a value, if false it's a toggle.
public
mixed
$has_value
= false
Constructor aliases: "valued"
$optname
The name of the option.
public
mixed
$optname
May be a single character in which case it's a short option. More than one character is a long option.
The short options may only be alphanumeric.
Long options may have dash (-) or underscore (_) characters as well.
$toggle_desc
For toggle parameters this is the description used.
public
mixed
$toggle_desc
Constructor aliases: "descToggle"
$toggle_false
For a non-multi toggle parameter, this is the value that will be used in the normalized output if the parameter was not specified.
public
mixed
$toggle_false
= false
Constructor aliases: "absent"
$toggle_multi
For any toggle parameter, if this is true the parameter can be specified more than once and it's normalized value will always be a numeric value.
public
mixed
$toggle_multi
= false
Constructor aliases: "multiple"
$toggle_true
For a non-multi toggle parameter, this is the value that will be used in the normalized output if the parameter was specified.
public
mixed
$toggle_true
= true
Constructor aliases: "present"
$value_desc
For parameters with values this is the description used.
public
mixed
$value_desc
Constructor aliases: "descValue"
$value_missing
For a parameter with a required value, if it's not specified at all, then this will by the default value put into the normalized output.
public
mixed
$value_missing
= null
Constructor aliases: "missing"
$value_placeholder
If has_value is true, this will be used in the usage as the identifier.
public
mixed
$value_placeholder
= self::DEFAULT_VALIDENT
As such it should be short with no special characters. Whitespace isn't really recommended, but is allowed. Will automatically be surrounded with < > characters for value_required=true and [ ] characters for value_required=false.
Constructor aliases: "placeholder"
$value_required
If has_value is true, and this is true, the value is required.
public
mixed
$value_required
= true
If this is false, the value may be omitted, in which case it acts as a toggle.
Constructor aliases: "required"
$varname
The variable name for normalized output.
public
mixed
$varname
If more than one parameter use the same varname, they are considered aliases. This is important to note with command groups as they check the varnames first and only fall back on optname if a varname was not found in the normalized parameters.
Must be a valid identifier, so alphanumeric and _ only. No whitespace.
$parent
protected
mixed
$parent
Methods
__construct()
Create a new Param instance.
public
__construct(Params $parent, string $optname[, string $varname = null ][, array<string|int, mixed> $opts = [] ]) : mixed
You probably should never need to call this directly. Use Params::_makeParam() or Param::param() instead.
Parameters
- $parent : Params
-
The Params instance that spawned this.
- $optname : string
-
The optname property for this Param.
- $varname : string = null
-
The varname property for this Param. Optional, if not specified we use $optname.
- $opts : array<string|int, mixed> = []
-
Optional, any properties in here that have corresponding class properties will be populated.
Return values
mixed —is_short()
Returns true if this is a short parameter.
public
is_short() : mixed
Return values
mixed —syntax()
Return the full option syntax.
public
syntax() : mixed
This is our 'optname' with the appropriate '-' or '--' prefix.
Return values
mixed —__construct_opts()
Set instance properties based on an array of options.
protected
__construct_opts(array<string|int, mixed> $opts[, array<string|int, mixed> $exceptions = [] ][, array<string|int, mixed> $aliases = [] ]) : mixed
Parameters
- $opts : array<string|int, mixed>
-
The associative array of options passed.
- $exceptions : array<string|int, mixed> = []
-
A flat array of property/option names to skip.
- $aliases : array<string|int, mixed> = []
-
An associative array of "alias" => "property".