Skip to content

Commit 751cb13

Browse files
Moved to L5 native config
1 parent 39548e1 commit 751cb13

File tree

4 files changed

+65
-39
lines changed

4 files changed

+65
-39
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,16 @@ Checkout the [2.1 branch](https://github.com/GrahamCampbell/Laravel-HTMLMin/tree
4141

4242
## Configuration
4343

44-
Laravel HTMLMin supports optional configuration through [orchestral/config](https://github.com/orchestral/config).
44+
Laravel HTMLMin supports optional configuration.
4545

46-
If you want an automated way to publish the config, then install [orchestral/publisher](https://github.com/orchestral/publisher).
47-
48-
You can then publish the config file by running:
46+
To get started, you'll need to publish all vendor assets:
4947

5048
```bash
51-
$ php artisan publish:config graham-campbell/htmlmin
49+
$ php artisan vendor:publish
5250
```
5351

52+
This will create a `config/htmlmin.php` file in your app that you can modify to set your configuration. Also, make sure you check for changes to the original config file in this package between releases.
53+
5454
There are a few config options:
5555

5656
##### Automatic Blade Optimizations

composer.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
"illuminate/routing": "5.0.*",
1717
"illuminate/support": "5.0.*",
1818
"illuminate/view": "5.0.*",
19-
"orchestra/config": "3.0.*",
20-
"orchestra/support-providers": "3.0.*",
2119
"mrclay/minify": "~2.2"
2220
},
2321
"require-dev": {
File renamed without changes.

src/HTMLMinServiceProvider.php

Lines changed: 60 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
namespace GrahamCampbell\HTMLMin;
1313

1414
use Illuminate\Contracts\Foundation\Application;
15+
use Illuminate\Support\ServiceProvider;
1516
use Illuminate\View\Engines\CompilerEngine;
16-
use Orchestra\Support\Providers\ServiceProvider;
1717

1818
/**
1919
* This is the htmlmin service provider class.
@@ -29,17 +29,33 @@ class HTMLMinServiceProvider extends ServiceProvider
2929
*/
3030
public function boot()
3131
{
32-
$this->addConfigComponent('graham-campbell/htmlmin', 'graham-campbell/htmlmin', realpath(__DIR__.'/../config'));
32+
$this->setupConfig($this->app);
3333

34-
if ($this->app['config']['graham-campbell/htmlmin::blade']) {
34+
if ($this->app->config->get('htmlmin.blade')) {
3535
$this->enableBladeOptimisations($this->app);
3636
}
3737

38-
if ($this->app['config']['graham-campbell/htmlmin::live']) {
38+
if ($this->app->config->get('htmlmin.live')) {
3939
$this->enableLiveOptimisations($this->app);
4040
}
4141

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);
4359
}
4460

4561
/**
@@ -77,12 +93,12 @@ protected function enableLiveOptimisations(Application $app)
7793
/**
7894
* Setup the filters.
7995
*
96+
* @param \Illuminate\Contracts\Foundation\Application $app
97+
*
8098
* @return void
8199
*/
82-
protected function setupFilters()
100+
protected function setupFilters(Application $app)
83101
{
84-
$app = $this->app;
85-
86102
$app['router']->filter('htmlmin', function ($route, $request, $response) use ($app) {
87103
$app['htmlmin']->live($response);
88104
});
@@ -95,101 +111,113 @@ protected function setupFilters()
95111
*/
96112
public function register()
97113
{
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);
104120
}
105121

106122
/**
107123
* Register the css minifier class.
108124
*
125+
* @param \Illuminate\Contracts\Foundation\Application $app
126+
*
109127
* @return void
110128
*/
111-
protected function registerCssMinifier()
129+
protected function registerCssMinifier(Application $app)
112130
{
113-
$this->app->singleton('htmlmin.css', function ($app) {
131+
$app->singleton('htmlmin.css', function ($app) {
114132
return new Minifiers\CssMinifier();
115133
});
116134

117-
$this->app->alias('htmlmin.css', 'GrahamCampbell\HTMLMin\Minifiers\CssMinifier');
135+
$app->alias('htmlmin.css', 'GrahamCampbell\HTMLMin\Minifiers\CssMinifier');
118136
}
119137

120138
/**
121139
* Register the js minifier class.
122140
*
141+
* @param \Illuminate\Contracts\Foundation\Application $app
142+
*
123143
* @return void
124144
*/
125-
protected function registerJsMinifier()
145+
protected function registerJsMinifier(Application $app)
126146
{
127-
$this->app->singleton('htmlmin.js', function ($app) {
147+
$app->singleton('htmlmin.js', function ($app) {
128148
return new Minifiers\JsMinifier();
129149
});
130150

131-
$this->app->alias('htmlmin.js', 'GrahamCampbell\HTMLMin\Minifiers\JsMinifier');
151+
$app->alias('htmlmin.js', 'GrahamCampbell\HTMLMin\Minifiers\JsMinifier');
132152
}
133153

134154
/**
135155
* Register the html minifier class.
136156
*
157+
* @param \Illuminate\Contracts\Foundation\Application $app
158+
*
137159
* @return void
138160
*/
139-
protected function registerHtmlMinifier()
161+
protected function registerHtmlMinifier(Application $app)
140162
{
141-
$this->app->singleton('htmlmin.html', function ($app) {
163+
$app->singleton('htmlmin.html', function ($app) {
142164
$css = $app['htmlmin.css'];
143165
$js = $app['htmlmin.js'];
144166

145167
return new Minifiers\HtmlMinifier($css, $js);
146168
});
147169

148-
$this->app->alias('htmlmin.html', 'GrahamCampbell\HTMLMin\Minifiers\HtmlMinifier');
170+
$app->alias('htmlmin.html', 'GrahamCampbell\HTMLMin\Minifiers\HtmlMinifier');
149171
}
150172

151173
/**
152174
* Register the blade minifier class.
153175
*
176+
* @param \Illuminate\Contracts\Foundation\Application $app
177+
*
154178
* @return void
155179
*/
156-
protected function registerBladeMinifier()
180+
protected function registerBladeMinifier(Application $app)
157181
{
158-
$this->app->singleton('htmlmin.blade', function ($app) {
182+
$app->singleton('htmlmin.blade', function ($app) {
159183
$force = $app['config']['graham-campbell/htmlmin::force'];
160184

161185
return new Minifiers\BladeMinifier($force);
162186
});
163187

164-
$this->app->alias('htmlmin.blade', 'GrahamCampbell\HTMLMin\Minifiers\BladeMinifier');
188+
$app->alias('htmlmin.blade', 'GrahamCampbell\HTMLMin\Minifiers\BladeMinifier');
165189
}
166190

167191
/**
168192
* Register the minify compiler class.
169193
*
194+
* @param \Illuminate\Contracts\Foundation\Application $app
195+
*
170196
* @return void
171197
*/
172-
protected function registerMinifyCompiler()
198+
protected function registerMinifyCompiler(Application $app)
173199
{
174-
$this->app->singleton('htmlmin.compiler', function ($app) {
200+
$app->singleton('htmlmin.compiler', function ($app) {
175201
$blade = $app['htmlmin.blade'];
176202
$files = $app['files'];
177203
$storagePath = $app['config']['view.compiled'];
178204

179205
return new Compilers\MinifyCompiler($blade, $files, $storagePath);
180206
});
181207

182-
$this->app->alias('htmlmin.compiler', 'GrahamCampbell\HTMLMin\Compilers\MinifyCompiler');
208+
$app->alias('htmlmin.compiler', 'GrahamCampbell\HTMLMin\Compilers\MinifyCompiler');
183209
}
184210

185211
/**
186212
* Register the htmlmin class.
187213
*
214+
* @param \Illuminate\Contracts\Foundation\Application $app
215+
*
188216
* @return void
189217
*/
190-
protected function registerHTMLMin()
218+
protected function registerHTMLMin(Application $app)
191219
{
192-
$this->app->singleton('htmlmin', function ($app) {
220+
$app->singleton('htmlmin', function ($app) {
193221
$blade = $app['htmlmin.blade'];
194222
$css = $app['htmlmin.css'];
195223
$js = $app['htmlmin.js'];
@@ -198,7 +226,7 @@ protected function registerHTMLMin()
198226
return new HTMLMin($blade, $css, $js, $html);
199227
});
200228

201-
$this->app->alias('htmlmin', 'GrahamCampbell\HTMLMin\HTMLMin');
229+
$app->alias('htmlmin', 'GrahamCampbell\HTMLMin\HTMLMin');
202230
}
203231

204232
/**

0 commit comments

Comments
 (0)