PHP Class Webmozart\Console\Api\Args\Format\ArgsFormatBuilder

Use the methods in this class to dynamically build {@link ArgsFormat} instances. When you are done configuring the builder, call {@link getFormat()} to build an immutable {@link ArgsFormat}. For convenience, you can call {@link ArgsFormat::build()} to create a new builder and use its fluent API to configure and build a format: php $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: php $baseFormat = ArgsFormat::build() ->addOption(new Option('verbose', 'v')) ->getFormat(); $format = ArgsFormat::build($baseFormat) ... ->getFormat(); Read {@link ArgsFormat} for a more detailed description of args formats.
See also: ArgsFormat
Since: 1.0
Author: Bernhard Schussek ([email protected])
Mostra file Open project: webmozart/console Class Usage Examples

Public Methods

Method Description
__construct ( ArgsFormat $baseFormat = null ) Creates a new builder.
addArgument ( Argument $argument ) : static Adds an argument at the end of the argument list.
addArguments ( array $arguments ) : static Adds arguments at the end of the argument list.
addCommandName ( CommandName $commandName ) : static Adds a command name to the built format.
addCommandNames ( array $commandNames ) : static Adds command names to the built format.
addCommandOption ( CommandOption $commandOption ) : static Adds a command option to the builder.
addCommandOptions ( array $commandOptions ) : static Adds command options to the builder.
addOption ( Option $option ) : static Adds an option at the end of the options list.
addOptions ( array $options ) : static Adds options at the end of the options list.
getArgument ( string | integer $name, boolean $includeBase = true ) : Argument Returns an argument by its name or position.
getArguments ( boolean $includeBase = true ) : Argument[] Returns all arguments added to the builder.
getBaseFormat ( ) : ArgsFormat Returns the base format.
getCommandNames ( boolean $includeBase = true ) : CommandName[] Returns all command names added to the builder.
getCommandOption ( string $name, boolean $includeBase = true ) : CommandOption Returns a command option by its long or short name.
getCommandOptions ( boolean $includeBase = true ) : CommandOption[] Returns all command options added to the builder.
getFormat ( ) : ArgsFormat Builds a format with the arguments and options added to the builder.
getOption ( string $name, boolean $includeBase = true ) : Option Returns an option by its long or short name.
getOptions ( boolean $includeBase = true ) : Option[] Returns all options added to the builder.
hasArgument ( string | integer $name, boolean $includeBase = true ) : boolean Returns whether the builder contains a specific argument.
hasArguments ( boolean $includeBase = true ) : boolean Returns whether the builder contains any argument.
hasCommandNames ( boolean $includeBase = true ) : boolean Returns whether the builder contains any command names.
hasCommandOption ( string $name, boolean $includeBase = true ) : boolean Returns whether the builder contains a specific command option.
hasCommandOptions ( boolean $includeBase = true ) : boolean Returns whether the builder contains any command options.
hasMultiValuedArgument ( boolean $includeBase = true ) : boolean Returns whether the builder contains a multi-valued argument.
hasOption ( string $name, boolean $includeBase = true ) : boolean Returns whether the builder contains a specific option.
hasOptionalArgument ( boolean $includeBase = true ) : boolean Returns whether the builder contains an optional argument.
hasOptions ( boolean $includeBase = true ) : boolean Returns whether the builder contains any option.
hasRequiredArgument ( boolean $includeBase = true ) : boolean Returns whether the builder contains a required argument.
setArguments ( array $arguments ) : static Sets the arguments of the built format.
setCommandNames ( array $commandNames ) : static Sets the command names of the built format.
setCommandOptions ( array $commandOptions ) : static Sets the command options of the built format.
setOptions ( array $options ) : static Sets the options of the built format.

Method Details

__construct() public method

You can optionally pass a base format. The built format inherits all the arguments and options from the base format.
public __construct ( ArgsFormat $baseFormat = null )
$baseFormat ArgsFormat The base format.

addArgument() public method

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.
public addArgument ( Argument $argument ) : static
$argument Argument The argument to add.
return static The current instance.

addArguments() public method

The existing arguments stored in the builder are preserved.
See also: addArgument()
public addArguments ( array $arguments ) : static
$arguments array The arguments to add.
return static The current instance.

addCommandName() public method

Adds a command name to the built format.
public addCommandName ( CommandName $commandName ) : static
$commandName CommandName The command name to add.
return static The current instance.

addCommandNames() public method

Adds command names to the built format.
public addCommandNames ( array $commandNames ) : static
$commandNames array The command names to add.
return static The current instance.

addCommandOption() public method

The existing command options stored in the builder are preserved.
See also: addCommandOptions()
public addCommandOption ( CommandOption $commandOption ) : static
$commandOption CommandOption The command option to add.
return static The current instance.

addCommandOptions() public method

The existing command options stored in the builder are preserved.
See also: addCommandOption()
public addCommandOptions ( array $commandOptions ) : static
$commandOptions array The command options to add.
return static The current instance.

addOption() public method

The existing options stored in the builder are preserved.
See also: addOptions()
public addOption ( Option $option ) : static
$option Option The option to add.
return static The current instance.

addOptions() public method

The existing options stored in the builder are preserved.
See also: addOption()
public addOptions ( array $options ) : static
$options array The options to add.
return static The current instance.

getArgument() public method

