|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace UniSharp\LaravelFilemanager; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Support\Facades\Storage; |
|
6
|
|
|
|
|
7
|
|
|
class LfmStorageRepository |
|
8
|
|
|
{ |
|
9
|
|
|
private $disk; |
|
10
|
|
|
private $path; |
|
11
|
|
|
private $helper; |
|
12
|
|
|
|
|
13
|
|
|
public function __construct($storage_path, $helper) |
|
14
|
|
|
{ |
|
15
|
|
|
$this->helper = $helper; |
|
16
|
|
|
$this->disk = Storage::disk($this->helper->config('disk')); |
|
17
|
|
|
$this->path = $storage_path; |
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
|
public function __call($function_name, $arguments) |
|
21
|
|
|
{ |
|
22
|
|
|
// TODO: check function exists |
|
23
|
|
|
return $this->disk->$function_name($this->path, ...$arguments); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
public function rootPath() |
|
27
|
|
|
{ |
|
28
|
|
|
return $this->disk->path(''); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
public function move($new_lfm_path) |
|
32
|
|
|
{ |
|
33
|
|
|
return $this->disk->move($this->path, $new_lfm_path->path('storage')); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
public function save($file) |
|
37
|
|
|
{ |
|
38
|
|
|
$nameint = strripos($this->path, "/"); |
|
39
|
|
|
$nameclean = substr($this->path, $nameint + 1); |
|
40
|
|
|
$pathclean = substr_replace($this->path, "", $nameint); |
|
41
|
|
|
$this->disk->putFileAs($pathclean, $file, $nameclean, 'public'); |
|
|
|
|
|
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
public function url($path) |
|
45
|
|
|
{ |
|
46
|
|
|
return $this->disk->url($path); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
public function makeDirectory() |
|
50
|
|
|
{ |
|
51
|
|
|
$this->disk->makeDirectory($this->path, ...func_get_args()); |
|
|
|
|
|
|
52
|
|
|
|
|
53
|
|
|
// some filesystems (e.g. Google Storage, S3?) don't let you set ACLs on directories (because they don't exist) |
|
54
|
|
|
// https://cloud.google.com/storage/docs/naming#object-considerations |
|
55
|
|
|
if ($this->disk->has($this->path)) { |
|
|
|
|
|
|
56
|
|
|
$this->disk->setVisibility($this->path, 'public'); |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
public function extension() |
|
61
|
|
|
{ |
|
62
|
|
|
setlocale(LC_ALL, 'en_US.UTF-8'); |
|
63
|
|
|
return pathinfo($this->path, PATHINFO_EXTENSION); |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
|