Overview

Namespaces

  • Webmozart
    • Console
      • Adapter
      • Api
        • Application
        • Args
          • Format
        • Command
        • Config
        • Event
        • Formatter
        • IO
        • Resolver
      • Args
      • Config
      • Formatter
      • Handler
        • Help
      • IO
        • InputStream
        • OutputStream
      • Process
      • Resolver
      • UI
        • Alignment
        • Component
        • Help
        • Layout
        • Style
      • Util

Classes

  • AbstractOption
  • ArgsFormat
  • ArgsFormatBuilder
  • Argument
  • CommandName
  • CommandOption
  • Option

Exceptions

  • InvalidValueException
  • Overview
  • Namespace
  • Class

Class Argument

An input argument.

Args arguments are passed after the command name and its options. In the example below, "localhost" is the argument to the "server -d" command.

$ console server -d localhost

Arguments can be either optional or required. By default, all arguments are optional, but you can explicitly make an argument optional or required by passing one of the flags Webmozart\Console\Api\Args\Format\Argument::OPTIONAL and Webmozart\Console\Api\Args\Format\Argument::REQUIRED to the constructor:

$argument = new Argument('server', Argument::REQUIRED);

Arguments can also be multi-valued. Multi-valued arguments can be passed any number of times:

$ console server -d localhost google.com

To create a multi-valued argument, pass the flag Webmozart\Console\Api\Args\Format\Argument::MULTI_VALUED to the constructor:

$argument = new Argument('server', Argument::MULTI_VALUED);

You can combine the Webmozart\Console\Api\Args\Format\Argument::MULTI_VALUED flag with either Webmozart\Console\Api\Args\Format\Argument::OPTIONAL or Webmozart\Console\Api\Args\Format\Argument::REQUIRED using the bitwise operator "|":

$argument = new Argument('server', Argument::REQUIRED | Argument::MULTI_VALUED);
Namespace: Webmozart\Console\Api\Args\Format
Author: Bernhard Schussek bschussek@gmail.com
Since: 1.0
Located at Api/Args/Format/Argument.php
Methods summary
public
# __construct( string $name, integer $flags = 0, string $description = null, mixed $defaultValue = null )

Creates a new argument.

Creates a new argument.

Parameters

$name
The argument name
$flags
A bitwise combination of the flag constants.
$description
A human-readable description of the argument.
$defaultValue

The default value of the argument (must be null for the flag self::REQUIRED).

public string
# getName( )

Returns the name of the argument.

Returns the name of the argument.

Returns

string
The argument name.
public boolean
# isRequired( )

Returns whether the argument is required.

Returns whether the argument is required.

Returns

boolean

Returns true if the flag Webmozart\Console\Api\Args\Format\Argument::REQUIRED was passed to the constructor.

public boolean
# isOptional( )

Returns whether the argument is optional.

Returns whether the argument is optional.

Returns

boolean

Returns true if the flag Webmozart\Console\Api\Args\Format\Argument::OPTIONAL was passed to the constructor.

public boolean
# isMultiValued( )

Returns whether the argument accepts multiple values.

Returns whether the argument accepts multiple values.

Returns

boolean

Returns true if the flag Webmozart\Console\Api\Args\Format\Argument::MULTI_VALUED was passed to the constructor.

public
# setDefaultValue( mixed $defaultValue = null )

Sets the default value.

Sets the default value.

If the argument is required, this method throws an exception.

If the option is multi-valued, the passed value must be an array or null.

Parameters

$defaultValue
The default value.

Throws

Webmozart\Console\Api\Args\Format\InvalidValueException
If the default value is invalid.
public mixed
# getDefaultValue( )

Returns the default value of the argument.

Returns the default value of the argument.

Returns

mixed
The default value.
public mixed
# parseValue( mixed $value )

Parses an argument value.

Parses an argument value.

Pass one of the flags Webmozart\Console\Api\Args\Format\Argument::STRING, Webmozart\Console\Api\Args\Format\Argument::BOOLEAN, Webmozart\Console\Api\Args\Format\Argument::INTEGER and Webmozart\Console\Api\Args\Format\Argument::FLOAT to the constructor to configure the result of this method. You can optionally combine the flags with Webmozart\Console\Api\Args\Format\Argument::NULLABLE to support the conversion of "null" to null.

Parameters

$value
The value to parse.

Returns

mixed
The parsed value.

Throws

Webmozart\Console\Api\Args\Format\InvalidValueException
public string
# getDescription( )

Returns the description text.

Returns the description text.

Returns

string
The description text.
Constants summary
integer REQUIRED

Flag: The argument is required.

Flag: The argument is required.

# 1
integer OPTIONAL

Flag: The argument is optional.

Flag: The argument is optional.

# 2
integer MULTI_VALUED

Flag: The argument can be repeated multiple times.

Flag: The argument can be repeated multiple times.

# 4
integer STRING

Flag: The value is parsed as string.

Flag: The value is parsed as string.

# 16
integer BOOLEAN

Flag: The value is parsed as boolean.

Flag: The value is parsed as boolean.

# 32
integer INTEGER

Flag: The value is parsed as integer.

Flag: The value is parsed as integer.

# 64
integer FLOAT

Flag: The value is parsed as float.

Flag: The value is parsed as float.

# 128
integer NULLABLE

Flag: The value "null" should be parsed as null.

Flag: The value "null" should be parsed as null.

# 256
Webmozart Console API API documentation generated by ApiGen