PHP Класс Webmozart\Console\Api\Args\Format\ArgsFormat

This class is a container for {@link CommandName}, {@link CommandOption}, {@link Option} and {@link Argument} objects. The format is used to interpret a given {@link RawArgs} instance. You can pass the options and arguments to the constructor of the class: php $format = new ArgsFormat(array( new CommandName('server'), new CommandName('add'), new Argument('host', Argument::REQUIRED), new Option('port', 'p', Option::VALUE_OPTIONAL, null, 80), )); The previous example configures a command that can be called like this: $ console server add localhost $ console server add localhost --port 8080 If the "add" command should be called via an option, change the format to: php $format = new ArgsFormat(array( new CommandName('server'), new CommandOption('add', 'a'), new Argument('host', Argument::REQUIRED), new Option('port', 'p', Option::VALUE_OPTIONAL, null, 80), )); The command is then called like this: $ console server --add localhost $ console server --add localhost --port 8080 The format is immutable after its construction. This is necessary to maintain consistency when one format inherits from another. For example, adding a required argument to the base format of a format that already contains optional arguments is an illegal operation that cannot be prevented if the formats are mutable. If you want to create a format stepwisely, use an {@link ArgsFormatBuilder}. If multiple formats share a common set of options and arguments, extract these options and arguments into a base format and let the other formats inherit from this base format: php $baseFormat = new ArgsFormat(array( new Option('verbose', 'v'), )); $format = new ArgsFormat(array( new CommandName('server'), new CommandName('add'), new Argument('host', Argument::REQUIRED), new Option('port', 'p', Option::VALUE_OPTIONAL, null, 80), ), $baseFormat);
С версии: 1.0
Автор: Bernhard Schussek ([email protected])
Показать файл Открыть проект Примеры использования класса

Открытые методы

Метод Описание
__construct ( array | ArgsFormatBuilder $elements = [], ArgsFormat $baseFormat = null ) Creates a new format.
build ( ArgsFormat $baseFormat = null ) : ArgsFormatBuilder Returns a format builder.
getArgument ( string | integer $name, boolean $includeBase = true ) : Argument Returns an argument by its name or position.
getArguments ( boolean $includeBase = true ) : Argument[] Returns all arguments of the format.
getBaseFormat ( ) : ArgsFormat Returns the base format.
getCommandNames ( boolean $includeBase = true ) : CommandName[] Returns the command names.
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 of the format.
getNumberOfArguments ( boolean $includeBase = true ) : integer Returns the number of arguments.
getNumberOfRequiredArguments ( boolean $includeBase = true ) : integer Returns the number of required arguments.
getOption ( string $name, boolean $includeBase = true ) : Option Returns an option by its long or short name.
getOptions ( boolean $includeBase = true ) : Option[] Returns all options of the format.
hasArgument ( string | integer $name, boolean $includeBase = true ) : boolean Returns whether the format contains a specific argument.
hasArguments ( boolean $includeBase = true ) : boolean Returns whether the format contains any argument.
hasCommandNames ( boolean $includeBase = true ) : boolean Returns whether the format contains any command names.
hasCommandOption ( string $name, boolean $includeBase = true ) : boolean Returns whether the format contains a specific command option.
hasCommandOptions ( boolean $includeBase = true ) : boolean Returns whether the format contains command options.
hasMultiValuedArgument ( boolean $includeBase = true ) : boolean Returns whether the format contains a multi-valued argument.
hasOption ( string $name, boolean $includeBase = true ) : boolean Returns whether the format contains a specific option.
hasOptionalArgument ( boolean $includeBase = true ) : boolean Returns whether the format contains an optional argument.
hasOptions ( boolean $includeBase = true ) : boolean Returns whether the format contains options.
hasRequiredArgument ( boolean $includeBase = true ) : boolean Returns whether the format contains a required argument.

Приватные методы

Метод Описание
createBuilderForElements ( array $elements, ArgsFormat $baseFormat = null ) : ArgsFormatBuilder Creates a format builder for a set of arguments and options.

Описание методов

__construct() публичный Метод

You can optionally pass a base format. The created format inherits all the arguments and options defined in the base format.
public __construct ( array | ArgsFormatBuilder $elements = [], ArgsFormat $baseFormat = null )
$elements array | ArgsFormatBuilder The arguments and options or a builder instance.
$baseFormat ArgsFormat The format.

build() публичный статический Метод

