-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathRasterizer.php
More file actions
41 lines (29 loc) · 988 Bytes
/
Rasterizer.php
File metadata and controls
41 lines (29 loc) · 988 Bytes
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
<?php
namespace Padam87\RasterizeBundle;
use Symfony\Component\Process\InputStream;
use Symfony\Component\Stopwatch\Stopwatch;
class Rasterizer
{
public function __construct(protected ConfigHelper $configHelper, protected ?Stopwatch $stopwatch = null)
{
}
public function rasterize(string $html, array $arguments = [], array $env = [], ?callable $callback = null): string
{
if ($this->stopwatch instanceof Stopwatch) {
$this->stopwatch->start('rasterizer');
}
$input = new InputStream();
$process = $this->configHelper->buildProcess($input, $arguments, $env);
if ($callback !== null) {
$callback($process);
}
$process->start(null, []);
$input->write($html);
$input->close();
$process->wait();
if ($this->stopwatch instanceof Stopwatch) {
$this->stopwatch->stop('rasterizer');
}
return $process->getOutput();
}
}