class MigrationBuilder extends Console

Helper class for generating migration classes.

Traits

Supports ability to validate console input.

Constants

MIGRATION_PROMPT

The message to present to user when name of migration is being asked.

PROMPT_ATTRIBUTES

Array of validators common for the make:migration command.

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 $reservedSQLKeyWords from  HasValidators
protected array $validators

Array of validator callbacks.

from  HasValidators

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.

notReservedSQLKeyword()

Enforce rule when reserved SQL 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.

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(string $fieldName = "")

Creates new instance of Console class.

from  Console
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.

from  Console
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.

from  Console
static mixed
confirm(string $message, FrameworkQuestion $question, string|bool|int|float|null $default = true)

Asks a user to confirm based on question asked.

from  Console
static Console
getInstance(string $fieldName = "")

Returns instance of this or child helper class.

from  Console
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.

from  Console
static int
contents(string $migrationName, mixed $renameOption, mixed $updateOption, FrameworkQuestion $question)

Generates new migration class if table-name argument is provided. If rename or update flags are set then appropriate migration class is created.

static string
fileNameTime()

Generates time stamp for migrations in following format: yyyymmddhhmmss.

static int
generateACLTableMigration()

Generates migration for acl table.

static int
generateAllMigrations()

Generates all migrations.

static int
generateEmailAttachmentsTableMigration()

Generates migration for email_attachments table.

static int
generateMigrationByName(InputInterface $input)

Generates migration by name.

static int
generateMigrationsTableMigration()

Generates migration for migration table.

static int
generateProfileImagesTableMigration()

Generates migration for profile_images table.

static int
generateUserSessionsTableMigration()

Generates migration for user_sessions table.

static int
generateUsersTableMigration()

Generates migration for users table.

static bool
isBothFlagsSet(mixed $renameOption, mixed $updateOption)

Determines if both rename and update flags are set. If they are both set then a message is displayed and true is returned.

static int
makeMigration(string $migrationName)

Generates a migration class for creating a new table.

static int
makeRenameMigration(string $migrationName, mixed $renameOption)

Generates a migration class for renaming an existing table.

static int
makeUpdateMigration(string $migrationName)

Generates a migration class for updating existing table.

static string
migrationNamePrompt(FrameworkQuestion $question)

Handles question for which table a new migration will target.

static int
migrationTypePrompt(FrameworkQuestion $question, string $migrationName)

Prompts user for input when no argument and no options are set.

static array
modifiedAttributes(array $attributes)

Returns modified version of MigrationBuilder::PROMPT_ATTRIBUTES array.

static int
renameChoice(string $migrationName, FrameworkQuestion $question)

Prompts user to enter name for table to be renamed. Used when user responds with the choice to rename.

static int
renamePrompt(FrameworkQuestion $question, mixed $renameOption)

Prompts user to enter name of table to be updated. Used when user provides name of controller as an argument.

static array
setFlags(InputInterface $input)

Generates an array containing values for rename and update flags.

static string
validateRenameOption(string $to, string $from, FrameworkQuestion $question)

Validate rename option value. If validation fails the user is asked to resolve the issue.

Details

in HasValidators at line 127
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 137
HasValidators alpha()

Enforce rule where input must contain only alphabetic characters.

Return Value

HasValidators

in HasValidators at line 151
HasValidators alphaNumeric()

Enforce rule where input must be alphanumeric characters.

Return Value

HasValidators

in HasValidators at line 169
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 194
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 209
HasValidators colonNotation()

Ensures response is in colon notation format.

Return Value

HasValidators

in HasValidators at line 231
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 254
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 269
void displayErrorMessages()

Displays a list of all error messages.

Return Value

void

in HasValidators at line 285
HasValidators dotNotation()

Ensures response is in dot notation format.

Return Value

HasValidators

in HasValidators at line 302
HasValidators email()

Ensures input is a valid E-mail address.

Return Value

HasValidators

in HasValidators at line 317
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 333
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 344
HasValidators integer()

Enforce rule where input must be an integer.

Return Value

HasValidators

in HasValidators at line 358
HasValidators ip()

Enforce rule where input must be a valid IP address.

Return Value

HasValidators

in HasValidators at line 376
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 405
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 443
HasValidators lower()

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

