FrameworkQuestion
class FrameworkQuestion
Supports questions through the command line interface.
Traits
Supports ability to validate console input.
Properties
| protected array | $errors | An array of errors. |
from HasValidators |
| protected string | $fieldName | The name of the field to be validated. |
from HasValidators |
| protected array | $reservedKeywords | An array of reserved keywords. |
from HasValidators |
| protected array | $validators | Array of validator callbacks. |
from HasValidators |
| protected bool | $anticipate | Flag that tracks if anticipate mode is on or off. |
|
| protected QuestionHelper | $helper | Instance of QuestionHelper class. |
|
| protected InputInterface | $input | InputInterface instance created when parent command is ran. |
|
| protected OutputInterface | $output | OutputInterface instance created when parent command is ran. |
|
| protected bool | $secret | Determines whether or not input is hidden. |
|
| protected int|null | $timeout | Timeout for prompt in seconds. |
|
| protected bool | $trimmable | Sets mode for trimmable. |
Methods
Adds a new error message to the $errors array.
Enforce rule where input must contain only alphabetic characters.
Enforce rule where input must be alphanumeric characters.
Ensures input is between within a certain range in length.
Checks if class exists within the specified namespace.
Enforce rule where response and $match parameter needs to be different.
Sets name of field to be validated.
Checks if a port on a particular host is in use. Assists in verifying if a port is available for a serve command. If the port is already in use an error message is presented to the user.
Ensure user inputs valid comma separated list of values. The user must provide the following in the $attributes parameter: 1) Class containing full namespaced path 2) Name of function that returns an array of strings or a comma separated array of strings.
Enforces rule when input must contain at least one lower case character.
Enforce rule where response and $match parameter needs to match.
Ensures input meets requirements for maximum allowable length.
Ensures input meets requirements for minimum allowable length.
Enforces rule when input must contain no special characters.
Enforce rule when reserved keywords should be avoided.
Enforces rule when input must contain at least one numeric character.
Enforce rule where input must contain only numeric characters.
Adds validator to array of validators to be used.
Enforces rule when input must contain at least one special character.
Split on commas (tolerate spaces), normalize to lowercase, drop empties.
Enforces rule when input must contain at least one lower case character.
Calls validator callbacks. This function also ensures validators don't bleed into next question if instance is reused.
Creates instance of FrameworkQuestion class.
Used to turn on anticipate mode.
Asks the user a question. This function supports secret input and autocomplete. An exception is thrown when both $secret and $anticipate are true.
Checks state of anticipate, secret, and trimmable modes. If used for for certain questions then the user is alerted before being given the chance to answer those questions.
Asks the user a question where there is a choice to be made.
Asks a user to confirm based on question asked.
Disables trimmable. Default value is false.
Helper function for asking a question.
Sets input as hidden.
Sets timeout for input.
Details
in
HasValidators at line 79
void
addErrorMessage(string $message)
Adds a new error message to the $errors array.
in
HasValidators at line 89
HasValidators
alpha()
Enforce rule where input must contain only alphabetic characters.
in
HasValidators at line 103
HasValidators
alphaNumeric()
Enforce rule where input must be alphanumeric characters.
in
HasValidators at line 121
HasValidators
between(array $range)
Ensures input is between within a certain range in length.
in
HasValidators at line 146
HasValidators
classExists(string|array $namespace)
Checks if class exists within the specified namespace.
in
HasValidators at line 161
HasValidators
colonNotation()
Ensures response is in colon notation format.
in
HasValidators at line 179
HasValidators
different(mixed $data)
Enforce rule where response and $match parameter needs to be different.
in
HasValidators at line 194
void
displayErrorMessages()
Displays a list of all error messages.
in
HasValidators at line 210
HasValidators
dotNotation()
Ensures response is in dot notation format.
in
HasValidators at line 227
HasValidators
email()
Ensures input is a valid E-mail address.
in
HasValidators at line 242
HasValidators
fieldName(string|array $fieldName)
Sets name of field to be validated.
in
HasValidators at line 253
HasValidators
ip()
Enforce rule where input must be a valid IP address.
in
HasValidators at line 267
HasValidators
integer()
Enforce rule where input must be an integer.
in
HasValidators at line 285
HasValidators
isPortUsed(array $attributes)
Checks if a port on a particular host is in use. Assists in verifying if a port is available for a serve command. If the port is already in use an error message is presented to the user.
in
HasValidators at line 314
HasValidators
list(array $attributes)
Ensure user inputs valid comma separated list of values. The user must provide the following in the $attributes parameter: 1) Class containing full namespaced path 2) Name of function that returns an array of strings or a comma separated array of strings.
3) A string value in this array as an alias (optional).
in
HasValidators at line 352
HasValidators
lower()
Enforces rule when input must contain at least one lower case character.
in
HasValidators at line 367
HasValidators
match(mixed $match)
Enforce rule where response and $match parameter needs to match.
in
HasValidators at line 382
HasValidators
max(int|array $maxRule)
Ensures input meets requirements for maximum allowable length.
in
HasValidators at line 398
HasValidators
min(int|array $minRule)
Ensures input meets requirements for minimum allowable length.
in
HasValidators at line 413
HasValidators
negative()
Enforces rule when input must be a negative number.
in
HasValidators at line 427
HasValidators
noSpecialChars()
Enforces rule when input must contain no special characters.
in
HasValidators at line 441
HasValidators
notReservedKeyword()
Enforce rule when reserved keywords should be avoided.
in
HasValidators at line 455
HasValidators
number()
Enforces rule when input must contain at least one numeric character.
in
HasValidators at line 469
HasValidators
numeric()
Enforce rule where input must contain only numeric characters.
in
HasValidators at line 483
HasValidators
required()
Ensures required input is entered.
in
HasValidators at line 496
HasValidators
positive()
Enforces rule when input must a positive number.
in
HasValidators at line 510
HasValidators
queue()
Validates if queue exists in database or redis.
in
HasValidators at line 534
HasValidators
setValidator(callable $validator)
Adds validator to array of validators to be used.
in
HasValidators at line 544
HasValidators
special()
Enforces rule when input must contain at least one special character.
in
HasValidators at line 558
HasValidators
testFilterNotation()
Ensures response is in colon notation format.
in
HasValidators at line 579
static protected array
tokens(string $data)
Split on commas (tolerate spaces), normalize to lowercase, drop empties.
Useful for cases where you have a comma separated string.
in
HasValidators at line 589
HasValidators
upper()
Enforces rule when input must contain at least one lower case character.
in
HasValidators at line 603
HasValidators
url()
Enforce rule where input must be a valid URL.
in
HasValidators at line 619
protected bool
validate(mixed $response)
Calls validator callbacks. This function also ensures validators don't bleed into next question if instance is reused.
at line 77
__construct(InputInterface $input, OutputInterface $output)
Creates instance of FrameworkQuestion class.
at line 90
FrameworkQuestion
anticipate(bool|array $anticipate = true)
Used to turn on anticipate mode.
at line 115
mixed
ask(string $message, array $suggestions = [], string|bool|int|float|null $default = null)
Asks the user a question. This function supports secret input and autocomplete. An exception is thrown when both $secret and $anticipate are true.
at line 164
protected void
checkModes()
Checks state of anticipate, secret, and trimmable modes. If used for for certain questions then the user is alerted before being given the chance to answer those questions.
at line 187
mixed
choice(string $message, array $choices, string|bool|int|float|null $default = null)
Asks the user a question where there is a choice to be made.
at line 209
mixed
confirm(string $message, string|bool|int|float|null $default = true)
Asks a user to confirm based on question asked.
at line 227
FrameworkQuestion
disableTrimmable(bool|array $trimmable = false)
Disables trimmable. Default value is false.
at line 239
protected mixed
promptUser(Question $question)
Helper function for asking a question.
at line 260
FrameworkQuestion
secret(bool|array $secret = true)
Sets input as hidden.
at line 273
FrameworkQuestion
timeout(mixed $timeout = null)
Sets timeout for input.