1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* laravel-assets: asset management for Laravel 5 |
4
|
|
|
* Copyright (c) 2021 Greg Roach |
5
|
|
|
* This program is free software: you can redistribute it and/or modify |
6
|
|
|
* it under the terms of the GNU General Public License as published by |
7
|
|
|
* the Free Software Foundation, either version 3 of the License, or |
8
|
|
|
* (at your option) any later version. |
9
|
|
|
* This program is distributed in the hope that it will be useful, |
10
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
11
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12
|
|
|
* GNU General Public License for more details. |
13
|
|
|
* You should have received a copy of the GNU General Public License |
14
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>. |
15
|
|
|
*/ |
16
|
|
|
|
17
|
|
|
namespace Fisharebest\LaravelAssets\Filters; |
18
|
|
|
|
19
|
|
|
use Fisharebest\LaravelAssets\Assets; |
20
|
|
|
use Fisharebest\LaravelAssets\SetStateTrait; |
21
|
|
|
use tubalmartin\CssMin\Minifier; |
22
|
|
|
|
23
|
|
|
class MinifyCss implements FilterInterface |
24
|
|
|
{ |
25
|
|
|
use SetStateTrait; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Reduce the size of CSS files, using mrclay/minify compressor. |
29
|
|
|
* |
30
|
|
|
* @param string $data The data to be filtered |
31
|
|
|
* @param string $asset_url The original URL for this data |
32
|
|
|
* @param Assets $assets The asset manager object, for access to its config settings and utilities |
33
|
|
|
* |
34
|
|
|
* @return string |
35
|
|
|
*/ |
36
|
|
|
public function filter($data, $asset_url, $assets) |
37
|
|
|
{ |
38
|
|
|
if (!preg_match(Assets::REGEX_MINIFIED_CSS, $asset_url)) { |
39
|
|
|
$data = (new Minifier())->run($data); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
return $data; |
43
|
|
|
} |
44
|
|
|
} |
45
|
|
|
|