1
|
|
|
<?php namespace Mascame\Artificer; |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
use Illuminate\Support\ServiceProvider; |
5
|
|
|
use App; |
6
|
|
|
use Config; |
7
|
|
|
use Illuminate\Support\Str; |
8
|
|
|
use Mascame\Artificer\Extension\Booter; |
9
|
|
|
use Mascame\Artificer\Extension\PluginManager; |
10
|
|
|
use Mascame\Artificer\Extension\WidgetManager; |
11
|
|
|
use Mascame\Artificer\Model\Model; |
12
|
|
|
use Mascame\Artificer\Model\ModelObtainer; |
13
|
|
|
use Mascame\Artificer\Model\ModelSchema; |
14
|
|
|
use Mascame\ArtificerDefaultTheme\ArtificerDefaultThemeServiceProvider; |
15
|
|
|
use Mascame\ArtificerLogreaderPlugin\ArtificerLogreaderPluginServiceProvider; |
16
|
|
|
use Mascame\ArtificerWidgets\ArtificerWidgetsServiceProvider; |
17
|
|
|
use Mascame\Extender\Event\Event; |
18
|
|
|
use Mascame\Extender\Installer\FileInstaller; |
19
|
|
|
use Mascame\Extender\Installer\FileWriter; |
20
|
|
|
use Illuminate\Foundation\AliasLoader as Loader; |
21
|
|
|
|
22
|
|
|
|
23
|
|
|
class ArtificerServiceProvider extends ServiceProvider { |
24
|
|
|
|
25
|
|
|
protected $name = 'admin'; |
26
|
|
|
/** |
27
|
|
|
* Indicates if loading of the provider is deferred. |
28
|
|
|
* |
29
|
|
|
* @var bool |
30
|
|
|
*/ |
31
|
|
|
protected $defer = false; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Bootstrap the application events. |
35
|
|
|
* |
36
|
|
|
* @return void |
37
|
|
|
*/ |
38
|
|
|
public function boot() |
39
|
|
|
{ |
40
|
|
|
if (! Artificer::isBooted()) return; |
41
|
|
|
|
42
|
|
|
$this->addPublishing(); |
43
|
|
|
|
44
|
|
|
$this->app->register(ArtificerLogreaderPluginServiceProvider::class); |
45
|
|
|
$this->app->register(ArtificerWidgetsServiceProvider::class); |
46
|
|
|
|
47
|
|
|
App::make('ArtificerPluginManager')->boot(); |
48
|
|
|
App::make('ArtificerWidgetManager')->boot(); |
49
|
|
|
|
50
|
|
|
$this->requireFiles(); |
51
|
|
|
|
52
|
|
|
$this->app->register(\Collective\Html\HtmlServiceProvider::class); |
53
|
|
|
$this->app->register(ArtificerWidgetsServiceProvider::class); |
54
|
|
|
|
55
|
|
|
$loader = Loader::getInstance(); |
56
|
|
|
$loader->alias('HTML', \Collective\Html\HtmlFacade::class); |
57
|
|
|
$loader->alias('Form', \Collective\Html\FormFacade::class); |
58
|
|
|
|
59
|
|
|
$this->app->register(ArtificerDefaultThemeServiceProvider::class); |
60
|
|
|
|
61
|
|
|
|
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Determines if is on admin |
66
|
|
|
* |
67
|
|
|
* @return bool |
68
|
|
|
*/ |
69
|
|
|
public function isBootable($path, $routePrefix = null) { |
70
|
|
|
if (App::runningInConsole() || App::runningUnitTests()) return true; |
71
|
|
|
|
72
|
|
|
return ( |
73
|
|
|
$path == $routePrefix || Str::startsWith($path, $routePrefix . '/') |
74
|
|
|
); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
private function requireFiles() |
78
|
|
|
{ |
79
|
|
|
require_once __DIR__ . '/Http/filters.php'; |
80
|
|
|
require_once __DIR__ . '/Http/routes.php'; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
private function addPublishing() |
84
|
|
|
{ |
85
|
|
|
$this->publishes([ |
86
|
|
|
__DIR__.'/../config/' => config_path($this->name) .'/', |
87
|
|
|
]); |
88
|
|
|
|
89
|
|
|
$this->loadTranslationsFrom(__DIR__.'/../resources/lang', $this->name); |
90
|
|
|
|
91
|
|
|
$this->publishes([ |
92
|
|
|
__DIR__.'/../database/migrations/' => database_path('migrations') |
93
|
|
|
], 'migrations'); |
94
|
|
|
|
95
|
|
|
$this->publishes([ |
96
|
|
|
__DIR__.'/../database/seeds/' => database_path('seeds') |
97
|
|
|
], 'seeds'); |
98
|
|
|
|
99
|
|
|
$this->publishes([ |
100
|
|
|
__DIR__.'/../resources/assets/' => public_path('packages/mascame/' . $this->name), |
101
|
|
|
], 'public'); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
private function addModel() |
105
|
|
|
{ |
106
|
|
|
App::singleton('ArtificerModel', function () { |
107
|
|
|
return new Model(new ModelSchema(new ModelObtainer())); |
108
|
|
|
}); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
private function addLocalization() |
112
|
|
|
{ |
113
|
|
|
App::singleton('ArtificerLocalization', function () { |
114
|
|
|
return new Localization(); |
115
|
|
|
}); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
private function addManagers() |
119
|
|
|
{ |
120
|
|
|
$widgetsPath = config_path() . '/'. $this->name .'/widgets.php'; |
121
|
|
|
|
122
|
|
|
$widgetManager = new WidgetManager( |
123
|
|
|
new FileInstaller(new FileWriter(), $widgetsPath), |
124
|
|
|
new Booter(), |
125
|
|
|
new Event(app('events')) |
126
|
|
|
); |
127
|
|
|
|
128
|
|
|
|
129
|
|
|
App::singleton('ArtificerWidgetManager', function () use ($widgetManager) { |
130
|
|
|
return $widgetManager; |
131
|
|
|
}); |
132
|
|
|
|
133
|
|
|
$pluginsPath = config_path() . '/'. $this->name .'/plugins.php'; |
134
|
|
|
|
135
|
|
|
$pluginManager = new PluginManager( |
136
|
|
|
new FileInstaller(new FileWriter(), $pluginsPath), |
137
|
|
|
new Booter(), |
138
|
|
|
new Event(app('events')) |
139
|
|
|
); |
140
|
|
|
|
141
|
|
|
App::singleton('ArtificerPluginManager', function () use ($pluginManager) { |
142
|
|
|
return $pluginManager; |
143
|
|
|
}); |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* Register the service provider. |
148
|
|
|
* |
149
|
|
|
* @return void |
150
|
|
|
*/ |
151
|
|
|
public function register() |
152
|
|
|
{ |
153
|
|
|
$configPath = __DIR__ . '/../config/admin.php'; |
154
|
|
|
$this->mergeConfigFrom($configPath, $this->name); |
155
|
|
|
|
156
|
|
|
// Avoid bloating the App with files that will not be needed |
157
|
|
|
if (! $this->isBootable(request()->path(), config('admin.route_prefix'))) return; |
158
|
|
|
|
159
|
|
|
$this->addModel(); |
160
|
|
|
$this->addLocalization(); |
161
|
|
|
$this->addManagers(); |
162
|
|
|
|
163
|
|
|
Artificer::$booted = true; |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* Get the services provided by the provider. |
168
|
|
|
* |
169
|
|
|
* @return array |
170
|
|
|
*/ |
171
|
|
|
public function provides() |
172
|
|
|
{ |
173
|
|
|
return array(); |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
} |
177
|
|
|
|