Return Value

HasValidators

in HasValidators at line 458
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 474
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 490
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 505
HasValidators negative()

Enforces rule when input must be a negative number.

Return Value

HasValidators

in HasValidators at line 519
HasValidators noSpecialChars()

Enforces rule when input must contain no special characters.

Return Value

HasValidators

in HasValidators at line 533
HasValidators notReservedKeyword()

Enforce rule when reserved keywords should be avoided.

Return Value

HasValidators

in HasValidators at line 547
HasValidators notReservedSQLKeyword()

Enforce rule when reserved SQL keywords should be avoided.

Return Value

HasValidators

in HasValidators at line 561
HasValidators number()

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

Return Value

HasValidators

in HasValidators at line 575
HasValidators numeric()

Enforce rule where input must contain only numeric characters.

Return Value

HasValidators

in HasValidators at line 597
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 618
HasValidators required()

Ensures required input is entered.

Return Value

HasValidators

in HasValidators at line 631
HasValidators positive()

Enforces rule when input must a positive number.

Return Value

HasValidators

in HasValidators at line 645
HasValidators queue()

Validates if queue exists in database or redis.

Return Value

HasValidators

in HasValidators at line 670
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 680
HasValidators special()

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

Return Value

HasValidators

in HasValidators at line 694
HasValidators tel()

Enforces rule where input must be a valid phone number.

Return Value

HasValidators

in HasValidators at line 718
HasValidators testFilterNotation()

Ensures response is in colon notation format.

Return Value

HasValidators

in HasValidators at line 739
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 752
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 796
HasValidators upper()

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

Return Value

HasValidators

in HasValidators at line 810
HasValidators url()

Enforce rule where input must be a valid URL.

Return Value

HasValidators

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

in Console at line 19
__construct(string $fieldName = "")

Creates new instance of Console class.

Parameters

string $fieldName

The name of the field to be validated.

in Console at line 42
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

Parameters

string $field

The reference to the value to be validated.

string $message

The message to present to the user.

FrameworkQuestion $question

Instance of FrameworkQuestion class.

array $validators

An array of additional validators.

bool $defaultNone

When set to true user will have to specify all validators. Default value is false. When false the validators you supply are appended to list of default validators.

Return Value

void

in Console at line 75
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.

Parameters

string $message

The message to present to the user.

array $choices

An array of choices.

FrameworkQuestion $question

Instance of FrameworkQuestion class.

string|bool|int|float|null $default

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

Return Value

mixed

The user answer.

in Console at line 93
static mixed confirm(string $message, FrameworkQuestion $question, string|bool|int|float|null $default = true)

Asks a user to confirm based on question asked.

Parameters

string $message

The message to present to the user.

FrameworkQuestion $question

Instance of FrameworkQuestion class.

string|bool|int|float|null $default

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

Return Value

mixed

The user answer.

in Console at line 107
static Console getInstance(string $fieldName = "")

Returns instance of this or child helper class.

Parameters

string $fieldName

The name of the field to be validated.

Return Value

Console

in Console at line 133
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

Parameters

string $message

The message to present to the user.

FrameworkQuestion $question

Instance of FrameworkQuestion class.

array $attributes

An array of additional validators and attributes.

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.

bool $defaultNone

When set to true user will have to specify all validators. Default value is false. When false the validators you supply are appended to list of default validators.

Return Value

string

The user response.

at line 36
static int contents(string $migrationName, mixed $renameOption, mixed $updateOption, FrameworkQuestion $question)

Generates new migration class if table-name argument is provided. If rename or update flags are set then appropriate migration class is created.

Parameters

string $migrationName

The name of the table for the new migration class.

mixed $renameOption

Value/state of rename flag.

mixed $updateOption
FrameworkQuestion $question

Instance of FrameworkQuestion class.

Return Value

int

A value that indicates success, invalid, or failure.

at line 57
static string fileNameTime()

Generates time stamp for migrations in following format: yyyymmddhhmmss.

Return Value

string

The migration timestamp.

at line 66
static int generateACLTableMigration()

Generates migration for acl table.

Return Value

int

A value that indicates success, invalid, or failure.

at line 80
static int generateAllMigrations()

Generates all migrations.

Return Value

int Command::SUCCESS

