12
12
namespace GrahamCampbell \HTMLMin ;
13
13
14
14
use Illuminate \Contracts \Foundation \Application ;
15
+ use Illuminate \Support \ServiceProvider ;
15
16
use Illuminate \View \Engines \CompilerEngine ;
16
- use Orchestra \Support \Providers \ServiceProvider ;
17
17
18
18
/**
19
19
* This is the htmlmin service provider class.
@@ -29,17 +29,33 @@ class HTMLMinServiceProvider extends ServiceProvider
29
29
*/
30
30
public function boot ()
31
31
{
32
- $ this ->addConfigComponent ( ' graham-campbell/htmlmin ' , ' graham-campbell/htmlmin ' , realpath ( __DIR__ . ' /../config ' ) );
32
+ $ this ->setupConfig ( $ this -> app );
33
33
34
- if ($ this ->app [ ' config ' ][ ' graham-campbell/ htmlmin:: blade '] ) {
34
+ if ($ this ->app -> config -> get ( ' htmlmin. blade ') ) {
35
35
$ this ->enableBladeOptimisations ($ this ->app );
36
36
}
37
37
38
- if ($ this ->app [ ' config ' ][ ' graham-campbell/ htmlmin:: live '] ) {
38
+ if ($ this ->app -> config -> get ( ' htmlmin. live ') ) {
39
39
$ this ->enableLiveOptimisations ($ this ->app );
40
40
}
41
41
42
- $ this ->setupFilters ();
42
+ $ this ->setupFilters ($ this ->app );
43
+ }
44
+
45
+ /**
46
+ * Setup the config.
47
+ *
48
+ * @param \Illuminate\Contracts\Foundation\Application $app
49
+ *
50
+ * @return void
51
+ */
52
+ protected function setupConfig (Application $ app )
53
+ {
54
+ $ source = realpath (__DIR__ .'/../config/htmlmin.php ' );
55
+
56
+ $ this ->publishes ([$ source => config_path ('htmlmin.php ' )]);
57
+
58
+ $ this ->mergeConfigFrom ('htmlmin ' , $ source );
43
59
}
44
60
45
61
/**
@@ -77,12 +93,12 @@ protected function enableLiveOptimisations(Application $app)
77
93
/**
78
94
* Setup the filters.
79
95
*
96
+ * @param \Illuminate\Contracts\Foundation\Application $app
97
+ *
80
98
* @return void
81
99
*/
82
- protected function setupFilters ()
100
+ protected function setupFilters (Application $ app )
83
101
{
84
- $ app = $ this ->app ;
85
-
86
102
$ app ['router ' ]->filter ('htmlmin ' , function ($ route , $ request , $ response ) use ($ app ) {
87
103
$ app ['htmlmin ' ]->live ($ response );
88
104
});
@@ -95,101 +111,113 @@ protected function setupFilters()
95
111
*/
96
112
public function register ()
97
113
{
98
- $ this ->registerJsMinifier ();
99
- $ this ->registerCssMinifier ();
100
- $ this ->registerHtmlMinifier ();
101
- $ this ->registerBladeMinifier ();
102
- $ this ->registerMinifyCompiler ();
103
- $ this ->registerHTMLMin ();
114
+ $ this ->registerJsMinifier ($ this -> app );
115
+ $ this ->registerCssMinifier ($ this -> app );
116
+ $ this ->registerHtmlMinifier ($ this -> app );
117
+ $ this ->registerBladeMinifier ($ this -> app );
118
+ $ this ->registerMinifyCompiler ($ this -> app );
119
+ $ this ->registerHTMLMin ($ this -> app );
104
120
}
105
121
106
122
/**
107
123
* Register the css minifier class.
108
124
*
125
+ * @param \Illuminate\Contracts\Foundation\Application $app
126
+ *
109
127
* @return void
110
128
*/
111
- protected function registerCssMinifier ()
129
+ protected function registerCssMinifier (Application $ app )
112
130
{
113
- $ this -> app ->singleton ('htmlmin.css ' , function ($ app ) {
131
+ $ app ->singleton ('htmlmin.css ' , function ($ app ) {
114
132
return new Minifiers \CssMinifier ();
115
133
});
116
134
117
- $ this -> app ->alias ('htmlmin.css ' , 'GrahamCampbell\HTMLMin\Minifiers\CssMinifier ' );
135
+ $ app ->alias ('htmlmin.css ' , 'GrahamCampbell\HTMLMin\Minifiers\CssMinifier ' );
118
136
}
119
137
120
138
/**
121
139
* Register the js minifier class.
122
140
*
141
+ * @param \Illuminate\Contracts\Foundation\Application $app
142
+ *
123
143
* @return void
124
144
*/
125
- protected function registerJsMinifier ()
145
+ protected function registerJsMinifier (Application $ app )
126
146
{
127
- $ this -> app ->singleton ('htmlmin.js ' , function ($ app ) {
147
+ $ app ->singleton ('htmlmin.js ' , function ($ app ) {
128
148
return new Minifiers \JsMinifier ();
129
149
});
130
150
131
- $ this -> app ->alias ('htmlmin.js ' , 'GrahamCampbell\HTMLMin\Minifiers\JsMinifier ' );
151
+ $ app ->alias ('htmlmin.js ' , 'GrahamCampbell\HTMLMin\Minifiers\JsMinifier ' );
132
152
}
133
153
134
154
/**
135
155
* Register the html minifier class.
136
156
*
157
+ * @param \Illuminate\Contracts\Foundation\Application $app
158
+ *
137
159
* @return void
138
160
*/
139
- protected function registerHtmlMinifier ()
161
+ protected function registerHtmlMinifier (Application $ app )
140
162
{
141
- $ this -> app ->singleton ('htmlmin.html ' , function ($ app ) {
163
+ $ app ->singleton ('htmlmin.html ' , function ($ app ) {
142
164
$ css = $ app ['htmlmin.css ' ];
143
165
$ js = $ app ['htmlmin.js ' ];
144
166
145
167
return new Minifiers \HtmlMinifier ($ css , $ js );
146
168
});
147
169
148
- $ this -> app ->alias ('htmlmin.html ' , 'GrahamCampbell\HTMLMin\Minifiers\HtmlMinifier ' );
170
+ $ app ->alias ('htmlmin.html ' , 'GrahamCampbell\HTMLMin\Minifiers\HtmlMinifier ' );
149
171
}
150
172
151
173
/**
152
174
* Register the blade minifier class.
153
175
*
176
+ * @param \Illuminate\Contracts\Foundation\Application $app
177
+ *
154
178
* @return void
155
179
*/
156
- protected function registerBladeMinifier ()
180
+ protected function registerBladeMinifier (Application $ app )
157
181
{
158
- $ this -> app ->singleton ('htmlmin.blade ' , function ($ app ) {
182
+ $ app ->singleton ('htmlmin.blade ' , function ($ app ) {
159
183
$ force = $ app ['config ' ]['graham-campbell/htmlmin::force ' ];
160
184
161
185
return new Minifiers \BladeMinifier ($ force );
162
186
});
163
187
164
- $ this -> app ->alias ('htmlmin.blade ' , 'GrahamCampbell\HTMLMin\Minifiers\BladeMinifier ' );
188
+ $ app ->alias ('htmlmin.blade ' , 'GrahamCampbell\HTMLMin\Minifiers\BladeMinifier ' );
165
189
}
166
190
167
191
/**
168
192
* Register the minify compiler class.
169
193
*
194
+ * @param \Illuminate\Contracts\Foundation\Application $app
195
+ *
170
196
* @return void
171
197
*/
172
- protected function registerMinifyCompiler ()
198
+ protected function registerMinifyCompiler (Application $ app )
173
199
{
174
- $ this -> app ->singleton ('htmlmin.compiler ' , function ($ app ) {
200
+ $ app ->singleton ('htmlmin.compiler ' , function ($ app ) {
175
201
$ blade = $ app ['htmlmin.blade ' ];
176
202
$ files = $ app ['files ' ];
177
203
$ storagePath = $ app ['config ' ]['view.compiled ' ];
178
204
179
205
return new Compilers \MinifyCompiler ($ blade , $ files , $ storagePath );
180
206
});
181
207
182
- $ this -> app ->alias ('htmlmin.compiler ' , 'GrahamCampbell\HTMLMin\Compilers\MinifyCompiler ' );
208
+ $ app ->alias ('htmlmin.compiler ' , 'GrahamCampbell\HTMLMin\Compilers\MinifyCompiler ' );
183
209
}
184
210
185
211
/**
186
212
* Register the htmlmin class.
187
213
*
214
+ * @param \Illuminate\Contracts\Foundation\Application $app
215
+ *
188
216
* @return void
189
217
*/
190
- protected function registerHTMLMin ()
218
+ protected function registerHTMLMin (Application $ app )
191
219
{
192
- $ this -> app ->singleton ('htmlmin ' , function ($ app ) {
220
+ $ app ->singleton ('htmlmin ' , function ($ app ) {
193
221
$ blade = $ app ['htmlmin.blade ' ];
194
222
$ css = $ app ['htmlmin.css ' ];
195
223
$ js = $ app ['htmlmin.js ' ];
@@ -198,7 +226,7 @@ protected function registerHTMLMin()
198
226
return new HTMLMin ($ blade , $ css , $ js , $ html );
199
227
});
200
228
201
- $ this -> app ->alias ('htmlmin ' , 'GrahamCampbell\HTMLMin\HTMLMin ' );
229
+ $ app ->alias ('htmlmin ' , 'GrahamCampbell\HTMLMin\HTMLMin ' );
202
230
}
203
231
204
232
/**
0 commit comments