independent-analytics
/
vendor
/
illuminate
/
database
/
Console
/
Migrations
/
MigrateMakeCommand.php
BaseCommand.php
2 years ago
FreshCommand.php
2 years ago
InstallCommand.php
2 years ago
MigrateCommand.php
2 years ago
MigrateMakeCommand.php
2 years ago
RefreshCommand.php
2 years ago
ResetCommand.php
2 years ago
RollbackCommand.php
2 years ago
StatusCommand.php
2 years ago
TableGuesser.php
2 years ago
MigrateMakeCommand.php
114 lines
| 1 | <?php |
| 2 | |
| 3 | namespace IAWP_SCOPED\Illuminate\Database\Console\Migrations; |
| 4 | |
| 5 | use IAWP_SCOPED\Illuminate\Database\Migrations\MigrationCreator; |
| 6 | use IAWP_SCOPED\Illuminate\Support\Composer; |
| 7 | use IAWP_SCOPED\Illuminate\Support\Str; |
| 8 | /** @internal */ |
| 9 | class MigrateMakeCommand extends BaseCommand |
| 10 | { |
| 11 | /** |
| 12 | * The console command signature. |
| 13 | * |
| 14 | * @var string |
| 15 | */ |
| 16 | protected $signature = 'make:migration {name : The name of the migration} |
| 17 | {--create= : The table to be created} |
| 18 | {--table= : The table to migrate} |
| 19 | {--path= : The location where the migration file should be created} |
| 20 | {--realpath : Indicate any provided migration file paths are pre-resolved absolute paths} |
| 21 | {--fullpath : Output the full path of the migration}'; |
| 22 | /** |
| 23 | * The console command description. |
| 24 | * |
| 25 | * @var string |
| 26 | */ |
| 27 | protected $description = 'Create a new migration file'; |
| 28 | /** |
| 29 | * The migration creator instance. |
| 30 | * |
| 31 | * @var \Illuminate\Database\Migrations\MigrationCreator |
| 32 | */ |
| 33 | protected $creator; |
| 34 | /** |
| 35 | * The Composer instance. |
| 36 | * |
| 37 | * @var \Illuminate\Support\Composer |
| 38 | */ |
| 39 | protected $composer; |
| 40 | /** |
| 41 | * Create a new migration install command instance. |
| 42 | * |
| 43 | * @param \Illuminate\Database\Migrations\MigrationCreator $creator |
| 44 | * @param \Illuminate\Support\Composer $composer |
| 45 | * @return void |
| 46 | */ |
| 47 | public function __construct(MigrationCreator $creator, Composer $composer) |
| 48 | { |
| 49 | parent::__construct(); |
| 50 | $this->creator = $creator; |
| 51 | $this->composer = $composer; |
| 52 | } |
| 53 | /** |
| 54 | * Execute the console command. |
| 55 | * |
| 56 | * @return void |
| 57 | */ |
| 58 | public function handle() |
| 59 | { |
| 60 | // It's possible for the developer to specify the tables to modify in this |
| 61 | // schema operation. The developer may also specify if this table needs |
| 62 | // to be freshly created so we can create the appropriate migrations. |
| 63 | $name = Str::snake(\trim($this->input->getArgument('name'))); |
| 64 | $table = $this->input->getOption('table'); |
| 65 | $create = $this->input->getOption('create') ?: \false; |
| 66 | // If no table was given as an option but a create option is given then we |
| 67 | // will use the "create" option as the table name. This allows the devs |
| 68 | // to pass a table name into this option as a short-cut for creating. |
| 69 | if (!$table && \is_string($create)) { |
| 70 | $table = $create; |
| 71 | $create = \true; |
| 72 | } |
| 73 | // Next, we will attempt to guess the table name if this the migration has |
| 74 | // "create" in the name. This will allow us to provide a convenient way |
| 75 | // of creating migrations that create new tables for the application. |
| 76 | if (!$table) { |
| 77 | [$table, $create] = TableGuesser::guess($name); |
| 78 | } |
| 79 | // Now we are ready to write the migration out to disk. Once we've written |
| 80 | // the migration out, we will dump-autoload for the entire framework to |
| 81 | // make sure that the migrations are registered by the class loaders. |
| 82 | $this->writeMigration($name, $table, $create); |
| 83 | $this->composer->dumpAutoloads(); |
| 84 | } |
| 85 | /** |
| 86 | * Write the migration file to disk. |
| 87 | * |
| 88 | * @param string $name |
| 89 | * @param string $table |
| 90 | * @param bool $create |
| 91 | * @return string |
| 92 | */ |
| 93 | protected function writeMigration($name, $table, $create) |
| 94 | { |
| 95 | $file = $this->creator->create($name, $this->getMigrationPath(), $table, $create); |
| 96 | if (!$this->option('fullpath')) { |
| 97 | $file = \pathinfo($file, \PATHINFO_FILENAME); |
| 98 | } |
| 99 | $this->line("<info>Created Migration:</info> {$file}"); |
| 100 | } |
| 101 | /** |
| 102 | * Get migration path (either specified by '--path' option or default location). |
| 103 | * |
| 104 | * @return string |
| 105 | */ |
| 106 | protected function getMigrationPath() |
| 107 | { |
| 108 | if (!\is_null($targetPath = $this->input->getOption('path'))) { |
| 109 | return !$this->usingRealPath() ? $this->laravel->basePath() . '/' . $targetPath : $targetPath; |
| 110 | } |
| 111 | return parent::getMigrationPath(); |
| 112 | } |
| 113 | } |
| 114 |