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); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function url($path) |
45
|
|
|
{ |
46
|
|
|
$config = $this->disk->getConfig(); |
47
|
|
|
|
48
|
|
|
if (key_exists('driver', $config) && $config['driver'] == 's3') |
49
|
|
|
|
50
|
|
|
$duration = $this->helper->config('s3.temporary_url_expiration'); |
51
|
|
|
return $this->disk->temporaryUrl($path, now()->addMinutes($duration)); |
52
|
|
|
|
53
|
|
|
else { |
|
|
|
|
54
|
|
|
return $this->disk->url($path); |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function makeDirectory() |
59
|
|
|
{ |
60
|
|
|
$this->disk->makeDirectory($this->path, ...func_get_args()); |
61
|
|
|
|
62
|
|
|
// some filesystems (e.g. Google Storage, S3?) don't let you set ACLs on directories (because they don't exist) |
63
|
|
|
// https://cloud.google.com/storage/docs/naming#object-considerations |
64
|
|
|
if ($this->disk->has($this->path)) { |
65
|
|
|
$this->disk->setVisibility($this->path, 'public'); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public function extension() |
70
|
|
|
{ |
71
|
|
|
setlocale(LC_ALL, 'en_US.UTF-8'); |
72
|
|
|
return pathinfo($this->path, PATHINFO_EXTENSION); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|