1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace rdx\filemanager; |
4
|
|
|
|
5
|
|
|
use Illuminate\Http\File; |
6
|
|
|
use rdx\filemanager\FileUsageContract; |
7
|
|
|
use rdx\filemanager\FileManager; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* @property string $fullpath |
11
|
|
|
*/ |
12
|
|
|
class ManagedFile { |
13
|
|
|
|
14
|
|
|
protected $manager; |
15
|
|
|
|
16
|
|
|
public $id = 0; |
17
|
|
|
public $filename; |
18
|
|
|
public $filepath; |
19
|
|
|
public $created_at; |
20
|
|
|
public $created_by; |
21
|
|
|
public $file; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* |
25
|
|
|
*/ |
26
|
|
|
public function __construct(FileManager $manager, array $params) { |
27
|
|
|
$this->manager = $manager; |
28
|
|
|
|
29
|
|
|
foreach ($params as $property => $value) { |
30
|
|
|
$this->$property = $value; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
if ($this->filepath) { |
34
|
|
|
$this->file = new File($this->fullpath, false); |
35
|
|
|
} |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* |
40
|
|
|
*/ |
41
|
|
|
public function getUsageCount() { |
42
|
|
|
return $this->manager->getUsageCount($this); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* |
47
|
|
|
*/ |
48
|
|
|
public function getUsages() { |
49
|
|
|
return $this->manager->getUsages($this); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* |
54
|
|
|
*/ |
55
|
|
|
public function addUsage(FileUsageContract $usage) { |
56
|
|
|
return $this->manager->addUsage($usage, $this); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* |
61
|
|
|
*/ |
62
|
|
|
public function replaceUsage(FileUsageContract $usage) { |
63
|
|
|
return $this->manager->replaceUsage($usage, $this); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* |
68
|
|
|
*/ |
69
|
|
|
public function webPath($publisher) { |
70
|
|
|
return $this->manager->resolveWebPath($publisher, $this->filepath); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* |
75
|
|
|
*/ |
76
|
|
|
public function publicPath($publisher) { |
77
|
|
|
return $this->manager->resolvePublicPath($publisher, $this->filepath); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* |
82
|
|
|
*/ |
83
|
|
|
public function __get($name) { |
84
|
|
|
if ($name == 'fullpath') { |
85
|
|
|
return $this->manager->resolveStoragePath($this->filepath); |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
} |
90
|
|
|
|