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 ArgsFormatBuilder

A builder for Webmozart\Console\Api\Args\Format\ArgsFormat instances.

Use the methods in this class to dynamically build Webmozart\Console\Api\Args\Format\ArgsFormat instances. When you are done configuring the builder, call Webmozart\Console\Api\Args\Format\ArgsFormatBuilder::getFormat() to build an immutable Webmozart\Console\Api\Args\Format\ArgsFormat.

For convenience, you can call ArgsFormat::build() to create a new builder and use its fluent API to configure and build a format:

$format = ArgsFormat::build() ->addCommandName(new CommandName('server')) ->addCommandOption(new CommandOption('add', 'a')) ->addArgument(new Argument('host')) ->addOption(new Option('port', 'p')) ->getFormat();

You can optionally pass a base format to inherit from. The arguments of the base format are prepended to the arguments of the built format. The options of the base format are added to the built options:

$baseFormat = ArgsFormat::build() ->addOption(new Option('verbose', 'v')) ->getFormat();

$format = ArgsFormat::build($baseFormat) // ... ->getFormat();

Read Webmozart\Console\Api\Args\Format\ArgsFormat for a more detailed description of args formats.

Namespace: Webmozart\Console\Api\Args\Format
Author: Bernhard Schussek bschussek@gmail.com
Since: 1.0
See: Webmozart\Console\Api\Args\Format\ArgsFormat
Located at Api/Args/Format/ArgsFormatBuilder.php
Methods summary
public
# __construct( Webmozart\Console\Api\Args\Format\ArgsFormat $baseFormat = null )

Creates a new builder.

Creates a new builder.

You can optionally pass a base format. The built format inherits all the arguments and options from the base format.

Parameters

$baseFormat
The base format.
public Webmozart\Console\Api\Args\Format\ArgsFormat
# getBaseFormat( )

Returns the base format.

Returns the base format.

Returns

Webmozart\Console\Api\Args\Format\ArgsFormat
The base format.
public static
# setCommandNames( array $commandNames )

Sets the command names of the built format.

Sets the command names of the built format.

Parameters

$commandNames
The command names.

Returns

static
The current instance.
public static
# addCommandNames( array $commandNames )

Adds command names to the built format.

Adds command names to the built format.

Parameters

$commandNames
The command names to add.

Returns

static
The current instance.
public static
# addCommandName( Webmozart\Console\Api\Args\Format\CommandName $commandName )

Adds a command name to the built format.

Adds a command name to the built format.

Parameters

$commandName
The command name to add.

Returns

static
The current instance.
public boolean
# hasCommandNames( boolean $includeBase = true )

Returns whether the builder contains any command names.

Returns whether the builder contains any command names.

Parameters

$includeBase

Whether to consider command names of the base format.

Returns

boolean

Returns true if the builder contains any command names and false otherwise.

public Webmozart\Console\Api\Args\Format\CommandName[]
# getCommandNames( boolean $includeBase = true )

Returns all command names added to the builder.

Returns all command names added to the builder.

Parameters

$includeBase

Whether to include command names of the base format in the result.

Returns

Webmozart\Console\Api\Args\Format\CommandName[]
The command names.
public static
# setCommandOptions( array $commandOptions )

Sets the command options of the built format.

Sets the command options of the built format.

Any existing command options are removed when this method is called.

Parameters

$commandOptions

The command options of the built format.

Returns

static
The current instance.

Throws

Webmozart\Console\Api\Args\CannotAddOptionException
If an option cannot be added.

See

Webmozart\Console\Api\Args\Format\ArgsFormatBuilder::addCommandOption()
public static
# addCommandOptions( array $commandOptions )

Adds command options to the builder.

Adds command options to the builder.

The existing command options stored in the builder are preserved.

Parameters

$commandOptions
The command options to add.

Returns

static
The current instance.

Throws

Webmozart\Console\Api\Args\CannotAddOptionException
If an option cannot be added.

See

Webmozart\Console\Api\Args\Format\ArgsFormatBuilder::addCommandOption()
public static
# addCommandOption( Webmozart\Console\Api\Args\Format\CommandOption $commandOption )

Adds a command option to the builder.

Adds a command option to the builder.

The existing command options stored in the builder are preserved.

Parameters

$commandOption
The command option to add.

Returns

static
The current instance.

