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

void
addErrorMessage(string $message)

Adds a new error message to the $errors array.

alpha()

Enforce rule where input must contain only alphabetic characters.

alphaNumeric()

Enforce rule where input must be alphanumeric characters.

between(array $range)

Ensures input is between within a certain range in length.

classExists(string|array $namespace)

Checks if class exists within the specified namespace.

colonNotation()

Ensures response is in colon notation format.

void
compositeFieldValidation(array|string $additionalFieldData, array $conditions, array $bind)

Tests form validation with multiple fields. Used by the unique validator to test several fields for uniqueness.

different(mixed $data)

Enforce rule where response and $match parameter needs to be different.

void
displayErrorMessages()

Displays a list of all error messages.

dotNotation()

Ensures response is in dot notation format.

email()

Ensures input is a valid E-mail address.

fieldName(string|array $fieldName)

Sets name of field to be validated.

void
includeDeleted(bool|string $includeDeleted, array $queryParams)

Supports includeDeleted feature for database operations.

integer()

Enforce rule where input must be an integer.

ip()

Enforce rule where input must be a valid IP address.

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.

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.

lower()

Enforces rule when input must contain at least one lower case character.

match(mixed $match)

Enforce rule where response and $match parameter needs to match.

max(int|array $maxRule)

Ensures input meets requirements for maximum allowable length.

min(int|array $minRule)

Ensures input meets requirements for minimum allowable length.

negative()

Enforces rule when input must be a negative number.

noSpecialChars()

Enforces rule when input must contain no special characters.

notReservedKeyword()

Enforce rule when reserved keywords should be avoided.

number()

Enforces rule when input must contain at least one numeric character.

numeric()

Enforce rule where input must contain only numeric characters.

static void
parseAttributes(object $object, array $validators)

Parse array containing additional validators or attributes for FrameworkQuestion as strings along with any additional parameters that maybe expected.

required()

Ensures required input is entered.

void
resetAfterValidation()

Resets fieldname and validators instance variables so duplicate messages are not displayed in forms.

positive()

Enforces rule when input must a positive number.

queue()

Validates if queue exists in database or redis.

setValidator(callable $validator)

Adds validator to array of validators to be used.

special()

Enforces rule when input must contain at least one special character.

tel()

Enforces rule where input must be a valid phone number.

testFilterNotation()

Ensures response is in colon notation format.

static array
tokens(string $data)

Split on commas (tolerate spaces), normalize to lowercase, drop empties.

unique(array $attributes)

Checks if value already exists in a database.

upper()

Enforces rule when input must contain at least one lower case character.

url()

Enforce rule where input must be a valid URL.

bool
validate(mixed $response)

Calls validator callbacks. This function also ensures validators don't bleed into next question if instance is reused.

__construct(InputInterface $input, OutputInterface $output)

Creates instance of FrameworkQuestion class.

anticipate(bool|array $anticipate = true)

Used to turn on anticipate mode.

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.

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.

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.

mixed
confirm(string $message, string|bool|int|float|null $default = true)

Asks a user to confirm based on question asked.

disableTrimmable(bool|array $trimmable = false)

Disables trimmable. Default value is false.

mixed
promptUser(Question $question)

Helper function for asking a question.

secret(bool|array $secret = true)

Sets input as hidden.

timeout(mixed $timeout = null)

Sets timeout for input.

Details

in HasValidators at line 82
void addErrorMessage(string $message)

Adds a new error message to the $errors array.

Parameters

string $message

The error message to be added to the $errors array.

Return Value

void

in HasValidators at line 92
HasValidators alpha()

Enforce rule where input must contain only alphabetic characters.

Return Value

HasValidators

in HasValidators at line 106
HasValidators alphaNumeric()

Enforce rule where input must be alphanumeric characters.

Return Value

HasValidators

in HasValidators at line 124
HasValidators between(array $range)

Ensures input is between within a certain range in length.

Parameters

array $range

2 element array where position 0 is min and position 1 is max.

Return Value

HasValidators

Exceptions

FrameworkRuntimeException

in HasValidators at line 149
HasValidators classExists(string|array $namespace)

Checks if class exists within the specified namespace.

