generated from shgysk8zer0/blank-repo
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
file.php
53 lines (43 loc) · 1.07 KB
/
file.php
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
50
51
52
53
<?php
namespace shgysk8zer0\HTTP;
use \shgysk8zer0\HTTP\Interfaces\FileInterface;
use \shgysk8zer0\HTTP\Traits\FileTrait;
use \JsonSerializable;
use \InvalidArgumentException;
class File implements JsonSerializable, FileInterface
{
use FileTrait;
public function __construct(
string $filename,
?string $mimetype = null,
?string $postname = ''
) {
if (! $this->_setFile($filename, $mimetype, $postname)) {
throw new InvalidArgumentException(sprintf('File %s not found', $filename));
}
}
public function jsonSerialize(): array
{
return [
'name' => $this->getFileName(),
'mime' => $this->getMimeType(),
'postname' => $this->getPostFileName(),
];
}
public function __debugInfo(): array
{
return [
'name' => $this->getFileName(),
'mime' => $this->getMimeType(),
'postname' => $this->getPostFileName(),
];
}
public function saveAs(string $path):? FileInterface
{
if (copy($this->getFileName(), $path)) {
return new self($path, $this->getMimeType(), $this->getPostFileName());
} else {
return null;
}
}
}