-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThemeServiceProvider.php
More file actions
164 lines (147 loc) · 4.63 KB
/
ThemeServiceProvider.php
File metadata and controls
164 lines (147 loc) · 4.63 KB
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
<?php
namespace Mods\Theme;
use Blade;
use Mods\Theme\Asset;
use Mods\Theme\Console\Command;
use Mods\Support\ServiceProvider;
use Mods\Theme\Compiler\Factory as ComplierFactory;
class ThemeServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
Blade::directive('asset_img', function ($expression) {
$area = app()->area();
$theme = app(\Mods\Theme\Factory::class)->getActiveTheme($area);
return asset("assets/{$area}/{$theme}/img/{$expression}");
});
}
/**
* Register any application services.
*
* @return void
*/
public function register()
{
$this->registerThemeDeployer();
$this->app->register(
\Mods\Theme\EventServiceProvider::class
);
$this->app->singleton('theme.asset.resolver', function ($app) {
return new AssetResolver($app['files']);
});
$this->app->singleton('theme.resolver', function ($app) {
return new ThemeResolver($app['files'], $app['config']);
});
$this->app->singleton('theme', function ($app) {
$env = new Factory(
$app['theme.resolver'],
$app['view'],
$app['events']
);
$env->setContainer($app);
return $env;
});
$this->app->booted(function ($app) {
$app['theme']->booted($app);
});
}
/**
* Register the command.
*
* @return void
*/
protected function registerThemeDeployer()
{
$this->app->singleton('command.theme.deploy', function ($app) {
return new Command\Deploy();
});
$this->app->singleton('command.theme.clear', function ($app) {
return new Command\Clear();
});
$this->app->singleton('command.theme.preprocessor', function ($app) {
return new Command\PreProcess();
});
$this->app->singleton('command.theme.compile', function ($app) {
return new Command\Compile();
});
$this->app->singleton('command.theme.webpack', function ($app) {
return new Command\Webpack();
});
$this->commands([
'command.theme.deploy', 'command.theme.clear',
'command.theme.preprocessor', 'command.theme.compile',
'command.theme.webpack'
]);
$this->app->singleton('theme.deployer', function ($app) {
return new Asset\Deployer(
$app['files'],
$app['theme.asset.resolver'],
$app['theme.resolver'],
$app['config'],
$app['events'],
$app['path.resources']
);
});
$this->app->singleton('theme.clear', function ($app) {
return new Asset\Clear(
$app['files'],
$app['theme.asset.resolver'],
$app['config'],
$app['path.resources'],
$app['path.public']
);
});
$this->app->singleton('theme.complier', function ($app) {
return new Asset\Complier(
$app['files'],
$app['theme.asset.complier'],
$app['path.resources']
);
});
$this->app->singleton('theme.asset.complier', function ($app) {
return new ComplierFactory(
$app['Illuminate\Pipeline\Pipeline'],
$app['config']->get('theme.compliers', [])
);
});
$this->app->singleton('theme.preprocessor', function ($app) {
return new Asset\PreProcess(
$app,
$app['files'],
$app['Mods\View\Factory'],
$app['theme.resolver'],
$app['config']
);
});
$this->app->singleton('theme.webpack', function ($app) {
return new Asset\Webpack(
$app,
$app['files'],
$app['theme.asset.resolver'],
$app['config'],
$app['path.resources'],
$app['path.public']
);
});
}
/**
* Get the services provided by the provider.
*
* @return array
*/
public function provides()
{
if (!$this->app->environment('production')) {
return [
'command.theme.deploy', 'command.theme.clear',
'command.theme.preprocessor', 'command.theme.compile',
'command.theme.webpack'
];
}
}
}