You can optionally pass a base format. The built format inherits all the arguments and options defined in the base format.
public static build ( ArgsFormat $baseFormat = null ) : ArgsFormatBuilder
$baseFormat ArgsFormat The base format.
Результат ArgsFormatBuilder The created builder.

getArgument() публичный Метод

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.
Результат Argument The argument.

getArguments() публичный Метод

Returns all arguments of the format.
public getArguments ( boolean $includeBase = true ) : Argument[]
$includeBase boolean Whether to include arguments of the base format in the result.
Результат Argument[] The arguments.

getBaseFormat() публичный Метод

Returns the base format.
public getBaseFormat ( ) : ArgsFormat
Результат ArgsFormat The base format.

getCommandNames() публичный Метод

Returns the command names.
public getCommandNames ( boolean $includeBase = true ) : CommandName[]
$includeBase boolean Whether to include command names in the base format in the result.
Результат CommandName[] The command names.

getCommandOption() публичный Метод

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 options in the base format in the search.
Результат CommandOption The command option.

getCommandOptions() публичный Метод

Returns all command options of the format.
public getCommandOptions ( boolean $includeBase = true ) : CommandOption[]
$includeBase boolean Whether to include options of the base format in the result.
Результат CommandOption[] The command options.

getNumberOfArguments() публичный Метод

Returns the number of arguments.
public getNumberOfArguments ( boolean $includeBase = true ) : integer
$includeBase boolean Whether to include arguments in the base format in the result.
Результат integer The number of arguments.

getNumberOfRequiredArguments() публичный Метод

Returns the number of required arguments.
public getNumberOfRequiredArguments ( boolean $includeBase = true ) : integer
$includeBase boolean Whether to include arguments in the base format in the result.
Результат integer The number of required arguments.

getOption() публичный Метод

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.
Результат Option The option.

getOptions() публичный Метод

Returns all options of the format.
public getOptions ( boolean $includeBase = true ) : Option[]
$includeBase boolean Whether to include options of the base format in the result.
Результат Option[] The options.

hasArgument() публичный Метод

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.
Результат boolean Returns `true` if the argument with the given name or position could be found and `false` otherwise.

hasArguments() публичный Метод

Returns whether the format contains any argument.
public hasArguments ( boolean $includeBase = true ) : boolean
$includeBase boolean Whether to include arguments in the base format in the search.
Результат boolean Returns `true` if the format contains any argument and `false` otherwise.

hasCommandNames() публичный Метод

Returns whether the format contains any command names.
public hasCommandNames ( boolean $includeBase = true ) : boolean
$includeBase boolean Whether to consider command names in the base format.
Результат boolean Returns `true` if the format contains command names and `false` otherwise.

hasCommandOption() публичный Метод

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 options in the base format in the search.
Результат boolean Returns `true` if the command option with the given name could be found and `false` otherwise.

hasCommandOptions() публичный Метод

Returns whether the format contains command options.
public hasCommandOptions ( boolean $includeBase = true ) : boolean
$includeBase boolean Whether to include options in the base format in the search.
Результат boolean Returns `true` if the format contains command options and `false` otherwise.

hasMultiValuedArgument() публичный Метод

Returns whether the format contains a multi-valued argument.
public hasMultiValuedArgument ( boolean $includeBase = true ) : boolean
$includeBase boolean Whether to include arguments in the base format in the search.
Результат boolean Returns `true` if the format contains a multi-valued argument and `false` otherwise.

hasOption() публичный Метод

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.
Результат boolean Returns `true` if the option with the given name could be found and `false` otherwise.

hasOptionalArgument() публичный Метод

Returns whether the format contains an optional argument.
public hasOptionalArgument ( boolean $includeBase = true ) : boolean
$includeBase boolean Whether to include arguments in the base format in the search.
Результат boolean Returns `true` if the format contains an optional argument and `false` otherwise.

hasOptions() публичный Метод

Returns whether the format contains options.
public hasOptions ( boolean $includeBase = true ) : boolean
$includeBase boolean Whether to include options in the base format in the search.
Результат boolean Returns `true` if the format contains options and `false` otherwise.

hasRequiredArgument() публичный Метод

Returns whether the format contains a required argument.
public hasRequiredArgument ( boolean $includeBase = true ) : boolean
$includeBase boolean Whether to include arguments in the base format in the search.
Результат boolean Returns `true` if the format contains a required argument and `false` otherwise.