|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace duxet\Rethinkdb; |
|
4
|
|
|
|
|
5
|
|
|
use duxet\Rethinkdb\Console\Migrations\MigrateMakeCommand; |
|
6
|
|
|
use duxet\Rethinkdb\Console\Model\ModelMakeCommand; |
|
7
|
|
|
use duxet\Rethinkdb\Eloquent\Model; |
|
8
|
|
|
use duxet\Rethinkdb\Migrations\MigrationCreator; |
|
9
|
|
|
use Illuminate\Support\ServiceProvider; |
|
10
|
|
|
|
|
11
|
|
|
class RethinkdbServiceProvider extends ServiceProvider |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* Bootstrap the application events. |
|
15
|
|
|
* |
|
16
|
|
|
* @return void |
|
17
|
|
|
*/ |
|
18
|
|
|
public function boot() |
|
19
|
|
|
{ |
|
20
|
|
|
Model::setConnectionResolver($this->app['db']); |
|
21
|
|
|
Model::setEventDispatcher($this->app['events']); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Register the service provider. |
|
26
|
|
|
* |
|
27
|
|
|
* @return void |
|
28
|
|
|
*/ |
|
29
|
|
|
public function register() |
|
30
|
|
|
{ |
|
31
|
|
|
$this->app->resolving('db', function ($db) { |
|
32
|
|
|
$db->extend('rethinkdb', function ($config) { |
|
33
|
|
|
return new Connection($config); |
|
34
|
|
|
}); |
|
35
|
|
|
}); |
|
36
|
|
|
|
|
37
|
|
|
$this->app->singleton('command.rethink-migrate.make', function ($app) { |
|
38
|
|
|
|
|
39
|
|
|
$creator = new MigrationCreator($app['files']); |
|
40
|
|
|
$composer = $app['composer']; |
|
41
|
|
|
|
|
42
|
|
|
return new MigrateMakeCommand($creator, $composer); |
|
43
|
|
|
}); |
|
44
|
|
|
|
|
45
|
|
|
$this->commands('command.rethink-migrate.make'); |
|
46
|
|
|
|
|
47
|
|
|
$this->app->singleton('command.rethink-model.make', function ($app) { |
|
48
|
|
|
return new ModelMakeCommand($app['files']); |
|
49
|
|
|
}); |
|
50
|
|
|
|
|
51
|
|
|
$this->commands('command.rethink-model.make'); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
public function provides() |
|
55
|
|
|
{ |
|
56
|
|
|
return ['command.rethink-migrate.make', 'command.rethink-model.make']; |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
|