PHP Class Webmozart\Console\Api\Config\Config

Since: 1.0
Author: Bernhard Schussek ([email protected])
Show file Open project: webmozart/console Class Usage Examples

Public Methods

Method Description
__construct ( ) Creates a new configuration.
addArgument ( string $name, integer $flags, string $description = null, mixed $default = null ) : ApplicationConfig | CommandConfig | SubCommandConfig | OptionCommandConfig Adds an argument.
addOption ( string $longName, string $shortName = null, integer $flags, string $description = null, mixed $default = null, string $valueName = '...' ) : ApplicationConfig | CommandConfig | SubCommandConfig | OptionCommandConfig Adds an option.
disableLenientArgsParsing ( ) : ApplicationConfig | CommandConfig | SubCommandConfig | OptionCommandConfig Disables lenient argument parsing.
enableLenientArgsParsing ( ) : ApplicationConfig | CommandConfig | SubCommandConfig | OptionCommandConfig Enables lenient argument parsing.
getArgsParser ( ) : Webmozart\Console\Api\Args\ArgsParser Returns the configured argument parser.
getArguments ( ) : Argument[] Returns the configured arguments.
getHandler ( ) : object Returns the command handler to execute when a command is run.
getHandlerMethod ( ) : string Returns the method of the command handler that should be executed when the configured command is run.
getHelperSet ( ) : Symfony\Component\Console\Helper\HelperSet Returns the configured helper set.
getOptions ( ) : Option[] Returns the configured options.
isLenientArgsParsingEnabled ( ) : boolean Returns whether lenient argument parsing is enabled.
setArgsParser ( Webmozart\Console\Api\Args\ArgsParser $argsParser ) : ApplicationConfig | CommandConfig | SubCommandConfig | OptionCommandConfig Sets the used argument parser.
setHandler ( object | callback $handler ) : ApplicationConfig | CommandConfig | SubCommandConfig | OptionCommandConfig Sets the command handler to execute when a command is run.
setHandlerMethod ( string $handlerMethod ) : ApplicationConfig | CommandConfig | SubCommandConfig | OptionCommandConfig Sets the method of the command handler that should be executed when the configured command is run.
setHelperSet ( Symfony\Component\Console\Helper\HelperSet $helperSet ) : ApplicationConfig | CommandConfig | SubCommandConfig | OptionCommandConfig Sets the used helper set.

Protected Methods

Method Description
configure ( ) Adds the default configuration.
getDefaultArgsParser ( ) : Webmozart\Console\Api\Args\ArgsParser Returns the arguments parser to use if none is set.
getDefaultHandler ( ) : object Returns the command handler to use if none is set.
getDefaultHandlerMethod ( ) : string Returns the handler method to use if none is set.
getDefaultHelperSet ( ) : Symfony\Component\Console\Helper\HelperSet Returns the helper set to use if none is set.
getDefaultLenientArgsParsing ( ) : boolean Returns whether the arguments parsing handles errors gracefully.

Method Details

__construct() public method

Creates a new configuration.
public __construct ( )

addArgument() public method

Read {@link Argument} for a more detailed description of console arguments.
See also: getArguments()
public addArgument ( string $name, integer $flags, string $description = null, mixed $default = null ) : ApplicationConfig | CommandConfig | SubCommandConfig | OptionCommandConfig
$name string The argument name.
$flags integer A bitwise combination of the flag constants in the {@link Argument} class.
$description string A one-line description of the argument.
$default mixed The default value. Must be `null` if the flags contain {@link Argument::REQUIRED}.
return ApplicationConfig | CommandConfig | SubCommandConfig | OptionCommandConfig The current instance.

addOption() public method

Read {@link Option} for a more detailed description of console options.
See also: getOptions()
public addOption ( string $longName, string $shortName = null, integer $flags, string $description = null, mixed $default = null, string $valueName = '...' ) : ApplicationConfig | CommandConfig | SubCommandConfig | OptionCommandConfig
$longName string The long option name.
$shortName string The short option name. Can be `null`.
$flags integer A bitwise combination of the flag constants in the {@link Option} class.
$description string A one-line description of the option.
$default mixed The default value. Must be `null` if the flags contain {@link Option::REQUIRED_VALUE}.
$valueName string The name of the value to be used in usage examples of the option.
return ApplicationConfig | CommandConfig | SubCommandConfig | OptionCommandConfig The current instance.

configure() protected method

Override this method in your own subclasses.
protected configure ( )

disableLenientArgsParsing() public method

When lenient argument parsing is enabled, the argument parser will not fail if the console arguments contain invalid or missing arguments. Lenient argument parsing is disabled by default.
See also: enableLenientArgsParsing()
public disableLenientArgsParsing ( ) : ApplicationConfig | CommandConfig | SubCommandConfig | OptionCommandConfig
return ApplicationConfig | CommandConfig | SubCommandConfig | OptionCommandConfig The current instance.

