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])
Afficher le fichier Open project: webmozart/console Class Usage Examples

Méthodes publiques

Méthode 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 méthode

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 méthode

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.
Résultat static The current instance.

addArguments() public méthode

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

addCommandName() public méthode

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

addCommandNames() public méthode

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

addCommandOption() public méthode

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.
Résultat static The current instance.

addCommandOptions() public méthode

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.
Résultat static The current instance.

addOption() public méthode

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

addOptions() public méthode

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

getArgument() public méthode

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.
Résultat Argument The argument.

getArguments() public méthode

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.
Résultat Argument[] The arguments.

getBaseFormat() public méthode

Returns the base format.
public getBaseFormat ( ) : ArgsFormat
Résultat ArgsFormat The base format.

getCommandNames() public méthode

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.
Résultat CommandName[] The command names.

getCommandOption() public méthode

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.
Résultat CommandOption The command option.

getCommandOptions() public méthode

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.
Résultat CommandOption[] The command options.

getFormat() public méthode

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

getOption() public méthode

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.
Résultat Option The option.

getOptions() public méthode

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.
Résultat Option[] The options.

hasArgument() public méthode

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.
Résultat boolean Returns `true` if the argument with the given name or position could be found and `false` otherwise.

hasArguments() public méthode

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.
Résultat boolean Returns `true` if the builder contains any argument and `false` otherwise.

hasCommandNames() public méthode

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.
Résultat boolean Returns `true` if the builder contains any command names and `false` otherwise.

hasCommandOption() public méthode

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.
Résultat boolean Returns `true` if the command option with the given name could be found and `false` otherwise.

hasCommandOptions() public méthode

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.
Résultat boolean Returns `true` if the builder contains command options and `false` otherwise.

hasMultiValuedArgument() public méthode

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.
Résultat boolean Returns `true` if the builder contains a multi-valued argument and `false` otherwise.

hasOption() public méthode

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.
Résultat boolean Returns `true` if the option with the given name could be found and `false` otherwise.

hasOptionalArgument() public méthode

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.
Résultat boolean Returns `true` if the builder contains an optional argument and `false` otherwise.

hasOptions() public méthode

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.
Résultat boolean Returns `true` if the builder contains any option and `false` otherwise.

hasRequiredArgument() public méthode

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.
Résultat boolean Returns `true` if the builder contains a required argument and `false` otherwise.

setArguments() public méthode

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.
Résultat static The current instance.

setCommandNames() public méthode

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

setCommandOptions() public méthode

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.
Résultat static The current instance.

setOptions() public méthode

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.
Résultat static The current instance.