-
Notifications
You must be signed in to change notification settings - Fork 241
/
WorkshopServiceProvider.php
142 lines (126 loc) · 4.57 KB
/
WorkshopServiceProvider.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<?php
namespace Modules\Workshop\Providers;
use Illuminate\Support\ServiceProvider;
use Modules\Core\Events\BuildingSidebar;
use Modules\Core\Events\LoadingBackendTranslations;
use Modules\Core\Services\Composer;
use Modules\Core\Traits\CanGetSidebarClassForModule;
use Modules\Core\Traits\CanPublishConfiguration;
use Modules\Workshop\Console\EntityScaffoldCommand;
use Modules\Workshop\Console\ModuleScaffoldCommand;
use Modules\Workshop\Console\ThemeScaffoldCommand;
use Modules\Workshop\Console\UpdateModuleCommand;
use Modules\Workshop\Events\Handlers\RegisterWorkshopSidebar;
use Modules\Workshop\Manager\StylistThemeManager;
use Modules\Workshop\Manager\ThemeManager;
use Modules\Workshop\Scaffold\Module\Generators\EntityGenerator;
use Modules\Workshop\Scaffold\Module\Generators\FilesGenerator;
use Modules\Workshop\Scaffold\Module\Generators\ValueObjectGenerator;
use Modules\Workshop\Scaffold\Module\ModuleScaffold;
use Modules\Workshop\Scaffold\Theme\ThemeGeneratorFactory;
use Modules\Workshop\Scaffold\Theme\ThemeScaffold;
use Nwidart\Modules\Repository;
class WorkshopServiceProvider extends ServiceProvider
{
use CanPublishConfiguration, CanGetSidebarClassForModule;
/**
* Indicates if loading of the provider is deferred.
*
* @var bool
*/
protected $defer = false;
/**
* Register the service provider.
*
* @return void
*/
public function register()
{
$this->registerCommands();
$this->bindThemeManager();
$this->app['events']->listen(
BuildingSidebar::class,
$this->getSidebarClassForModule('workshop', RegisterWorkshopSidebar::class)
);
$this->app['events']->listen(LoadingBackendTranslations::class, function (LoadingBackendTranslations $event) {
$event->load('workshop', array_dot(trans('workshop::workshop')));
$event->load('modules', array_dot(trans('workshop::modules')));
$event->load('themes', array_dot(trans('workshop::themes')));
});
app('router')->bind('module', function ($module) {
return app(Repository::class)->find($module);
});
app('router')->bind('theme', function ($theme) {
return app(ThemeManager::class)->find($theme);
});
}
public function boot()
{
$this->publishConfig('workshop', 'permissions');
$this->publishConfig('workshop', 'config');
$this->loadMigrationsFrom(__DIR__ . '/../Database/Migrations');
}
/**
* Register artisan commands
*/
private function registerCommands()
{
$this->registerModuleScaffoldCommand();
$this->registerUpdateCommand();
$this->registerThemeScaffoldCommand();
$this->commands([
'command.asgard.module.scaffold',
'command.asgard.module.update',
'command.asgard.theme.scaffold',
EntityScaffoldCommand::class,
]);
}
/**
* Register the scaffold command
*/
private function registerModuleScaffoldCommand()
{
$this->app->singleton('asgard.module.scaffold', function ($app) {
return new ModuleScaffold(
$app['files'],
$app['config'],
new EntityGenerator($app['files'], $app['config']),
new ValueObjectGenerator($app['files'], $app['config']),
new FilesGenerator($app['files'], $app['config'])
);
});
$this->app->singleton('command.asgard.module.scaffold', function ($app) {
return new ModuleScaffoldCommand($app['asgard.module.scaffold']);
});
}
/**
* Register the update module command
*/
private function registerUpdateCommand()
{
$this->app->singleton('command.asgard.module.update', function ($app) {
return new UpdateModuleCommand(new Composer($app['files'], base_path()));
});
}
/**
* Register the theme scaffold command
*/
private function registerThemeScaffoldCommand()
{
$this->app->singleton('asgard.theme.scaffold', function ($app) {
return new ThemeScaffold(new ThemeGeneratorFactory(), $app['files']);
});
$this->app->singleton('command.asgard.theme.scaffold', function ($app) {
return new ThemeScaffoldCommand($app['asgard.theme.scaffold']);
});
}
/**
* Bind the theme manager
*/
private function bindThemeManager()
{
$this->app->singleton(ThemeManager::class, function ($app) {
return new StylistThemeManager($app['files']);
});
}
}