-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathTraceableMinifier.php
More file actions
57 lines (47 loc) · 1.74 KB
/
Copy pathTraceableMinifier.php
File metadata and controls
57 lines (47 loc) · 1.74 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
<?php
declare(strict_types=1);
/*
* This file is part of the SensioLabs MinifyBundle package.
*
* (c) Simon André - Sensiolabs
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sensiolabs\MinifyBundle\Minifier;
use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;
/**
* @author Simon André <smn.andre@gmail.com>
*/
final class TraceableMinifier implements MinifierInterface
{
public function __construct(
private readonly MinifierInterface $minifier,
private readonly LoggerInterface $logger = new NullLogger(),
) {
}
public function minify(string $input, string $type/* , ?\Sensiolabs\MinifyBundle\Minifier\Options\OptionsInterface $options = null */): string
{
$inputSize = strlen($input);
$this->logger->debug('Minify command input: {inputSize} kB', [
'inputSize' => round($inputSize / 1024, 1),
'input' => $input,
]);
$timeStart = microtime(true);
$output = $this->minifier->minify(...\func_get_args());
$timeEnd = microtime(true);
$outputSize = strlen($output);
$this->logger->debug('Minify command output: {outputSize} kB', [
'output' => $output,
'outputSize' => round($outputSize / 1024, 1),
]);
$this->logger->info('Minified asset type {type}: reduced {ratio} % in {duration} ms.', [
'type' => $type,
'ratio' => abs((int) ($inputSize > 0 ? ($outputSize - $inputSize) / $inputSize * 100 : 0)),
'duration' => (int) (($timeEnd - $timeStart) * 1000),
'sizeDiff' => round(($outputSize - $inputSize) / 1024, 1),
]);
return $output;
}
}