|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Schnittstabil\Dartisan\Commands; |
|
4
|
|
|
|
|
5
|
|
|
use Garden\Cli\Cli; |
|
6
|
|
|
use Garden\Cli\Args; |
|
7
|
|
|
use Illuminate\Database\Migrations\MigrationCreator; |
|
8
|
|
|
|
|
9
|
|
|
class MigrateMakeCommand extends Command |
|
10
|
|
|
{ |
|
11
|
|
|
use DatabaseAwareCommandTrait; |
|
12
|
|
|
use MigrationAwareCommandTrait; |
|
13
|
|
|
|
|
14
|
|
|
public static $name = 'make:migration'; |
|
15
|
|
|
protected $args; |
|
16
|
|
|
protected $migrationCreator; |
|
17
|
|
|
protected $migrationsPath; |
|
18
|
|
|
|
|
19
|
|
|
public function __construct(callable $outputFormatter, Args $args, MigrationCreator $migrationCreator, $migrationsPath) |
|
20
|
|
|
{ |
|
21
|
|
|
parent::__construct($outputFormatter); |
|
22
|
|
|
$this->args = $args; |
|
23
|
|
|
$this->migrationCreator = $migrationCreator; |
|
24
|
|
|
$this->migrationsPath = $migrationsPath; |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
public function run() |
|
28
|
|
|
{ |
|
29
|
|
|
$name = trim($this->args->getArg('name')); |
|
30
|
|
|
$path = $this->args->getOpt('path', $this->migrationsPath); |
|
31
|
|
|
$create = $this->args->getOpt('create'); |
|
32
|
|
|
$table = $this->args->getOpt('table', $create); |
|
33
|
|
|
|
|
34
|
|
|
$file = pathinfo($this->migrationCreator->create($name, $path, $table, $create), PATHINFO_FILENAME); |
|
35
|
|
|
$this->echoInfo('Created Migration:', false); |
|
36
|
|
|
$this->echo(' ', false); |
|
37
|
|
|
$this->echo($file); |
|
38
|
|
|
return 0; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
public static function register(Cli $cli) |
|
42
|
|
|
{ |
|
43
|
|
|
$cli = static::registerDatabaseOpts($cli); |
|
44
|
|
|
$cli = static::registerMigrationOpts($cli); |
|
45
|
|
|
|
|
46
|
|
|
return $cli |
|
47
|
|
|
->command(static::$name) |
|
48
|
|
|
->description('Create a new migration file.') |
|
49
|
|
|
->opt('create', 'The table to be created.') |
|
50
|
|
|
->opt('table', 'The table to migrate.') |
|
51
|
|
|
->opt('path', 'The location where the migration file should be created.') |
|
52
|
|
|
->arg('name', 'The name of the migration.', true); |
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
|