CommandHelper
class CommandHelper extends Console
Supports commands related to building console commands and associated helper classes.
Traits
Supports ability to validate console input.
Constants
| private COMMAND_PATH |
The path for user defined command classes. |
| private HELPER_PATH |
The path for user defined command helper classes. |
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 |
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.
Tests form validation with multiple fields. Used by the unique validator to test several fields for uniqueness.
Enforce rule where response and $match parameter needs to be different.
Sets name of field to be validated.
Supports includeDeleted feature for database operations.
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.
Parse array containing additional validators or attributes for FrameworkQuestion as strings along with any additional parameters that maybe expected.
Resets fieldname and validators instance variables so duplicate messages are not displayed in forms.
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.
Checks if value already exists in a database.
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.
Validates argument and option input. If validation fails then the user is asked to enter a new value.
Ask user to confirm among several options based on question asked.
Asks a user to confirm based on question asked.
Returns instance of this or child helper class.
Asks user question about file to be created.
Generates new class that extends Command.
Generates new class that contains functions that support multiple console commands.
Details
in
HasValidators at line 82
void
addErrorMessage(string $message)
Adds a new error message to the $errors array.
in
HasValidators at line 92
HasValidators
alpha()
Enforce rule where input must contain only alphabetic characters.
in
HasValidators at line 106
HasValidators
alphaNumeric()
Enforce rule where input must be alphanumeric characters.
in
HasValidators at line 124
HasValidators
between(array $range)
Ensures input is between within a certain range in length.
in
HasValidators at line 149
HasValidators
classExists(string|array $namespace)
Checks if class exists within the specified namespace.
in
HasValidators at line 164
HasValidators
colonNotation()
Ensures response is in colon notation format.
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.
in
HasValidators at line 209
HasValidators
different(mixed $data)
Enforce rule where response and $match parameter needs to be different.
in
HasValidators at line 224
void
displayErrorMessages()
Displays a list of all error messages.
in
HasValidators at line 240
HasValidators
dotNotation()
Ensures response is in dot notation format.
in
HasValidators at line 257
HasValidators
email()
Ensures input is a valid E-mail address.
in
HasValidators at line 272
HasValidators
fieldName(string|array $fieldName)
Sets name of field to be validated.
in
HasValidators at line 288
void
includeDeleted(bool|string $includeDeleted, array $queryParams)
Supports includeDeleted feature for database operations.
in
HasValidators at line 299
HasValidators
integer()
Enforce rule where input must be an integer.
in
HasValidators at line 313
HasValidators
ip()
Enforce rule where input must be a valid IP address.
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.
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).
in
HasValidators at line 398
HasValidators
lower()
Enforces rule when input must contain at least one lower case character.
in
HasValidators at line 413
HasValidators
match(mixed $match)
Enforce rule where response and $match parameter needs to match.
in
HasValidators at line 428
HasValidators
max(int|array $maxRule)
Ensures input meets requirements for maximum allowable length.
in
HasValidators at line 444
HasValidators
min(int|array $minRule)
Ensures input meets requirements for minimum allowable length.
in
HasValidators at line 459
HasValidators
negative()
Enforces rule when input must be a negative number.
in
HasValidators at line 473
HasValidators
noSpecialChars()
Enforces rule when input must contain no special characters.
in
HasValidators at line 487
HasValidators
notReservedKeyword()
Enforce rule when reserved keywords should be avoided.
in
HasValidators at line 501
HasValidators
number()
Enforces rule when input must contain at least one numeric character.
in
HasValidators at line 515
HasValidators
numeric()
Enforce rule where input must contain only numeric characters.
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.
in
HasValidators at line 558
HasValidators
required()
Ensures required input is entered.
in
HasValidators at line 572
protected void
resetAfterValidation()
Resets fieldname and validators instance variables so duplicate messages are not displayed in forms.
in
HasValidators at line 582
HasValidators
positive()
Enforces rule when input must a positive number.
in
HasValidators at line 596
HasValidators
queue()
Validates if queue exists in database or redis.
in
HasValidators at line 621
HasValidators
setValidator(callable $validator)
Adds validator to array of validators to be used.
in
HasValidators at line 631
HasValidators
special()
Enforces rule when input must contain at least one special character.
in
HasValidators at line 645
HasValidators
tel()
Enforces rule where input must be a valid phone number.
in
HasValidators at line 669
HasValidators
testFilterNotation()
Ensures response is in colon notation format.
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.
in
HasValidators at line 703
HasValidators
unique(array $attributes)
Checks if value already exists in a database.
in
HasValidators at line 747
HasValidators
upper()
Enforces rule when input must contain at least one lower case character.
in
HasValidators at line 761
HasValidators
url()
Enforce rule where input must be a valid URL.
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.
in
Console at line 19
__construct(string $fieldName = "")
Creates new instance of Console class.
in
Console at line 41
static void
argOptionValidate(string $field, string $message, FrameworkQuestion $question, array $validators = [], bool $defaultNone = false)
Validates argument and option input. If validation fails then the user is asked to enter a new value.
Validates the following conditions: 1) required 2) noSpecialChars 3) alpha 4) notReservedKeyword
in
Console at line 74
static mixed
choice(string $message, array $choices, FrameworkQuestion $question, string|bool|int|float|null $default = null)
Ask user to confirm among several options based on question asked.
in
Console at line 92
static mixed
confirm(string $message, FrameworkQuestion $question, string|bool|int|float|null $default = true)
Asks a user to confirm based on question asked.
in
Console at line 106
static Console
getInstance(string $fieldName = "")
Returns instance of this or child helper class.
in
Console at line 131
static string
prompt(string $message, FrameworkQuestion $question, array $attributes = [], array $suggestions = [], string|bool|int|float|null $default = null, bool $defaultNone = false)
Asks user question about file to be created.
Validates the following conditions: 1) required 2) noSpecialChars 3) alpha 4) notReservedKeyword
at line 29
static int
makeCommand(string $commandName)
Generates new class that extends Command.
at line 42
static int
makeHelper(string $helperName)
Generates new class that contains functions that support multiple console commands.