|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Pbmedia\LaravelFFMpeg\Filesystem; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Filesystem\FilesystemAdapter; |
|
6
|
|
|
use Spatie\TemporaryDirectory\TemporaryDirectory; |
|
7
|
|
|
|
|
8
|
|
|
class Media |
|
9
|
|
|
{ |
|
10
|
|
|
private Disk $disk; |
|
11
|
|
|
private $path; |
|
12
|
|
|
private ?TemporaryDirectory $temporaryDirectory = null; |
|
13
|
|
|
|
|
14
|
|
|
public function __construct(Disk $disk, $path) |
|
15
|
|
|
{ |
|
16
|
|
|
$this->disk = $disk; |
|
17
|
|
|
$this->path = $path; |
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
|
public static function make($disk, $path): self |
|
21
|
|
|
{ |
|
22
|
|
|
return new static(Disk::make($disk), $path); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
public function getDisk(): Disk |
|
26
|
|
|
{ |
|
27
|
|
|
return $this->disk; |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
public function getPath(): string |
|
31
|
|
|
{ |
|
32
|
|
|
return $this->path; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
public function getFilenameWithoutExtension(): string |
|
36
|
|
|
{ |
|
37
|
|
|
return pathinfo($this->getPath())['filename']; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
private function temporaryDirectoryAdapter(): FilesystemAdapter |
|
41
|
|
|
{ |
|
42
|
|
|
return app('filesystem')->createLocalDriver( |
|
43
|
|
|
['root' => $this->temporaryDirectory->path()] |
|
|
|
|
|
|
44
|
|
|
); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public function getLocalPath(): string |
|
48
|
|
|
{ |
|
49
|
|
|
$disk = $this->getDisk(); |
|
50
|
|
|
$path = $this->getPath(); |
|
51
|
|
|
|
|
52
|
|
|
if ($disk->isLocalDisk()) { |
|
53
|
|
|
return $disk->path($path); |
|
|
|
|
|
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
if (!$this->temporaryDirectory) { |
|
57
|
|
|
$this->temporaryDirectory = $disk->getTemporaryDirectory(); |
|
58
|
|
|
|
|
59
|
|
|
if ($disk->exists($path)) { |
|
|
|
|
|
|
60
|
|
|
$this->temporaryDirectoryAdapter()->writeStream($path, $disk->readStream($path)); |
|
|
|
|
|
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
return $this->temporaryDirectoryAdapter()->path($path); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
public function copyAllFromTemporaryDirectory(string $visibility = null) |
|
68
|
|
|
{ |
|
69
|
|
|
if (!$this->temporaryDirectory) { |
|
70
|
|
|
return $this; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
$temporaryDirectoryAdapter = $this->temporaryDirectoryAdapter(); |
|
74
|
|
|
|
|
75
|
|
|
$destinationAdapater = $this->getDisk()->getFilesystemAdapter(); |
|
76
|
|
|
|
|
77
|
|
|
foreach ($temporaryDirectoryAdapter->allFiles() as $path) { |
|
78
|
|
|
$destinationAdapater->writeStream($path, $temporaryDirectoryAdapter->readStream($path)); |
|
79
|
|
|
|
|
80
|
|
|
if ($visibility) { |
|
81
|
|
|
$destinationAdapater->setVisibility($path, $visibility); |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
return $this; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
public function setVisibility(string $visibility = null) |
|
89
|
|
|
{ |
|
90
|
|
|
$disk = $this->getDisk(); |
|
91
|
|
|
|
|
92
|
|
|
if ($visibility && $disk->isLocalDisk()) { |
|
93
|
|
|
$disk->setVisibility($visibility); |
|
|
|
|
|
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
return $this; |
|
97
|
|
|
} |
|
98
|
|
|
} |
|
99
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.