Parameters

string|array $namespace

A string or an array containing one element with string for the namespace.

Return Value

HasValidators

in HasValidators at line 164
HasValidators colonNotation()

Ensures response is in colon notation format.

Return Value

HasValidators

in HasValidators at line 186
void compositeFieldValidation(array|string $additionalFieldData, array $conditions, array $bind)

Tests form validation with multiple fields. Used by the unique validator to test several fields for uniqueness.

Parameters

array|string $additionalFieldData

Additional fields and values to test.

array $conditions

The conditions array passed by reference.

array $bind

The binds array passed by reference.

Return Value

void

in HasValidators at line 209
HasValidators different(mixed $data)

Enforce rule where response and $match parameter needs to be different.

Parameters

mixed $data

The value we want to compare.

Return Value

HasValidators

in HasValidators at line 224
void displayErrorMessages()

Displays a list of all error messages.

Return Value

void

in HasValidators at line 240
HasValidators dotNotation()

Ensures response is in dot notation format.

Return Value

HasValidators

in HasValidators at line 257
HasValidators email()

Ensures input is a valid E-mail address.

Return Value

HasValidators

in HasValidators at line 272
HasValidators fieldName(string|array $fieldName)

Sets name of field to be validated.

Parameters

string|array $fieldName

The name of the field to be validated.

Return Value

HasValidators

in HasValidators at line 288
void includeDeleted(bool|string $includeDeleted, array $queryParams)

Supports includeDeleted feature for database operations.

Parameters

bool|string $includeDeleted

The includedDeleted flag. When true the 'includeDeleted' element with a value of true is added to the $queryParams associative array.

array $queryParams

The parameters for the query that is passed by reference.

Return Value

void

in HasValidators at line 299
HasValidators integer()

Enforce rule where input must be an integer.

Return Value

HasValidators

in HasValidators at line 313
HasValidators ip()

Enforce rule where input must be a valid IP address.

Return Value

HasValidators

in HasValidators at line 331
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.

Parameters

array $attributes

An array that assumes index 0 is the host and index 1 is timeout variable which is set to 3 if not provided.

Return Value

HasValidators

in HasValidators at line 360
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).

Parameters

array $attributes

A : separate list in the following format: NamespaceToClass\Class:Method:Alias.

Return Value

HasValidators

in HasValidators at line 398
HasValidators lower()

Enforces rule when input must contain at least one lower case character.

Return Value

HasValidators

in HasValidators at line 413
HasValidators match(mixed $match)

Enforce rule where response and $match parameter needs to match.

Parameters

mixed $match

The value we want to compare.

Return Value

HasValidators

in HasValidators at line 428
HasValidators max(int|array $maxRule)

Ensures input meets requirements for maximum allowable length.

Parameters

int|array $maxRule

The maximum allowed size for input.

Return Value

HasValidators

in HasValidators at line 444
HasValidators min(int|array $minRule)

Ensures input meets requirements for minimum allowable length.

Parameters

int|array $minRule

The minimum allowed size for input.

Return Value

HasValidators

in HasValidators at line 459
HasValidators negative()

Enforces rule when input must be a negative number.

Return Value

HasValidators

in HasValidators at line 473
HasValidators noSpecialChars()

Enforces rule when input must contain no special characters.

Return Value

HasValidators

in HasValidators at line 487
HasValidators notReservedKeyword()

Enforce rule when reserved keywords should be avoided.

Return Value

HasValidators

in HasValidators at line 501
HasValidators number()

Enforces rule when input must contain at least one numeric character.

Return Value

HasValidators

in HasValidators at line 515
HasValidators numeric()

Enforce rule where input must contain only numeric characters.

Return Value

HasValidators

in HasValidators at line 537
static protected void parseAttributes(object $object, array $validators)

Parse array containing additional validators or attributes for FrameworkQuestion as strings along with any additional parameters that maybe expected.

Parameters

object $object

The instance of a class using the HasValidators trait.

array $validators

An array of validators. Any additional parameters must be separated with a ":".

Return Value

void

Exceptions

FrameworkException

in HasValidators at line 558
HasValidators required()

Ensures required input is entered.

Return Value

