Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
namespace Illuminate\Database;
4
 
5
use Illuminate\Contracts\Events\Dispatcher;
6
use Illuminate\Contracts\Support\DeferrableProvider;
7
use Illuminate\Database\Console\Migrations\FreshCommand;
8
use Illuminate\Database\Console\Migrations\InstallCommand;
9
use Illuminate\Database\Console\Migrations\MigrateCommand;
10
use Illuminate\Database\Console\Migrations\MigrateMakeCommand;
11
use Illuminate\Database\Console\Migrations\RefreshCommand;
12
use Illuminate\Database\Console\Migrations\ResetCommand;
13
use Illuminate\Database\Console\Migrations\RollbackCommand;
14
use Illuminate\Database\Console\Migrations\StatusCommand;
15
use Illuminate\Database\Migrations\DatabaseMigrationRepository;
16
use Illuminate\Database\Migrations\MigrationCreator;
17
use Illuminate\Database\Migrations\Migrator;
18
use Illuminate\Support\ServiceProvider;
19
 
20
class MigrationServiceProvider extends ServiceProvider implements DeferrableProvider
21
{
22
    /**
23
     * The commands to be registered.
24
     *
25
     * @var array
26
     */
27
    protected $commands = [
28
        'Migrate' => MigrateCommand::class,
29
        'MigrateFresh' => FreshCommand::class,
30
        'MigrateInstall' => InstallCommand::class,
31
        'MigrateRefresh' => RefreshCommand::class,
32
        'MigrateReset' => ResetCommand::class,
33
        'MigrateRollback' => RollbackCommand::class,
34
        'MigrateStatus' => StatusCommand::class,
35
        'MigrateMake' => MigrateMakeCommand::class,
36
    ];
37
 
38
    /**
39
     * Register the service provider.
40
     *
41
     * @return void
42
     */
43
    public function register()
44
    {
45
        $this->registerRepository();
46
 
47
        $this->registerMigrator();
48
 
49
        $this->registerCreator();
50
 
51
        $this->registerCommands($this->commands);
52
    }
53
 
54
    /**
55
     * Register the migration repository service.
56
     *
57
     * @return void
58
     */
59
    protected function registerRepository()
60
    {
61
        $this->app->singleton('migration.repository', function ($app) {
62
            $table = $app['config']['database.migrations'];
63
 
64
            return new DatabaseMigrationRepository($app['db'], $table);
65
        });
66
    }
67
 
68
    /**
69
     * Register the migrator service.
70
     *
71
     * @return void
72
     */
73
    protected function registerMigrator()
74
    {
75
        // The migrator is responsible for actually running and rollback the migration
76
        // files in the application. We'll pass in our database connection resolver
77
        // so the migrator can resolve any of these connections when it needs to.
78
        $this->app->singleton('migrator', function ($app) {
79
            $repository = $app['migration.repository'];
80
 
81
            return new Migrator($repository, $app['db'], $app['files'], $app['events']);
82
        });
83
    }
84
 
85
    /**
86
     * Register the migration creator.
87
     *
88
     * @return void
89
     */
90
    protected function registerCreator()
91
    {
92
        $this->app->singleton('migration.creator', function ($app) {
93
            return new MigrationCreator($app['files'], $app->basePath('stubs'));
94
        });
95
    }
96
 
97
    /**
98
     * Register the given commands.
99
     *
100
     * @param  array  $commands
101
     * @return void
102
     */
103
    protected function registerCommands(array $commands)
104
    {
105
        foreach (array_keys($commands) as $command) {
106
            $this->{"register{$command}Command"}();
107
        }
108
 
109
        $this->commands(array_values($commands));
110
    }
111
 
112
    /**
113
     * Register the command.
114
     *
115
     * @return void
116
     */
117
    protected function registerMigrateCommand()
118
    {
119
        $this->app->singleton(MigrateCommand::class, function ($app) {
120
            return new MigrateCommand($app['migrator'], $app[Dispatcher::class]);
121
        });
122
    }
123
 
124
    /**
125
     * Register the command.
126
     *
127
     * @return void
128
     */
129
    protected function registerMigrateFreshCommand()
130
    {
131
        $this->app->singleton(FreshCommand::class);
132
    }
133
 
134
    /**
135
     * Register the command.
136
     *
137
     * @return void
138
     */
139
    protected function registerMigrateInstallCommand()
140
    {
141
        $this->app->singleton(InstallCommand::class, function ($app) {
142
            return new InstallCommand($app['migration.repository']);
143
        });
144
    }
145
 
146
    /**
147
     * Register the command.
148
     *
149
     * @return void
150
     */
151
    protected function registerMigrateMakeCommand()
152
    {
153
        $this->app->singleton(MigrateMakeCommand::class, function ($app) {
154
            // Once we have the migration creator registered, we will create the command
155
            // and inject the creator. The creator is responsible for the actual file
156
            // creation of the migrations, and may be extended by these developers.
157
            $creator = $app['migration.creator'];
158
 
159
            $composer = $app['composer'];
160
 
161
            return new MigrateMakeCommand($creator, $composer);
162
        });
163
    }
164
 
165
    /**
166
     * Register the command.
167
     *
168
     * @return void
169
     */
170
    protected function registerMigrateRefreshCommand()
171
    {
172
        $this->app->singleton(RefreshCommand::class);
173
    }
174
 
175
    /**
176
     * Register the command.
177
     *
178
     * @return void
179
     */
180
    protected function registerMigrateResetCommand()
181
    {
182
        $this->app->singleton(ResetCommand::class, function ($app) {
183
            return new ResetCommand($app['migrator']);
184
        });
185
    }
186
 
187
    /**
188
     * Register the command.
189
     *
190
     * @return void
191
     */
192
    protected function registerMigrateRollbackCommand()
193
    {
194
        $this->app->singleton(RollbackCommand::class, function ($app) {
195
            return new RollbackCommand($app['migrator']);
196
        });
197
    }
198
 
199
    /**
200
     * Register the command.
201
     *
202
     * @return void
203
     */
204
    protected function registerMigrateStatusCommand()
205
    {
206
        $this->app->singleton(StatusCommand::class, function ($app) {
207
            return new StatusCommand($app['migrator']);
208
        });
209
    }
210
 
211
    /**
212
     * Get the services provided by the provider.
213
     *
214
     * @return array
215
     */
216
    public function provides()
217
    {
218
        return array_merge([
219
            'migrator', 'migration.repository', 'migration.creator',
220
        ], array_values($this->commands));
221
    }
222
}