1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Mostafaznv\Larupload\Concerns\Storage\UploadEntity; |
4
|
|
|
|
5
|
|
|
use Illuminate\Http\UploadedFile; |
6
|
|
|
use Mostafaznv\Larupload\Enums\LaruploadFileType; |
7
|
|
|
use Mostafaznv\Larupload\Enums\LaruploadMode; |
8
|
|
|
use Mostafaznv\Larupload\Enums\LaruploadSecureIdsMethod; |
9
|
|
|
use Mostafaznv\Larupload\UploadEntities; |
10
|
|
|
|
11
|
|
|
trait UploadEntityProperties |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* File object |
15
|
|
|
* |
16
|
|
|
* @var UploadedFile|mixed |
17
|
|
|
*/ |
18
|
|
|
protected mixed $file; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Cover Object |
22
|
|
|
* |
23
|
|
|
* @var UploadedFile|mixed |
24
|
|
|
*/ |
25
|
|
|
protected mixed $cover; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Model ID / Secure ID |
29
|
|
|
* This property will be initiated only on retrieving model. |
30
|
|
|
*/ |
31
|
|
|
protected string $id; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Type of file in Larupload ecosystem |
35
|
|
|
* |
36
|
|
|
* @var LaruploadFileType|null |
37
|
|
|
*/ |
38
|
|
|
protected ?LaruploadFileType $type; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Mode of uploadable entity |
42
|
|
|
*/ |
43
|
|
|
protected LaruploadMode $mode; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Specify whether Larupload should generate a cover image for images and videos or not. |
47
|
|
|
*/ |
48
|
|
|
protected bool $generateCover; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Dominant color flag |
52
|
|
|
* |
53
|
|
|
* @var boolean |
54
|
|
|
*/ |
55
|
|
|
protected bool $dominantColor; |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Dominant color quality |
59
|
|
|
* |
60
|
|
|
* @var int |
61
|
|
|
*/ |
62
|
|
|
protected int $dominantColorQuality = 10; |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Specify whether Larupload should Keep old files or not |
66
|
|
|
*/ |
67
|
|
|
protected bool $keepOldFiles; |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Specify whether Larupload should preserve files or not |
71
|
|
|
*/ |
72
|
|
|
protected bool $preserveFiles; |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Specify whether Larupload should store Original File Name |
76
|
|
|
*/ |
77
|
|
|
protected bool $storeOriginalFileName; |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Specify whether Larupload should optimize image or not |
81
|
|
|
*/ |
82
|
|
|
protected bool $optimizeImage; |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Specify SecurityIDs Method |
86
|
|
|
*/ |
87
|
|
|
protected LaruploadSecureIdsMethod $secureIdsMethod; |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Uploaded flag to prevent infinite loop |
91
|
|
|
*/ |
92
|
|
|
protected bool $uploaded = false; |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Output array to save in database |
96
|
|
|
* |
97
|
|
|
* @var array |
98
|
|
|
*/ |
99
|
|
|
protected array $output = [ |
100
|
|
|
'id' => null, |
101
|
|
|
'name' => null, |
102
|
|
|
'original_name' => null, |
103
|
|
|
'size' => null, |
104
|
|
|
'type' => null, |
105
|
|
|
'mime_type' => null, |
106
|
|
|
'width' => null, |
107
|
|
|
'height' => null, |
108
|
|
|
'duration' => null, |
109
|
|
|
'dominant_color' => null, |
110
|
|
|
'format' => null, |
111
|
|
|
'cover' => null, |
112
|
|
|
]; |
113
|
|
|
|
114
|
|
|
|
115
|
|
|
public function generateCover(bool $status): UploadEntities |
116
|
|
|
{ |
117
|
|
|
$this->generateCover = $status; |
118
|
|
|
|
119
|
|
|
return $this; |
|
|
|
|
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
public function getGenerateCoverStatus(): bool |
123
|
|
|
{ |
124
|
|
|
return $this->generateCover; |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
public function dominantColor(bool $status): UploadEntities |
128
|
|
|
{ |
129
|
|
|
$this->dominantColor = $status; |
130
|
|
|
|
131
|
|
|
return $this; |
|
|
|
|
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
public function dominantColorQuality(int $quality): UploadEntities |
135
|
|
|
{ |
136
|
|
|
$this->dominantColorQuality = $quality; |
137
|
|
|
|
138
|
|
|
return $this; |
|
|
|
|
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
public function isUploaded(): bool |
142
|
|
|
{ |
143
|
|
|
return $this->uploaded; |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
public function keepOldFiles(bool $status): UploadEntities |
147
|
|
|
{ |
148
|
|
|
$this->keepOldFiles = $status; |
149
|
|
|
|
150
|
|
|
return $this; |
|
|
|
|
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
public function preserveFiles(bool $status): UploadEntities |
154
|
|
|
{ |
155
|
|
|
$this->preserveFiles = $status; |
156
|
|
|
|
157
|
|
|
return $this; |
|
|
|
|
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
public function storeOriginalFileName(bool $status): UploadEntities |
161
|
|
|
{ |
162
|
|
|
$this->storeOriginalFileName = $status; |
163
|
|
|
|
164
|
|
|
return $this; |
|
|
|
|
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
public function optimizeImage(bool $status): UploadEntities |
168
|
|
|
{ |
169
|
|
|
$this->optimizeImage = $status; |
170
|
|
|
|
171
|
|
|
return $this; |
|
|
|
|
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
public function secureIdsMethod(LaruploadSecureIdsMethod $method): UploadEntities |
175
|
|
|
{ |
176
|
|
|
$this->secureIdsMethod = $method; |
177
|
|
|
|
178
|
|
|
return $this; |
|
|
|
|
179
|
|
|
} |
180
|
|
|
} |
181
|
|
|
|