-
Notifications
You must be signed in to change notification settings - Fork 728
/
Copy pathLfmStorageRepository.php
93 lines (76 loc) · 2.55 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<?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)
{
if ($function_name == 'directories') {
$directories = $this->disk->directories($this->path, ...$arguments);
$config = $this->helper->config('private_folder_name');
if(method_exists(app()->make($config), 'userAuthDirs')) {
return $this->getAuthDirectories($directories, app()->make($config)->userAuthDirs());
} else {
return $directories;
}
} else {
// 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 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);
}
public function getAuthDirectories($directories, $auth_dirs)
{
$check = $directories;
if(count($auth_dirs)){
// remove unauthorized directories
foreach($check as $i => $directory) {
if(!in_array($directory, $auth_dirs)){
unset($directories[$i]);
}
}
}
return $directories;
}
}