Migrate
class Migrate extends Console
Helper class for migration related console commands.
Traits
Supports ability to validate console input.
Constants
| MIGRATIONS_PATH |
Path to database migration files. |
| MIGRATION_PROMPT |
The message to present to user when name of migration is being asked. |
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.
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.
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.
Parse array containing additional validators or attributes for FrameworkQuestion as strings along with any additional parameters that maybe expected.
Test if a particular batch of migrations exists.
Ask user to confirm if they want to drop all tables.
Ask user to confirm if they want to proceed with migration operation when in production mode.
Generates new migration class if table-name argument is provided. If rename or update flags are set then appropriate migration class is created.
Drops all tables from the database without using down function.
Generates time stamp for migrations in following format: yyyymmddhhmmss.
Generates migration for acl table.
Generates all migrations.
Generates migration for email_attachments table.
Generates migration by name.
Generates migration for migration table.
Generates migration for profile_images table.
Generates migration for user_sessions table.
Generates migration for users table.
Determines if both rename and update flags are set. If they are both set then a message is displayed and true is returned.
Generates a migration class for creating a new table.
Generates a migration class for renaming an existing table.
Generates a migration class for updating existing table.
Performs migration operation.
Handles question for which table a new migration will target.
Prompts user for input when no argument and no options are set.
Performs refresh operation.
Prompts user to enter name for table to be renamed. Used when user responds with the choice to rename.
Prompts user to enter name of table to be updated. Used when user provides name of controller as an argument.
Performs roll back operation
Perform step roll back.
Generates an array containing values for rename and update flags.
Reports migration status.
Drops table one at a time.
Determines number of tables in database before performing migration operations.
Validate rename option value. If validation fails the user is asked to resolve the issue.
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.
in
Console at line 20
__construct(string $fieldName = "")
Creates new instance of Console class.
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
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.
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.
in
Console at line 107
static Console
getInstance(string $fieldName = "")
Returns instance of this or child helper class.
in
Console at line 132
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
in
Console at line 167
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.
at line 38
static private bool
batchExists(int $batch)
Test if a particular batch of migrations exists.
at line 53
static mixed
confirmDropAllTables(FrameworkQuestion $question)
Ask user to confirm if they want to drop all tables.
at line 65
static mixed
confirmMigrationInProduction(FrameworkQuestion $question)
Ask user to confirm if they want to proceed with migration operation when in production mode.
at line 80
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.
at line 101
static int
dropAllTables()
Drops all tables from the database without using down function.
at line 134
static string
fileNameTime()
Generates time stamp for migrations in following format: yyyymmddhhmmss.
at line 143
static int
generateACLTableMigration()
Generates migration for acl table.
at line 157
static int
generateAllMigrations()
Generates all migrations.
at line 171
static int
generateEmailAttachmentsTableMigration()
Generates migration for email_attachments table.
at line 186
static int
generateMigrationByName(InputInterface $input)
Generates migration by name.
at line 201
static int
generateMigrationsTableMigration()
Generates migration for migration table.
at line 215
static int
generateProfileImagesTableMigration()
Generates migration for profile_images table.
at line 229
static int
generateUserSessionsTableMigration()
Generates migration for user_sessions table.
at line 243
static int
generateUsersTableMigration()
Generates migration for users table.
at line 260
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.
at line 276
static int
makeMigration(string $migrationName)
Generates a migration class for creating a new table.
at line 296
static int
makeRenameMigration(string $migrationName, mixed $renameOption)
Generates a migration class for renaming an existing table.
at line 314
static int
makeUpdateMigration(string $migrationName)
Generates a migration class for updating existing table.
at line 331
static int
migrate()
Performs migration operation.
at line 402
static string
migrationNamePrompt(FrameworkQuestion $question)
Handles question for which table a new migration will target.
at line 414
static int
migrationTypePrompt(FrameworkQuestion $question, string $migrationName)
Prompts user for input when no argument and no options are set.
at line 434
static int
refresh(bool|int $step = false)
Performs refresh operation.
at line 490
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.
at line 504
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.
at line 518
static int
rollback(string|int|bool $batch = false)
Performs roll back operation
at line 566
static int
rollbackStep(string|int $step)
Perform step roll back.
at line 580
static array
setFlags(InputInterface $input)
Generates an array containing values for rename and update flags.
at line 592
static int
status()
Reports migration status.
at line 648
static private bool|int
step(string $klassNamespace, bool|int $step = false)
Drops table one at a time.
at line 669
static private int
tableCount()
Determines number of tables in database before performing migration operations.
at line 702
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