Throws

Webmozart\Console\Api\Args\CannotAddOptionException
If the option cannot be added.

See

Webmozart\Console\Api\Args\Format\ArgsFormatBuilder::addCommandOptions()
public boolean
# hasCommandOption( string $name, boolean $includeBase = true )

Returns whether the builder contains a specific command option.

Returns whether the builder contains a specific command option.

You can either pass the long or the short name of the command option.

Parameters

$name
The long or short option name.
$includeBase

Whether to include command options in the base format in the search.

Returns

boolean

Returns true if the command option with the given name could be found and false otherwise.

public boolean
# hasCommandOptions( boolean $includeBase = true )

Returns whether the builder contains any command options.

Returns whether the builder contains any command options.

Parameters

$includeBase

Whether to include command options in the base format in the search.

Returns

boolean

Returns true if the builder contains command options and false otherwise.

public Webmozart\Console\Api\Args\Format\CommandOption
# getCommandOption( string $name, boolean $includeBase = true )

Returns a command option by its long or short name.

Returns a command option by its long or short name.

Parameters

$name
The long or short option name.
$includeBase

Whether to include command options in the base format in the search.

Returns

Webmozart\Console\Api\Args\Format\CommandOption
The command option.

Throws

Webmozart\Console\Api\Args\NoSuchOptionException

If the command option with the given name does not not exist.

public Webmozart\Console\Api\Args\Format\CommandOption[]
# getCommandOptions( boolean $includeBase = true )

Returns all command options added to the builder.

Returns all command options added to the builder.

Parameters

$includeBase

Whether to include command options of the base format in the result.

Returns

Webmozart\Console\Api\Args\Format\CommandOption[]
The command options.
public static
# setArguments( array $arguments )

Sets the arguments of the built format.

Sets the arguments of the built format.

Any existing arguments are removed when this method is called.

Parameters

$arguments
The arguments of the built format.

Returns

static
The current instance.

Throws

Webmozart\Console\Api\Args\CannotAddArgumentException
If an argument cannot be added.

See

Webmozart\Console\Api\Args\Format\ArgsFormatBuilder::addArgument()
public static
# addArguments( array $arguments )

Adds arguments at the end of the argument list.

Adds arguments at the end of the argument list.

The existing arguments stored in the builder are preserved.

Parameters

$arguments
The arguments to add.

Returns

static
The current instance.

Throws

Webmozart\Console\Api\Args\CannotAddArgumentException
If an argument cannot be added.

See

Webmozart\Console\Api\Args\Format\ArgsFormatBuilder::addArgument()
public static
# addArgument( Webmozart\Console\Api\Args\Format\Argument $argument )

Adds an argument at the end of the argument list.

Adds an argument at the end of the argument list.

The existing arguments stored in the builder are preserved.

You cannot add arguments after adding a multi-valued argument. If you do so, this method throws an exception.

Adding required arguments after optional arguments is not supported. Also in this case an exception is thrown.

Parameters

$argument
The argument to add.

Returns

static
The current instance.

Throws

Webmozart\Console\Api\Args\CannotAddArgumentException
If the argument cannot be added.
public boolean
# hasArgument( string|integer $name, boolean $includeBase = true )

Returns whether the builder contains a specific argument.

Returns whether the builder contains a specific argument.

You can either pass the name of the argument or the 0-based position of the argument.

Parameters

$name

The argument name or its 0-based position in the argument list.

$includeBase

Whether to include arguments in the base format in the search.

Returns

boolean

Returns true if the argument with the given name or position could be found and false otherwise.

public boolean
# hasMultiValuedArgument( boolean $includeBase = true )

Returns whether the builder contains a multi-valued argument.

Returns whether the builder contains a multi-valued argument.

Parameters

$includeBase

Whether to include arguments in the base format in the search.

Returns

boolean

Returns true if the builder contains a multi-valued argument and false otherwise.

public boolean
# hasOptionalArgument( boolean $includeBase = true )

Returns whether the builder contains an optional argument.

Returns whether the builder contains an optional argument.

Parameters

$includeBase

Whether to include arguments in the base format in the search.

Returns

boolean

Returns true if the builder contains an optional argument and false otherwise.

public boolean
# hasRequiredArgument( boolean $includeBase = true )

Returns whether the builder contains a required argument.

