Skip to content

Commit 10ba1ee

Browse files
committed
Switch to using Middleware so it affects all laravel routes, not just statamic ones
1 parent 92d21ae commit 10ba1ee

File tree

2 files changed

+8
-11
lines changed

2 files changed

+8
-11
lines changed
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
<?php
22

3-
namespace Thoughtco\Minify\Listeners;
3+
namespace Thoughtco\Minify\Middleware;
44

5+
use Closure;
56
use File;
67
use MatthiasMullie\Minify;
7-
use Statamic\Events\ResponseCreated;
88

9-
class MinifyListener
9+
class MinifyMiddleware
1010
{
11-
1211
private $minPath = 'min/';
1312

1413
/**
1514
* before response sent back to browser
1615
*/
17-
public function handle(ResponseCreated $event)
16+
public function handle($request, Closure $next)
1817
{
1918
$content = $event->response->content();
2019
if (stripos($content, '<html') !== false)

src/ServiceProvider.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,20 @@
22

33
namespace Thoughtco\Minify;
44

5+
use Illuminate\Contracts\Http\;
56
use Illuminate\Support\Facades\File;
67
use Statamic\Providers\AddonServiceProvider;
78
use Statamic\Statamic;
9+
use Thoughtco\Minify\Middleware\MinifyMiddleware;
810

911
class ServiceProvider extends AddonServiceProvider
1012
{
11-
protected $listen = [
12-
'Statamic\Events\ResponseCreated' => [
13-
'Thoughtco\Minify\Listeners\MinifyListener',
14-
],
15-
];
16-
1713
public function boot()
1814
{
1915
parent::boot();
2016

17+
app(Kernel::class)->pushMiddleware(MinifyMiddleware::class);
18+
2119
Statamic::afterInstalled(function ($command) {
2220

2321
if (File::exists(config_path('thoughtco/minify.php')))

0 commit comments

Comments
 (0)