cleanup when storing compiled file

This commit is contained in:
Philipp Lang 2022-12-14 15:53:58 +01:00
parent cdff8dded1
commit c985cb5fd9
1 changed files with 12 additions and 7 deletions

View File

@ -41,20 +41,20 @@ abstract class BaseCompiler implements Responsable
return $this;
}
public function storeAs(string $directory, string $name, string $disk): void
public function storeAs(string $directory, string $name, string $disk): string
{
$contents = $this->file->getContent();
Storage::disk($disk)->put($name, $contents);
Storage::disk($disk)->put($directory.'/'.$name, $contents);
$this->cleanup();
return $directory.'/'.$name;
}
public function storeIn(string $directory, string $disk): string
{
$contents = $this->file->getContent();
Storage::disk($disk)->put($directory.'/'.$this->file->getFilename(), $contents);
return $this->file->getFilename();
return $this->storeAs($directory, $this->file->getFilename(), $disk);
}
public function toResponse($request)
@ -90,4 +90,9 @@ abstract class BaseCompiler implements Responsable
$document->getEngine()->binary().' --halt-on-error '.escapeshellarg($document->filename()),
])->implode(' && ');
}
private function cleanup(): void
{
exec('rm -R '.$this->file->getPath());
}
}