|
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
|
|
|
use Schnittstabil\Dartisan\OutputInterface; |
|
9
|
|
|
|
|
10
|
|
|
class MigrateMakeCommand extends Command |
|
11
|
|
|
{ |
|
12
|
|
|
use DatabaseAwareCommandTrait; |
|
13
|
|
|
use MigrationAwareCommandTrait; |
|
14
|
|
|
|
|
15
|
|
|
public static $name = 'make:migration'; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @var MigrationCreator |
|
19
|
|
|
*/ |
|
20
|
|
|
protected $migrationCreator; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @var string |
|
24
|
|
|
*/ |
|
25
|
|
|
protected $migrationsPath; |
|
26
|
|
|
|
|
27
|
|
|
public function __construct( |
|
28
|
|
|
Args $args, |
|
29
|
|
|
OutputInterface $output, |
|
30
|
|
|
MigrationCreator $migrationCreator, |
|
31
|
|
|
string $migrationsPath |
|
32
|
|
|
) { |
|
33
|
|
|
parent::__construct($args, $output); |
|
34
|
|
|
$this->migrationCreator = $migrationCreator; |
|
35
|
|
|
$this->migrationsPath = $migrationsPath; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function run() |
|
39
|
|
|
{ |
|
40
|
|
|
$name = trim($this->args->getArg('name')); |
|
41
|
|
|
$path = $this->args->getOpt('path', $this->migrationsPath); |
|
42
|
|
|
$create = $this->args->getOpt('create'); |
|
43
|
|
|
$table = $this->args->getOpt('table', $create); |
|
44
|
|
|
|
|
45
|
|
|
$file = pathinfo($this->migrationCreator->create($name, $path, $table, $create), PATHINFO_FILENAME); |
|
46
|
|
|
$this->output->info('Created Migration:', false); |
|
|
|
|
|
|
47
|
|
|
$this->output->raw(' ', false); |
|
|
|
|
|
|
48
|
|
|
$this->output->raw($file); |
|
|
|
|
|
|
49
|
|
|
|
|
50
|
|
|
return 0; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
public static function register(Cli $cli) |
|
54
|
|
|
{ |
|
55
|
|
|
$cli = static::registerDatabaseOpts($cli); |
|
56
|
|
|
$cli = static::registerMigrationOpts($cli); |
|
57
|
|
|
|
|
58
|
|
|
return $cli |
|
59
|
|
|
->command(static::$name) |
|
60
|
|
|
->description('Create a new migration file.') |
|
61
|
|
|
->opt('create', 'The table to be created.') |
|
62
|
|
|
->opt('table', 'The table to migrate.') |
|
63
|
|
|
->opt('path', 'The location where the migration file should be created.') |
|
64
|
|
|
->arg('name', 'The name of the migration.', true); |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
|
Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.