Subversion-Projekte lars-tiefland.laravel_shop

Revision

Zur aktuellen Revision | Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
namespace Illuminate\Database\Console\Migrations;
4
 
5
use Illuminate\Database\Migrations\MigrationCreator;
6
use Illuminate\Support\Composer;
7
use Illuminate\Support\Str;
8
 
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 (Deprecated)}';
22
 
23
    /**
24
     * The console command description.
25
     *
26
     * @var string
27
     */
28
    protected $description = 'Create a new migration file';
29
 
30
    /**
31
     * The migration creator instance.
32
     *
33
     * @var \Illuminate\Database\Migrations\MigrationCreator
34
     */
35
    protected $creator;
36
 
37
    /**
38
     * The Composer instance.
39
     *
40
     * @var \Illuminate\Support\Composer
41
     */
42
    protected $composer;
43
 
44
    /**
45
     * Create a new migration install command instance.
46
     *
47
     * @param  \Illuminate\Database\Migrations\MigrationCreator  $creator
48
     * @param  \Illuminate\Support\Composer  $composer
49
     * @return void
50
     */
51
    public function __construct(MigrationCreator $creator, Composer $composer)
52
    {
53
        parent::__construct();
54
 
55
        $this->creator = $creator;
56
        $this->composer = $composer;
57
    }
58
 
59
    /**
60
     * Execute the console command.
61
     *
62
     * @return void
63
     */
64
    public function handle()
65
    {
66
        // It's possible for the developer to specify the tables to modify in this
67
        // schema operation. The developer may also specify if this table needs
68
        // to be freshly created so we can create the appropriate migrations.
69
        $name = Str::snake(trim($this->input->getArgument('name')));
70
 
71
        $table = $this->input->getOption('table');
72
 
73
        $create = $this->input->getOption('create') ?: false;
74
 
75
        // If no table was given as an option but a create option is given then we
76
        // will use the "create" option as the table name. This allows the devs
77
        // to pass a table name into this option as a short-cut for creating.
78
        if (! $table && is_string($create)) {
79
            $table = $create;
80
 
81
            $create = true;
82
        }
83
 
84
        // Next, we will attempt to guess the table name if this the migration has
85
        // "create" in the name. This will allow us to provide a convenient way
86
        // of creating migrations that create new tables for the application.
87
        if (! $table) {
88
            [$table, $create] = TableGuesser::guess($name);
89
        }
90
 
91
        // Now we are ready to write the migration out to disk. Once we've written
92
        // the migration out, we will dump-autoload for the entire framework to
93
        // make sure that the migrations are registered by the class loaders.
94
        $this->writeMigration($name, $table, $create);
95
 
96
        $this->composer->dumpAutoloads();
97
    }
98
 
99
    /**
100
     * Write the migration file to disk.
101
     *
102
     * @param  string  $name
103
     * @param  string  $table
104
     * @param  bool  $create
105
     * @return string
106
     */
107
    protected function writeMigration($name, $table, $create)
108
    {
109
        $file = $this->creator->create(
110
            $name, $this->getMigrationPath(), $table, $create
111
        );
112
 
113
        $this->components->info(sprintf('Migration [%s] created successfully.', $file));
114
    }
115
 
116
    /**
117
     * Get migration path (either specified by '--path' option or default location).
118
     *
119
     * @return string
120
     */
121
    protected function getMigrationPath()
122
    {
123
        if (! is_null($targetPath = $this->input->getOption('path'))) {
124
            return ! $this->usingRealPath()
125
                            ? $this->laravel->basePath().'/'.$targetPath
126
                            : $targetPath;
127
        }
128
 
129
        return parent::getMigrationPath();
130
    }
131
}