1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Jumilla\Addomnipot\Laravel; |
4
|
|
|
|
5
|
|
|
use Illuminate\Support\ServiceProvider as BaseServiceProvider; |
6
|
|
|
use Illuminate\Contracts\Http\Kernel as HttpKernel; |
7
|
|
|
|
8
|
|
|
class ServiceProvider extends BaseServiceProvider |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* Addon environment. |
12
|
|
|
* |
13
|
|
|
* @var \Jumilla\Addomnipot\Laravel\Environment |
14
|
|
|
*/ |
15
|
|
|
protected $environment; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Register the service provider. |
19
|
|
|
*/ |
20
|
1 |
|
public function register() |
21
|
|
|
{ |
22
|
1 |
|
$app = $this->app; |
23
|
|
|
|
24
|
1 |
|
$app->instance('addon', $this->environment = new Environment($app)); |
25
|
1 |
|
$app->alias('addon', Environment::class); |
26
|
|
|
|
27
|
|
|
$app->singleton(Generator::class, function ($app) { |
|
|
|
|
28
|
|
|
return new Generator(); |
29
|
1 |
|
}); |
30
|
|
|
|
31
|
1 |
|
$this->registerCommands(); |
32
|
|
|
|
33
|
1 |
|
$this->registerClassResolvers(); |
34
|
|
|
|
35
|
1 |
|
$app['event']->fire(new Events\AddonWorldCreated($this->environment)); |
36
|
|
|
|
37
|
1 |
|
$this->registerAddons(); |
38
|
1 |
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Register the cache related console commands. |
42
|
|
|
*/ |
43
|
1 |
|
public function registerCommands() |
44
|
|
|
{ |
45
|
|
|
$this->app->singleton('command.addon.list', function ($app) { |
|
|
|
|
46
|
|
|
return new Console\AddonListCommand(); |
47
|
1 |
|
}); |
48
|
|
|
|
49
|
|
|
$this->app->singleton('command.addon.status', function ($app) { |
|
|
|
|
50
|
|
|
return new Console\AddonStatusCommand(); |
51
|
1 |
|
}); |
52
|
|
|
|
53
|
|
|
$this->app->singleton('command.addon.make', function ($app) { |
|
|
|
|
54
|
|
|
return new Console\AddonMakeCommand(); |
55
|
1 |
|
}); |
56
|
|
|
|
57
|
|
|
$this->app->singleton('command.addon.name', function ($app) { |
|
|
|
|
58
|
|
|
return new Console\AddonNameCommand(); |
59
|
1 |
|
}); |
60
|
|
|
|
61
|
1 |
|
$this->app->singleton('command.addon.remove', function ($app) { |
|
|
|
|
62
|
|
|
return new Console\AddonRemoveCommand(); |
63
|
1 |
|
}); |
64
|
|
|
|
65
|
1 |
|
$this->commands([ |
66
|
1 |
|
'command.addon.list', |
67
|
|
|
'command.addon.status', |
68
|
|
|
'command.addon.make', |
69
|
|
|
'command.addon.name', |
70
|
|
|
'command.addon.remove', |
71
|
|
|
]); |
72
|
1 |
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
*/ |
76
|
1 |
|
protected function registerClassResolvers() |
77
|
|
|
{ |
78
|
1 |
|
$addons = $this->environment->addons(); |
79
|
|
|
|
80
|
1 |
|
ClassLoader::register($this->environment, $addons); |
81
|
|
|
|
82
|
1 |
|
AliasResolver::register($this->app['path'], $addons, $this->app['config']->get('app.aliases')); |
83
|
1 |
|
} |
84
|
|
|
|
85
|
1 |
|
public function registerAddons() |
86
|
|
|
{ |
87
|
1 |
|
foreach ($this->environment->addons() as $addon) { |
88
|
|
|
$addon->register($this->app); |
89
|
|
|
} |
90
|
|
|
|
91
|
1 |
|
$this->commands($this->environment->addonConsoleCommands()); |
92
|
|
|
|
93
|
1 |
|
foreach ($this->environment->addonHttpMiddlewares() as $middleware) { |
94
|
|
|
$this->app[HttpKernel::class]->pushMiddleware($middleware); |
95
|
|
|
} |
96
|
|
|
|
97
|
1 |
|
foreach ($this->environment->addonRouteMiddlewares() as $key => $middleware) { |
98
|
|
|
$this->app['router']->middleware($key, $middleware); |
99
|
|
|
} |
100
|
|
|
|
101
|
1 |
|
$this->app['event']->fire(new Events\AddonRegistered($this->environment)); |
102
|
1 |
|
} |
103
|
|
|
|
104
|
1 |
|
public function boot() |
105
|
|
|
{ |
106
|
1 |
|
foreach ($this->environment->addons() as $addon) { |
107
|
|
|
$addon->boot($this->app); |
108
|
|
|
} |
109
|
|
|
|
110
|
1 |
|
$this->app['event']->fire(new Events\AddonBooted($this->environment)); |
111
|
1 |
|
} |
112
|
|
|
} |
113
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.