class CallbackPrompter extends AbstractPrompter (View source)

Callback validate prompter.

It supports custom callback to validate use input and retry if fail.

Methods

__construct(string $question = null, callable $handler = null, $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.

Details

at line line 77
__construct(string $question = null, callable $handler = null, $default = null, IOInterface $io = null)

Constructor.

Parameters

string $question The question you want to ask.
callable $handler The callback handler.
$default $default The default value.
IOInterface $io The input object.

at line line 99
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.

at line line 144
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 158
callable getHandler()

Get callable handler.

Return Value

callable The validate callback.

at line line 172
ValidatePrompter setAttemptTimes(int $attempt)

Set attempt number.

Parameters

int $attempt Retry times.

Return Value

ValidatePrompter Return self to support chaining.

at line line 188
ValidatePrompter setNoValidMessage(string $noValidMessage)

Set message when validate fail.

Parameters

string $noValidMessage Validate fail message.

Return Value

ValidatePrompter Return self to support chaining.

at line line 205
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.