You can either pass the name of the argument or the 0-based position of the argument.
public getArgument ( string | integer $name, boolean $includeBase = true ) : Argument
$name string | integer The argument name or its 0-based position in the argument list.
$includeBase boolean Whether to include arguments in the base format in the search.
return Argument The argument.

getArguments() public method

Returns all arguments added to the builder.
public getArguments ( boolean $includeBase = true ) : Argument[]
$includeBase boolean Whether to include arguments of the base format in the result.
return Argument[] The arguments.

getBaseFormat() public method

Returns the base format.
public getBaseFormat ( ) : ArgsFormat
return ArgsFormat The base format.

getCommandNames() public method

Returns all command names added to the builder.
public getCommandNames ( boolean $includeBase = true ) : CommandName[]
$includeBase boolean Whether to include command names of the base format in the result.
return CommandName[] The command names.

getCommandOption() public method

Returns a command option by its long or short name.
public getCommandOption ( string $name, boolean $includeBase = true ) : CommandOption
$name string The long or short option name.
$includeBase boolean Whether to include command options in the base format in the search.
return CommandOption The command option.

getCommandOptions() public method

Returns all command options added to the builder.
public getCommandOptions ( boolean $includeBase = true ) : CommandOption[]
$includeBase boolean Whether to include command options of the base format in the result.
return CommandOption[] The command options.

getFormat() public method

Builds a format with the arguments and options added to the builder.
public getFormat ( ) : ArgsFormat
return ArgsFormat The built format.

getOption() public method

Returns an option by its long or short name.
public getOption ( string $name, boolean $includeBase = true ) : Option
$name string The long or short option name.
$includeBase boolean Whether to include options in the base format in the search.
return Option The option.

getOptions() public method

Returns all options added to the builder.
public getOptions ( boolean $includeBase = true ) : Option[]
$includeBase boolean Whether to include options of the base format in the result.
return Option[] The options.

hasArgument() public method

You can either pass the name of the argument or the 0-based position of the argument.
public hasArgument ( string | integer $name, boolean $includeBase = true ) : boolean
$name string | integer The argument name or its 0-based position in the argument list.
$includeBase boolean Whether to include arguments in the base format in the search.
return boolean Returns `true` if the argument with the given name or position could be found and `false` otherwise.

hasArguments() public method

Returns whether the builder contains any argument.
public hasArguments ( boolean $includeBase = true ) : boolean
$includeBase boolean Whether to include arguments in the base format in the search.
return boolean Returns `true` if the builder contains any argument and `false` otherwise.

hasCommandNames() public method

Returns whether the builder contains any command names.
public hasCommandNames ( boolean $includeBase = true ) : boolean
$includeBase boolean Whether to consider command names of the base format.
return boolean Returns `true` if the builder contains any command names and `false` otherwise.

hasCommandOption() public method

You can either pass the long or the short name of the command option.
public hasCommandOption ( string $name, boolean $includeBase = true ) : boolean
$name string The long or short option name.
$includeBase boolean Whether to include command options in the base format in the search.
return boolean Returns `true` if the command option with the given name could be found and `false` otherwise.

hasCommandOptions() public method

Returns whether the builder contains any command options.
public hasCommandOptions ( boolean $includeBase = true ) : boolean
$includeBase boolean Whether to include command options in the base format in the search.
return boolean Returns `true` if the builder contains command options and `false` otherwise.

hasMultiValuedArgument() public method

Returns whether the builder contains a multi-valued argument.
public hasMultiValuedArgument ( boolean $includeBase = true ) : boolean
$includeBase boolean Whether to include arguments in the base format in the search.
return boolean Returns `true` if the builder contains a multi-valued argument and `false` otherwise.

hasOption() public method

You can either pass the long or the short name of the option.
public hasOption ( string $name, boolean $includeBase = true ) : boolean
$name string The long or short option name.
$includeBase boolean Whether to include options in the base format in the search.
return boolean Returns `true` if the option with the given name could be found and `false` otherwise.

hasOptionalArgument() public method

Returns whether the builder contains an optional argument.
public hasOptionalArgument ( boolean $includeBase = true ) : boolean
$includeBase boolean Whether to include arguments in the base format in the search.
return boolean Returns `true` if the builder contains an optional argument and `false` otherwise.

hasOptions() public method

Returns whether the builder contains any option.
public hasOptions ( boolean $includeBase = true ) : boolean
$includeBase boolean Whether to include options in the base format in the search.
return boolean Returns `true` if the builder contains any option and `false` otherwise.

hasRequiredArgument() public method

Returns whether the builder contains a required argument.
public hasRequiredArgument ( boolean $includeBase = true ) : boolean
$includeBase boolean Whether to include arguments in the base format in the search.
return boolean Returns `true` if the builder contains a required argument and `false` otherwise.

setArguments() public method

Any existing arguments are removed when this method is called.
See also: addArgument()
public setArguments ( array $arguments ) : static
$arguments array The arguments of the built format.
return static The current instance.

setCommandNames() public method

Sets the command names of the built format.
public setCommandNames ( array $commandNames ) : static
$commandNames array The command names.
return static The current instance.

setCommandOptions() public method

Any existing command options are removed when this method is called.
See also: addCommandOption()
public setCommandOptions ( array $commandOptions ) : static
$commandOptions array The command options of the built format.
return static The current instance.

setOptions() public method

Any existing options are removed when this method is called.
See also: addOption()
public setOptions ( array $options ) : static
$options array The options of the built format.
return static The current instance.