Returns whether the builder contains a required argument.

Parameters

$includeBase

Whether to include arguments in the base format in the search.

Returns

boolean

Returns true if the builder contains a required argument and false otherwise.

public boolean
# hasArguments( boolean $includeBase = true )

Returns whether the builder contains any argument.

Returns whether the builder contains any argument.

Parameters

$includeBase

Whether to include arguments in the base format in the search.

Returns

boolean

Returns true if the builder contains any argument and false otherwise.

public Webmozart\Console\Api\Args\Format\Argument
# getArgument( string|integer $name, boolean $includeBase = true )

Returns an argument by its name or position.

Returns an argument by its name or position.

You can either pass the name of the argument or the 0-based position of the argument.

Parameters

$name

The argument name or its 0-based position in the argument list.

$includeBase

Whether to include arguments in the base format in the search.

Returns

Webmozart\Console\Api\Args\Format\Argument
The argument.

Throws

Webmozart\Console\Api\Args\NoSuchArgumentException

If the argument with the given name or position does not exist.

public Webmozart\Console\Api\Args\Format\Argument[]
# getArguments( boolean $includeBase = true )

Returns all arguments added to the builder.

Returns all arguments added to the builder.

Parameters

$includeBase

Whether to include arguments of the base format in the result.

Returns

Webmozart\Console\Api\Args\Format\Argument[]
The arguments.
public static
# setOptions( array $options )

Sets the options of the built format.

Sets the options of the built format.

Any existing options are removed when this method is called.

Parameters

$options
The options of the built format.

Returns

static
The current instance.

Throws

Webmozart\Console\Api\Args\CannotAddOptionException
If an option cannot be added.

See

Webmozart\Console\Api\Args\Format\ArgsFormatBuilder::addOption()
public static
# addOptions( array $options )

Adds options at the end of the options list.

Adds options at the end of the options list.

The existing options stored in the builder are preserved.

Parameters

$options
The options to add.

Returns

static
The current instance.

Throws

Webmozart\Console\Api\Args\CannotAddOptionException
If an option cannot be added.

See

Webmozart\Console\Api\Args\Format\ArgsFormatBuilder::addOption()
public static
# addOption( Webmozart\Console\Api\Args\Format\Option $option )

Adds an option at the end of the options list.

Adds an option at the end of the options list.

The existing options stored in the builder are preserved.

Parameters

$option
The option to add.

Returns

static
The current instance.

Throws

Webmozart\Console\Api\Args\CannotAddOptionException
If the option cannot be added.

See

Webmozart\Console\Api\Args\Format\ArgsFormatBuilder::addOptions()
public boolean
# hasOption( string $name, boolean $includeBase = true )

Returns whether the builder contains a specific option.

Returns whether the builder contains a specific option.

You can either pass the long or the short name of the option.

Parameters

$name
The long or short option name.
$includeBase

Whether to include options in the base format in the search.

Returns

boolean

Returns true if the option with the given name could be found and false otherwise.

public boolean
# hasOptions( boolean $includeBase = true )

Returns whether the builder contains any option.

Returns whether the builder contains any option.

Parameters

$includeBase

Whether to include options in the base format in the search.

Returns

boolean

Returns true if the builder contains any option and false otherwise.

public Webmozart\Console\Api\Args\Format\Option
# getOption( string $name, boolean $includeBase = true )

Returns an option by its long or short name.

Returns an option by its long or short name.

Parameters

$name
The long or short option name.
$includeBase

Whether to include options in the base format in the search.

Returns

Webmozart\Console\Api\Args\Format\Option
The option.

Throws

Webmozart\Console\Api\Args\NoSuchOptionException

If the option with the given name does not not exist.

public Webmozart\Console\Api\Args\Format\Option[]
# getOptions( boolean $includeBase = true )

Returns all options added to the builder.

Returns all options added to the builder.

Parameters

$includeBase

Whether to include options of the base format in the result.

Returns

Webmozart\Console\Api\Args\Format\Option[]
The options.
public Webmozart\Console\Api\Args\Format\ArgsFormat
# getFormat( )

Builds a format with the arguments and options added to the builder.

Builds a format with the arguments and options added to the builder.

Returns

Webmozart\Console\Api\Args\Format\ArgsFormat
The built format.
Webmozart Console API API documentation generated by ApiGen