forked from UniSharp/laravel-filemanager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLfmStorageRepository.php
65 lines (53 loc) · 1.69 KB
/
LfmStorageRepository.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
59
60
61
62
63
64
65
<?php
namespace UniSharp\LaravelFilemanager;
use Illuminate\Support\Facades\Storage;
class LfmStorageRepository
{
private $disk;
private $path;
private $helper;
public function __construct($storage_path, $helper)
{
$this->helper = $helper;
$this->disk = Storage::disk($this->helper->config('disk'));
$this->path = $storage_path;
}
public function __call($function_name, $arguments)
{
// TODO: check function exists
return $this->disk->$function_name($this->path, ...$arguments);
}
public function rootPath()
{
return $this->disk->path('');
}
public function move($new_lfm_path)
{
return $this->disk->move($this->path, $new_lfm_path->path('storage'));
}
public function save($file)
{
$nameint = strripos($this->path, "/");
$nameclean = substr($this->path, $nameint + 1);
$pathclean = substr_replace($this->path, "", $nameint);
$this->disk->putFileAs($pathclean, $file, $nameclean, 'public');
}
public function url($path)
{
return $this->disk->url($path);
}
public function makeDirectory()
{
$this->disk->makeDirectory($this->path, ...func_get_args());
// some filesystems (e.g. Google Storage, S3?) don't let you set ACLs on directories (because they don't exist)
// https://cloud.google.com/storage/docs/naming#object-considerations
if ($this->disk->has($this->path)) {
$this->disk->setVisibility($this->path, 'public');
}
}
public function extension()
{
setlocale(LC_ALL, 'en_US.UTF-8');
return pathinfo($this->path, PATHINFO_EXTENSION);
}
}