-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathJSignFileService.php
More file actions
49 lines (42 loc) · 1.21 KB
/
JSignFileService.php
File metadata and controls
49 lines (42 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
48
49
<?php
namespace Jeidison\JSignPDF;
/**
* @author Jeidison Farias <jeidison.farias@gmail.com>
*/
class JSignFileService
{
public static function instance(): self
{
return new self();
}
public function contentFile(string $path, bool $isInBase64 = false): string
{
$content = file_get_contents($path);
if ($content === false) {
return '';
}
return $isInBase64 ? base64_encode($content) : $content;
}
public function storeFile(string $path, string $name, string $content): string
{
$filename = $path . $name;
file_put_contents($filename, $content);
return $filename;
}
public function deleteFile(string $path): void
{
if (is_file($path)) {
unlink($path);
}
}
public function deleteTempFiles(string $pathTemp, string $name): void
{
$pathPfxFile = "$pathTemp$name.pfx";
$pathPdfFile = "$pathTemp$name.pdf";
$pathPdfSignedFile = "{$pathTemp}{$name}_signed.pdf";
$tempFiles = [$pathPfxFile, $pathPdfFile, $pathPdfSignedFile];
foreach ($tempFiles as $path) {
$this->deleteFile($path);
}
}
}