at line 95
static int generateEmailAttachmentsTableMigration()

Generates migration for email_attachments table.

Return Value

int

A value that indicates success, invalid, or failure.

at line 110
static int generateMigrationByName(InputInterface $input)

Generates migration by name.

Parameters

InputInterface $input

The Symfony InputInterface object.

Return Value

int Command::SUCCESS

at line 125
static int generateMigrationsTableMigration()

Generates migration for migration table.

Return Value

int

A value that indicates success, invalid, or failure.

at line 139
static int generateProfileImagesTableMigration()

Generates migration for profile_images table.

Return Value

int

A value that indicates success, invalid, or failure.

at line 153
static int generateUserSessionsTableMigration()

Generates migration for user_sessions table.

Return Value

int

A value that indicates success, invalid, or failure.

at line 167
static int generateUsersTableMigration()

Generates migration for users table.

Return Value

int

A value that indicates success, invalid, or failure.

at line 184
static bool isBothFlagsSet(mixed $renameOption, mixed $updateOption)

Determines if both rename and update flags are set. If they are both set then a message is displayed and true is returned.

Parameters

mixed $renameOption

Value/state of rename flag.

mixed $updateOption

Return Value

bool

True if both flags are set. Otherwise, we return false.

at line 200
static int makeMigration(string $migrationName)

Generates a migration class for creating a new table.

Parameters

string $migrationName

The name of the table the new migration will target.

Return Value

int

A value that indicates success, invalid, or failure.

at line 220
static int makeRenameMigration(string $migrationName, mixed $renameOption)

Generates a migration class for renaming an existing table.

Parameters

string $migrationName

The name of the table the new migration will target.

mixed $renameOption

Value/state of rename flag.

Return Value

int

A value that indicates success, invalid, or failure.

at line 238
static int makeUpdateMigration(string $migrationName)

Generates a migration class for updating existing table.

Parameters

string $migrationName

The name of the table the new migration will target.

Return Value

int

A value that indicates success, invalid, or failure.

at line 256
static string migrationNamePrompt(FrameworkQuestion $question)

Handles question for which table a new migration will target.

Parameters

FrameworkQuestion $question

Instance of FrameworkQuestion class.

Return Value

string

The name of the table the new migration will target.

at line 268
static int migrationTypePrompt(FrameworkQuestion $question, string $migrationName)

Prompts user for input when no argument and no options are set.

Parameters

FrameworkQuestion $question

Instance of FrameworkQuestion class.

string $migrationName

Name of migration to be created or renamed to.

Return Value

int

A value that indicates success, invalid, or failure.

at line 287
static private array modifiedAttributes(array $attributes)

Returns modified version of MigrationBuilder::PROMPT_ATTRIBUTES array.

Parameters

array $attributes

The additional attributes you want to add.

Return Value

array

The modified const array.

at line 299
static private int renameChoice(string $migrationName, FrameworkQuestion $question)

Prompts user to enter name for table to be renamed. Used when user responds with the choice to rename.

Parameters

string $migrationName

The new name for the table to be renamed.

FrameworkQuestion $question

Instance of FrameworkQuestion class.

Return Value

int

A value that indicates success, invalid, or failure.

at line 318
static int renamePrompt(FrameworkQuestion $question, mixed $renameOption)

Prompts user to enter name of table to be updated. Used when user provides name of controller as an argument.

Parameters

FrameworkQuestion $question

Instance of FrameworkQuestion class.

mixed $renameOption

Value/state of rename flag.

Return Value

int

A value that indicates success, invalid, or failure.

at line 331
static array setFlags(InputInterface $input)

Generates an array containing values for rename and update flags.

Parameters

InputInterface $input

The Symfony InputInterface object.

Return Value

array

The contents of the rename and update flags.

at line 356
static private string validateRenameOption(string $to, string $from, FrameworkQuestion $question)

Validate rename option value. If validation fails the user is asked to resolve the issue.

Validates the following conditions: 1) required 2) noSpecialChars 3) alpha 4) notReservedKeyword 5) max 6) different

Parameters

string $to

The new name of the table.

string $from

The original name of the table.

FrameworkQuestion $question

Instance of FrameworkQuestion class.

Return Value

string

The original value if validation passed. The updated value if validation failed.