-
-
Notifications
You must be signed in to change notification settings - Fork 37
/
Asset.php
58 lines (47 loc) · 1.25 KB
/
Asset.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
54
55
56
57
58
<?php
declare(strict_types=1);
namespace Oneduo\NovaFileManager\Support;
use Illuminate\Contracts\Filesystem\Filesystem;
use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Traits\ForwardsCalls;
use JsonSerializable;
/**
* @mixin \Illuminate\Contracts\Filesystem\Filesystem
*/
class Asset implements Arrayable, JsonSerializable
{
use ForwardsCalls;
public function __construct(
public string $disk,
public string $path,
public ?Filesystem $filesystem = null,
) {
}
public function __call(string $name, array $arguments)
{
return $this->forwardCallTo($this->filesystem(), $name, $arguments);
}
public function filesystem(): Filesystem
{
if (!$this->filesystem) {
$this->filesystem = Storage::disk($this->disk);
}
return $this->filesystem;
}
public function toArray(): array
{
return [
'disk' => $this->disk,
'path' => $this->path,
];
}
public function jsonSerialize(): array
{
return $this->toArray();
}
public function __toString(): string
{
return json_encode($this->jsonSerialize(), JSON_THROW_ON_ERROR);
}
}