1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace LaravelPlus\Extension; |
4
|
|
|
|
5
|
|
|
use Illuminate\Support\Facades\Blade; |
6
|
|
|
use Jumilla\Addomnipot\Laravel\Environment as AddonEnvironment; |
7
|
|
|
use Jumilla\Addomnipot\Laravel\Registrar as AddonRegistrar; |
8
|
|
|
use Jumilla\Addomnipot\Laravel\ClassLoader as AddonClassLoader; |
9
|
|
|
use Jumilla\Addomnipot\Laravel\Generator as AddonGenerator; |
10
|
|
|
use Jumilla\Addomnipot\Laravel\AliasResolver; |
11
|
|
|
use Jumilla\Addomnipot\Laravel\Repository; |
12
|
|
|
use Jumilla\Addomnipot\Laravel\Events\AddonWorldCreated; |
13
|
|
|
use Jumilla\Addomnipot\Laravel\Events\AddonRegistered; |
14
|
|
|
use Jumilla\Addomnipot\Laravel\Events\AddonBooted; |
15
|
|
|
use LaravelPlus\Extension\Generators\GeneratorCommandRegistrar; |
16
|
|
|
use LaravelPlus\Extension\Templates\BladeExtension; |
17
|
|
|
use Jumilla\Versionia\Laravel\Migrator; |
18
|
|
|
|
19
|
|
|
class ServiceProvider extends \Illuminate\Support\ServiceProvider |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* Addon environment. |
23
|
|
|
* |
24
|
|
|
* @var \Jumilla\Addomnipot\Laravel\Environment |
25
|
|
|
*/ |
26
|
|
|
protected $addonEnvironment; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var array |
30
|
|
|
*/ |
31
|
|
|
protected static $commands = [ |
32
|
|
|
// app: |
33
|
|
|
'command+.app.container' => Console\AppContainerCommand::class, |
34
|
|
|
'command+.app.route' => Console\RouteListCommand::class, |
35
|
|
|
'command+.app.tail' => Console\TailCommand::class, |
36
|
|
|
// addon: |
37
|
|
|
'command+.addon.list' => Addons\Console\AddonListCommand::class, |
38
|
|
|
'command+.addon.status' => Addons\Console\AddonStatusCommand::class, |
39
|
|
|
'command+.addon.make' => Addons\Console\AddonMakeCommand::class, |
40
|
|
|
'command+.addon.name' => Addons\Console\AddonNameCommand::class, |
41
|
|
|
'command+.addon.remove' => Addons\Console\AddonRemoveCommand::class, |
42
|
|
|
// database: |
43
|
|
|
'command+.database.status' => Database\Console\DatabaseStatusCommand::class, |
44
|
|
|
'command+.database.upgrade' => Database\Console\DatabaseUpgradeCommand::class, |
45
|
|
|
'command+.database.clean' => Database\Console\DatabaseCleanCommand::class, |
46
|
|
|
'command+.database.refresh' => Database\Console\DatabaseRefreshCommand::class, |
47
|
|
|
'command+.database.rollback' => Database\Console\DatabaseRollbackCommand::class, |
48
|
|
|
'command+.database.again' => Database\Console\DatabaseAgainCommand::class, |
49
|
|
|
'command+.database.seed' => Database\Console\DatabaseSeedCommand::class, |
50
|
|
|
// hash: |
51
|
|
|
'command+.hash.make' => Console\HashMakeCommand::class, |
52
|
|
|
'command+.hash.check' => Console\HashCheckCommand::class, |
53
|
|
|
]; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @var array |
57
|
|
|
*/ |
58
|
|
|
protected $addons; |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Register the service provider. |
62
|
|
|
*/ |
63
|
1 |
|
public function register() |
64
|
|
|
{ |
65
|
1 |
|
$app = $this->app; |
66
|
|
|
|
67
|
|
|
// register spec path for app |
68
|
1 |
|
$app['path.specs'] = $app->basePath().'/resources/specs'; |
69
|
|
|
|
70
|
|
|
// register spec repository |
71
|
|
|
$app->singleton('specs', function ($app) { |
72
|
|
|
$loader = new Repository\FileLoader($app['files'], $app['path.specs']); |
73
|
|
|
|
74
|
|
|
return new Repository\NamespacedRepository($loader); |
75
|
1 |
|
}); |
76
|
|
|
|
77
|
|
|
// register addon environment |
78
|
1 |
|
$app->instance('addon', $this->addonEnvironment = new AddonEnvironment($app)); |
79
|
1 |
|
$app->alias('addon', AddonEnvironment::class); |
80
|
|
|
|
81
|
|
|
// register addon generator |
82
|
|
|
$app->singleton('addon.generator', function ($app) { |
83
|
|
|
return new AddonGenerator(); |
84
|
1 |
|
}); |
85
|
1 |
|
$app->alias('addon.generator', AddonGenerator::class); |
86
|
|
|
|
87
|
|
|
// register database migrator |
88
|
|
|
$app->singleton('database.migrator', function ($app) { |
89
|
|
|
return new Migrator($app['db'], $app['config']); |
90
|
1 |
|
}); |
91
|
1 |
|
$app->alias('database.migrator', Migrator::class); |
92
|
|
|
|
93
|
|
|
|
94
|
1 |
|
$app['events']->fire(new AddonWorldCreated($this->addonEnvironment)); |
95
|
|
|
|
96
|
1 |
|
$this->registerClassResolvers(); |
97
|
|
|
|
98
|
1 |
|
(new AddonRegistrar)->register($app, $this->addonEnvironment->addons()); |
99
|
|
|
|
100
|
1 |
|
$app['events']->fire(new AddonRegistered($this->addonEnvironment)); |
101
|
1 |
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
*/ |
105
|
1 |
|
protected function registerClassResolvers() |
106
|
|
|
{ |
107
|
1 |
|
$addons = $this->addonEnvironment->addons(); |
108
|
|
|
|
109
|
1 |
|
AddonClassLoader::register($this->addonEnvironment, $addons); |
110
|
|
|
|
111
|
1 |
|
AliasResolver::register($this->app['path'], $addons, $this->app['config']->get('app.aliases')); |
112
|
1 |
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* setup package's commands. |
116
|
|
|
* |
117
|
|
|
* @param array $commands |
118
|
|
|
*/ |
119
|
1 |
|
protected function setupPackageCommands(array $commands) |
120
|
|
|
{ |
121
|
1 |
|
foreach ($commands as $name => $class) { |
122
|
1 |
|
$this->app->singleton($name, function ($app) use ($class) { |
123
|
|
|
return $app->build($class); |
124
|
1 |
|
}); |
125
|
1 |
|
} |
126
|
|
|
|
127
|
|
|
// Now register all the commands |
128
|
1 |
|
$registrar = new GeneratorCommandRegistrar($this->app); |
129
|
|
|
|
130
|
1 |
|
$this->commands($registrar->register()); |
131
|
1 |
|
$this->commands(array_keys($commands)); |
132
|
1 |
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* Bootstrap the application events. |
136
|
|
|
*/ |
137
|
1 |
|
public function boot() |
138
|
|
|
{ |
139
|
1 |
|
$app = $this->app; |
140
|
|
|
|
141
|
|
|
// |
142
|
1 |
|
$this->registerBladeExtensions(); |
143
|
|
|
|
144
|
|
|
// boot all addons |
145
|
1 |
|
(new AddonRegistrar)->boot($app, $this->addonEnvironment->addons()); |
146
|
|
|
|
147
|
1 |
|
$this->setupPackageCommands(static::$commands); |
148
|
|
|
|
149
|
1 |
|
$app['events']->fire(new AddonBooted($this->addonEnvironment)); |
150
|
1 |
|
} |
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* register blade extensions. |
154
|
|
|
*/ |
155
|
1 |
|
protected function registerBladeExtensions() |
156
|
|
|
{ |
157
|
1 |
|
Blade::extend(BladeExtension::comment()); |
158
|
|
|
|
159
|
1 |
|
Blade::extend(BladeExtension::script()); |
160
|
1 |
|
} |
161
|
|
|
|
162
|
|
|
/** |
163
|
|
|
* Get the services provided by the provider. |
164
|
|
|
* |
165
|
|
|
* @return array |
166
|
|
|
*/ |
167
|
|
|
public function provides() |
168
|
|
|
{ |
169
|
|
|
return array_keys(static::$commands); |
170
|
|
|
} |
171
|
|
|
} |
172
|
|
|
|