-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathMinify.php
More file actions
47 lines (38 loc) · 1.21 KB
/
Minify.php
File metadata and controls
47 lines (38 loc) · 1.21 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
<?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;
use Sensiolabs\MinifyBundle\Exception\RuntimeException;
use Sensiolabs\MinifyBundle\Minifier\MinifierInterface;
use Symfony\Component\Process\Process;
/**
* @author Simon André <[email protected]>
*/
final class Minify implements MinifierInterface
{
public function __construct(
private readonly string $binaryPath,
) {
}
public function minify(string $input, string $type): string
{
$process = new Process([$this->binaryPath, '--type', $type]);
$process->setInput($input);
try {
$process->run();
} catch (\Throwable $e) {
throw new RuntimeException('Error during minify command: '.$e->getMessage(), 0, $e);
}
if (!$process->isSuccessful()) {
throw new RuntimeException(sprintf('Minify error %s: "%s".', $process->getExitCode(), $process->getExitCodeText()));
}
return $process->getOutput();
}
}