enableLenientArgsParsing() public method

When lenient argument parsing is enabled, the argument parser will not fail if the console arguments contain invalid or missing arguments. Lenient argument parsing is disabled by default.
See also: disableLenientArgsParsing()
public enableLenientArgsParsing ( ) : ApplicationConfig | CommandConfig | SubCommandConfig | OptionCommandConfig
return ApplicationConfig | CommandConfig | SubCommandConfig | OptionCommandConfig The current instance.

getArgsParser() public method

Returns the configured argument parser.
See also: setArgsParser()
public getArgsParser ( ) : Webmozart\Console\Api\Args\ArgsParser
return Webmozart\Console\Api\Args\ArgsParser The argument parser.

getArguments() public method

Read {@link Argument} for a more detailed description of arguments.
See also: addArgument()
public getArguments ( ) : Argument[]
return Webmozart\Console\Api\Args\Format\Argument[] The configured arguments.

getDefaultArgsParser() protected method

Returns the arguments parser to use if none is set.
protected getDefaultArgsParser ( ) : Webmozart\Console\Api\Args\ArgsParser
return Webmozart\Console\Api\Args\ArgsParser The default args parser.

getDefaultHandler() protected method

Returns the command handler to use if none is set.
protected getDefaultHandler ( ) : object
return object The default command handler.

getDefaultHandlerMethod() protected method

Returns the handler method to use if none is set.
protected getDefaultHandlerMethod ( ) : string
return string The default handler method.

getDefaultHelperSet() protected method

Returns the helper set to use if none is set.
protected getDefaultHelperSet ( ) : Symfony\Component\Console\Helper\HelperSet
return Symfony\Component\Console\Helper\HelperSet The default helper set.

getDefaultLenientArgsParsing() protected method

Returns whether the arguments parsing handles errors gracefully.
protected getDefaultLenientArgsParsing ( ) : boolean
return boolean The default value for lenient args parsing.

getHandler() public method

Returns the command handler to execute when a command is run.
See also: setHandler()
public getHandler ( ) : object
return object The command handler.

getHandlerMethod() public method

Returns the method of the command handler that should be executed when the configured command is run.
See also: setHandlerMethod()
public getHandlerMethod ( ) : string
return string The method name.

getHelperSet() public method

Returns the configured helper set.
See also: setHelperSet()
public getHelperSet ( ) : Symfony\Component\Console\Helper\HelperSet
return Symfony\Component\Console\Helper\HelperSet The helper set.

getOptions() public method

Read {@link Option} for a more detailed description of console options.
See also: addOption()
public getOptions ( ) : Option[]
return Webmozart\Console\Api\Args\Format\Option[] The configured options.

isLenientArgsParsingEnabled() public method

When lenient argument parsing is enabled, the argument parser will not fail if the console arguments contain invalid or missing arguments.
public isLenientArgsParsingEnabled ( ) : boolean
return boolean Returns `true` if lenient parsing is enabled and `false` otherwise.

setArgsParser() public method

Sets the used argument parser.
See also: getArgsParser()
public setArgsParser ( Webmozart\Console\Api\Args\ArgsParser $argsParser ) : ApplicationConfig | CommandConfig | SubCommandConfig | OptionCommandConfig
$argsParser Webmozart\Console\Api\Args\ArgsParser The argument parser.
return ApplicationConfig | CommandConfig | SubCommandConfig | OptionCommandConfig The current instance.

setHandler() public method

You can pass: * An object with handler methods. * A callable that receives a {@link Command} and returns an object with handler methods. The name of the executed handler method can be configured with {@link setHandlerMethod()}. By default, the method handle() is executed.
See also: getHandler()
public setHandler ( object | callback $handler ) : ApplicationConfig | CommandConfig | SubCommandConfig | OptionCommandConfig
$handler object | callback The command handler or the callable creating a new command handler on demand.
return ApplicationConfig | CommandConfig | SubCommandConfig | OptionCommandConfig The current instance.

setHandlerMethod() public method

The method receives three arguments: * {@link Args} $args: The console arguments. * {@link IO} $io: The I/O. * {@link Command} $command: The executed command.
See also: getHandlerMethod()
public setHandlerMethod ( string $handlerMethod ) : ApplicationConfig | CommandConfig | SubCommandConfig | OptionCommandConfig
$handlerMethod string The method name.
return ApplicationConfig | CommandConfig | SubCommandConfig | OptionCommandConfig The current instance.

setHelperSet() public method

Sets the used helper set.
See also: getHelperSet()
public setHelperSet ( Symfony\Component\Console\Helper\HelperSet $helperSet ) : ApplicationConfig | CommandConfig | SubCommandConfig | OptionCommandConfig
$helperSet Symfony\Component\Console\Helper\HelperSet The helper set.
return ApplicationConfig | CommandConfig | SubCommandConfig | OptionCommandConfig The current instance.