class ValidatePrompter extends CallbackPrompter (View source)

A text prompter but we can set an array to validate input value.

Methods

__construct(string $question = null, array $options = array(), $default = null, IOInterface $io = null)

Constructor.

string
ask(string $msg = '', string $default = null)

Show prompt to ask user.

string
in(string $question = null)

Get a value from standard input.

string
__invoke(string $msg = null, string $default = null)

Proxy to ask method.

getIO()

Method to get property Io

setIO(IOInterface $io)

Method to set property io

setHandler(callable $handler)

Set a callable handler, can be a Closure.

callable
getHandler()

Get callable handler.

setAttemptTimes(int $attempt)

Set attempt number.

setNoValidMessage(string $noValidMessage)

Set message when validate fail.

failToClose(boolean $failToClose = null, string $message = '')

If validate fail, whether close application or not.

addOption(string $description, string $option = null)

Add an option.

removeOption(mixed $key)

Remove an option by key.

setOptions(array $options)

Set option list.

Details

at line line 39
__construct(string $question = null, array $options = array(), $default = null, IOInterface $io = null)

Constructor.

Parameters

string $question The question you want to ask.
array $options The option list to validate input.
$default $default The default value.
IOInterface $io The input object.

string ask(string $msg = '', string $default = null)

Show prompt to ask user.

Parameters

string $msg Question.
string $default Default value.

Return Value

string The value that use input.

Exceptions

LogicException

string in(string $question = null)

Get a value from standard input.

Parameters

string $question The question you want to ask user.

Return Value

string The input string from standard input.

string __invoke(string $msg = null, string $default = null)

Proxy to ask method.

Parameters

string $msg Question.
string $default Default value.

Return Value

string The value that use input.

IOInterface getIO()

Method to get property Io

Return Value

IOInterface

AbstractPrompter setIO(IOInterface $io)

Method to set property io

Parameters

IOInterface $io

Return Value

AbstractPrompter Return self to support chaining.

ValidatePrompter setHandler(callable $handler)

Set a callable handler, can be a Closure.

This function should contain a param that is the value which from user input, and must return TRUE or FALSE means validate success or fail.

Parameters

callable $handler The validate callback.

Return Value

ValidatePrompter Return self to support chaining.

at line line 53
callable getHandler()

Get callable handler.

Return Value

callable The validate callback.

ValidatePrompter setAttemptTimes(int $attempt)

Set attempt number.

Parameters

int $attempt Retry times.

Return Value

ValidatePrompter Return self to support chaining.

ValidatePrompter setNoValidMessage(string $noValidMessage)

Set message when validate fail.

Parameters

string $noValidMessage Validate fail message.

Return Value

ValidatePrompter Return self to support chaining.

ValidatePrompter failToClose(boolean $failToClose = null, string $message = '')

If validate fail, whether close application or not.

Parameters

boolean $failToClose TRUE or FALSE, if is NULL, will be getter of $failToClose property.
string $message Message when close.

Return Value

ValidatePrompter Return self to support chaining.

at line line 83
ValidatePrompter addOption(string $description, string $option = null)

Add an option.

Parameters

string $description Option description.
string $option Option key, if this param is NULL, will use int as option key.

Return Value

ValidatePrompter Return self to support chaining.

at line line 106
ValidatePrompter removeOption(mixed $key)

Remove an option by key.

Parameters

mixed $key The option key you want to remove.

Return Value

ValidatePrompter Return self to support chaining.

at line line 125
ValidatePrompter setOptions(array $options)

Set option list.

Parameters

array $options The option list.

Return Value

ValidatePrompter Return self to support chaining.