HasValidators

in HasValidators at line 572
protected void resetAfterValidation()

Resets fieldname and validators instance variables so duplicate messages are not displayed in forms.

Return Value

void

in HasValidators at line 582
HasValidators positive()

Enforces rule when input must a positive number.

Return Value

HasValidators

in HasValidators at line 596
HasValidators queue()

Validates if queue exists in database or redis.

Return Value

HasValidators

in HasValidators at line 621
HasValidators setValidator(callable $validator)

Adds validator to array of validators to be used.

Parameters

callable $validator

The anonymous function for a validator.

Return Value

HasValidators

in HasValidators at line 631
HasValidators special()

Enforces rule when input must contain at least one special character.

Return Value

HasValidators

in HasValidators at line 645
HasValidators tel()

Enforces rule where input must be a valid phone number.

Return Value

HasValidators

in HasValidators at line 669
HasValidators testFilterNotation()

Ensures response is in colon notation format.

Return Value

HasValidators

in HasValidators at line 690
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.

Parameters

string $data

Comma separated strings of values to be converted into an array.

Return Value

array

An array containing values originally found in comma separated string.

in HasValidators at line 703
HasValidators unique(array $attributes)

Checks if value already exists in a database.

Parameters

array $attributes

The model, includeDeleted flag, and list of additional fields.

Return Value

HasValidators

in HasValidators at line 747
HasValidators upper()

Enforces rule when input must contain at least one lower case character.

Return Value

HasValidators

in HasValidators at line 761
HasValidators url()

Enforce rule where input must be a valid URL.

Return Value

HasValidators

in HasValidators at line 777
protected bool validate(mixed $response)

Calls validator callbacks. This function also ensures validators don't bleed into next question if instance is reused.

Parameters

mixed $response

The user answer.

Return Value

bool

True if validation passed. Otherwise, we return false.

at line 77
__construct(InputInterface $input, OutputInterface $output)

Creates instance of FrameworkQuestion class.

Parameters

InputInterface $input

The Symfony InputInterface object.

OutputInterface $output

The Symfony OutputInterface object.

at line 90
FrameworkQuestion anticipate(bool|array $anticipate = true)

Used to turn on anticipate mode.

Parameters

bool|array $anticipate

Anticipate mode is turned on when true is passed. Otherwise, it is disabled. Default value is true.

Return Value

FrameworkQuestion

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.

Parameters

string $message

The question to ask.

array $suggestions

An array of suggestions for when $anticipate is set to true. An exception is thrown if this array is empty and $anticipate = true.

string|bool|int|float|null $default

The default value if the user does not provide an answer.

Return Value

mixed

The user answer.

Exceptions

FrameworkException

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.

Return Value

void

Exceptions

FrameworkRuntimeException

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.

Parameters

string $message

The question to ask.

array $choices

An array of choices.

string|bool|int|float|null $default

The default value if the user does not provide an answer.

Return Value

mixed

The user answer.

at line 209
mixed confirm(string $message, string|bool|int|float|null $default = true)

Asks a user to confirm based on question asked.

Parameters

string $message

The question to ask. It is advised to phrase it such that the user knows to answer y or n.

string|bool|int|float|null $default

The default value if the user does not provide an answer.

Return Value

mixed

The user answer.

at line 227
FrameworkQuestion disableTrimmable(bool|array $trimmable = false)

Disables trimmable. Default value is false.

Parameters

bool|array $trimmable

Disables trimmable if false is provided. Otherwise, trimmable is set to true.

Return Value

FrameworkQuestion

at line 239
protected mixed promptUser(Question $question)

Helper function for asking a question.

Parameters

Question $question

Represents a question.

Return Value

mixed

The user answer.

at line 260
FrameworkQuestion secret(bool|array $secret = true)

Sets input as hidden.

Parameters

bool|array $secret

Default value is true. When true is passed then input is hidden. Otherwise, output is not hidden.

Return Value

FrameworkQuestion

at line 273
FrameworkQuestion timeout(mixed $timeout = null)

Sets timeout for input.

Parameters

mixed $timeout

The time in seconds before prompt timeout. Default value is null.

Return Value

FrameworkQuestion