Filters an asset after it has been loaded.
AssetInterface $asset An asset:
Overrides FilterInterface::filterLoad
public function filterLoad(AssetInterface $asset) {
$input = tempnam(sys_get_temp_dir(), 'assetic_dart');
$output = tempnam(sys_get_temp_dir(), 'assetic_dart');
file_put_contents($input, $asset
->getContent());
$pb = $this
->createProcessBuilder()
->add($this->dartBin)
->add('-o' . $output)
->add($input);
$proc = $pb
->getProcess();
$code = $proc
->run();
unlink($input);
if (0 !== $code) {
if (file_exists($output)) {
unlink($output);
}
throw FilterException::fromProcess($proc)
->setInput($asset
->getContent());
}
if (!file_exists($output)) {
throw new \RuntimeException('Error creating output file.');
}
$asset
->setContent(file_get_contents($output));
unlink($output);
}